-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgfpopCols.m
87 lines (69 loc) · 2.56 KB
/
gfpopCols.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
% SPDX-License-Identifier: BSD-3-Clause
% gfpop columns with original images
% Runs through the LiDAR images with verification after detecting
% changepoint.
%% Path setup
beehiveDataSetup;
%% Graph Generation
% Parameters
B1 = .005;
B2 = .005;
% Edges
edge1 = gfpopEdge("air","inc_to_bee","up",penalty=B1);
edge2 = gfpopEdge("inc_to_bee","inc_to_bee","up");
edge3 = gfpopEdge("inc_to_bee","BEE","up");
edge4 = gfpopEdge("BEE","dec_from_bee","down",penalty=B2);
edge5 = gfpopEdge("dec_from_bee","dec_from_bee","down");
edge6 = gfpopEdge("dec_from_bee","air","down");
% Graph
beeGraph = gfpopGraph(edges=[edge1 edge2 edge3 edge4 edge5 edge6],allNullEdges=true);
%% Bee Image Iteration
tic
load(testingDataDir + filesep + "testingData.mat");
numImages = length(testingData);
testingResultsLabel = zeros(numImages,2); % Image # | Insect Present
testingResultsLabel(1:end,1) = (1:numImages);
testingResultData = cell(numImages,1);
testingRowLabelPredicted = cell(numImages,1);
% Training Image Iteration
parfor imageNum = 1:length(testingData)
image = -1.*testingData{1,imageNum}
rowsPredicted = zeros(1,size(image,1));
validRows = zeros(1,size(image,1));
% Row Validation
for rowCheck = 1:size(image,1)
if(range(image(rowCheck,:) > mean(image(rowCheck,:))))
validRows(rowCheck) = 1;
end
end
validIndeces = find(validRows);
% Column Iteration
beeCols = cell(1,size(image,2));
for col = 1:size(image,2)
tmpResults = gfpop(image(:,col),beeGraph,"mean");
if(any(tmpResults.states.contains("BEE")))
beeRows = tmpResults.changepoints(tmpResults.states == "BEE");
beeRowsChecked = beeRows(ismember(beeRows,validIndeces));
counter = 1;
for rowIndex = 1:numel(beeRowsChecked)
row = beeRowsChecked(rowIndex);
if(image(row,col) > mean(image(row,:)))
beeCols{1,col} = tmpResults;
rowsPredicted(row) = 1;
end
end
end
end
testingRowLabelPredicted{imageNum,1} = rowsPredicted;
if(any(~cellfun(@isempty,beeCols)))
testingResultData{imageNum} = beeCols;
end
end
beeIndeces = ~cellfun(@isempty,testingResultData);
testingResultsLabel(beeIndeces,2) = 1;
% Saving Full Directory Structure
results = {testingResultsLabel,testingRowLabelPredicted,testingResultData,"Img Results | Row Results | Data"};
if ~exist(changepointResultsDir,'dir')
mkdir(changepointResultsDir);
end
save(changepointResultsDir + filesep + "gfpopColsResults.mat","results",'-v7.3');