-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathnewProcessImage.m
More file actions
101 lines (92 loc) · 3.31 KB
/
Copy pathnewProcessImage.m
File metadata and controls
101 lines (92 loc) · 3.31 KB
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
function [outTable] = newProcessImage(net, path,showIntStep)
% net = neural network that takes a 224x224x3 image and classifies how
% infected the image is, If the result is a binary result, then it will ask
% net2 how infected the sample is.
%
% path = full path to the full image to be classified
%
% net2 = network that specifies how infected a sample is, used if net is a
% binary classification
%
%
if nargin == 2
showIntStep = false; % set true to see the results as they are claculated
end
indexArr = reshape(1:36*24,[36,24]);
curImage = im2uint8(imread(path));
if showIntStep
figure;
h = axes;
f = waitbar(0,'Loading Image');
imshow(curImage);
end
subSizeX = 224;
subSizeY = 224;
str = "";
imageSet = [];
newIndex = [];
% for i = 1:numel(index)
% if showIntStep
% waitbar(i/(numel(index)+1),f,sprintf('Analyizing Image %d out of %d',i, numel(index)));
% end
% [row,col,~] = find(index==i,1,'first');
% rectPosBbox = [((row-1)*subSizeY)+1,((col-1)*subSizeX)+1,subSizeY-1,subSizeX-1];
% if showIntStep
% rectangle(h,'Position', rectPosBbox); %#ok<UNRCH>
% end
% CurSubImage = imcrop(curImage,rectPosBbox);
% drawnow;
% % test if the image contains a sample
% [isSample, ~ ] = isSampleMask(CurSubImage);
% if isSample == false
% else
% imageSet = cat(4,imageSet,CurSubImage);
% newIndex = [newIndex;i];
% end
% end
[rows columns numberOfColorBands] = size(curImage);
blockSizeR = 224; % Rows in block.
blockSizeC = 224; % Columns in block.
% Figure out the size of each block in rows.
% Most will be blockSizeR but there may be a remainder amount of less than that.
wholeBlockRows = floor(rows / blockSizeR);
blockVectorR = [blockSizeR * ones(1, wholeBlockRows), rem(rows, blockSizeR)];
% Figure out the size of each block in columns.
wholeBlockCols = floor(columns / blockSizeC);
blockVectorC = [blockSizeC * ones(1, wholeBlockCols), rem(columns, blockSizeC)];
% Create the cell array, ca.
% Each cell (except for the remainder cells at the end of the image)
% in the array contains a blockSizeR by blockSizeC by 3 color array.
% This line is where the image is actually divided up into blocks.
if numberOfColorBands > 1
% It's a color image.
ca = mat2cell(curImage, blockVectorR, blockVectorC, numberOfColorBands);
else
ca = mat2cell(curImage, blockVectorR, blockVectorC);
end
ca = ca(1:end-1,1:end-1);
ca=ca';
ca=ca(:);
index = cellfun(@(x) isSampleMask(x),ca);
ca = ca(index);
imarr = reshape(ca,[1 1 1 numel(ca)]);
imageSet = cell2mat(imarr);
if showIntStep
delete(f);
end
disp('Starting classification!')
tic;
[pred,score] = classify(net,imageSet);
disp('Ending classification');
toc
category = categorical(repelem({'NotASample'},36*24)',{'Uncategorized','NotASample','OutOfFocus','None','Low','Moderate','High','Infection'},{'Uncategorized','NotASample','OutOfFocus','None','Low','Moderate','High','Infection'},'Ordinal',true);
scoreOut =zeros(36*24,1);
scoreOut(index) = score(:,1);
category(index) = cellstr(pred);
[~,filename,fileext] = fileparts(path);
[col,row,~] = find(indexArr<=length(category));
file = repmat([filename,fileext],[length(category),1]);
outTable = table(cellstr(file),category,scoreOut,row,col,'VariableNames',{'File','Category','Score','row','col'});
% [folder,~,~] = fileparts(path);
% plotImageLables(folder,outTable);
end