-
Notifications
You must be signed in to change notification settings - Fork 0
/
customParasitologyFcn.m
39 lines (35 loc) · 955 Bytes
/
customParasitologyFcn.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
function [features, featureMetrics] = customParasitologyFcn(I)
persistent targetImage
matchHistograms = true; %Low-cost way to improve performance
% Histogram matching may help!
if isempty(targetImage) && matchHistograms
targetImage = rgb2gray(imread('BabesiosisRGB.png'));
end
extractorMethod = 'SURF'; %#ok Auto;BRISK;FREAK;SURF;BLOCK
%
% Convert I to grayscale if required.
[height,width,numChannels] = size(I);
if numChannels > 1
grayImage = rgb2gray(I);
else
grayImage = I;
end
if matchHistograms
grayImage = imhistmatch(grayImage,targetImage);
end
gridStep = 8;
gridX = 1:gridStep:width;
gridY = 1:gridStep:height;
[x,y] = meshgrid(gridX, gridY);
gridLocations = [x(:) y(:)];
[features, scenePoints] = extractFeatures(grayImage,gridLocations,...
'Method',extractorMethod,...
'SURFSize',64,...
'Upright',true);
%
try
features = double(features);
catch
features = double(features.Features);
end
featureMetrics = var(features,[],2);