forked from lucadellasantina/ObjectFinder
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidateObjectWithNeuralNet.m
More file actions
46 lines (43 loc) · 1.99 KB
/
validateObjectWithNeuralNet.m
File metadata and controls
46 lines (43 loc) · 1.99 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
%% ObjectFinder - Recognize 3D structures in image stacks
% Copyright (C) 2016,2017,2018 Luca Della Santina
%
% This file is part of ObjectFinder
%
% ObjectFinder is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program. If not, see <https://www.gnu.org/licenses/>.
%
function Filter = validateObjectWithNeuralNet(Dots, NeuralNet)
%% Classify objects using neural network (outcome == 'Object' or 'Noise')
tic;
sz = NeuralNet.netTransfer.Layers(1).InputSize;
Filter = Dots.Filter;
disp(['Validating objects using ' NeuralNet.Name]);
for i = 1:length(Dots.Vox)
% Reconstruct the image of current object from raw brightness values
minPt = min(Dots.Vox(i).Pos(:,1:3));
maxPt = max(Dots.Vox(i).Pos(:,1:3));
imMat = zeros(maxPt-minPt+1);
for j=1:size(Dots.Vox(i).Pos, 1)
pt = Dots.Vox(i).Pos(j,:) - minPt + 1;
imMat(pt(1),pt(2),pt(3)) = Dots.Vox(i).RawBright(j);
end
% Create maximum intensity projections along cardinal axes
z = imresize(squeeze(max(imMat,[],3)), [sz(1) sz(2)]);
y = imresize(squeeze(max(imMat,[],1)), [sz(1) sz(2)]);
x = imresize(squeeze(max(imMat,[],2)), [sz(1) sz(2)]);
I = cat(3,z,y,x); % Encode each MIP as a R-G-B color
% Classify using pretrained neural network
Filter.passF(i) = (classify(NeuralNet.netTransfer, I) == 'Object');
end
disp(['Done in ' num2str(toc) ' seconds, valid objects: ' num2str(numel(find(Filter.passF))) ' / ' num2str(numel(Filter.passF))]);
end