-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathMatchFilterWithGaussDerivative.m
52 lines (49 loc) · 1.75 KB
/
MatchFilterWithGaussDerivative.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
% Retinal vessel extraction by matched filter with first-order derivative of Gaussian
%
% Inputs:
% img = input imgage
% sigma = scale value
% yLength = length of neighborhood along y-axis
% numOfDirections = number of orientations
% mask = image mask
% c_value = c value
% t = threshold value of region props
% Output:
% vess = vessels extracted
function [vess] = MatchFilterWithGaussDerivative(img, sigma, yLength, numOfDirections, mask, c_value, t)
if isa(img,'double')~=1
img = double(img);
end
[rows,cols] = size(img);
MatchFilterRes(rows,cols,numOfDirections) = 0;
GaussDerivativeRes(rows,cols,numOfDirections) = 0;
for i = 0:numOfDirections-1
matchFilterKernel = MatchFilterAndGaussDerKernel(sigma,yLength, pi/numOfDirections*i, 0);
gaussDerivativeFilterKernel = MatchFilterAndGaussDerKernel(sigma, yLength, pi/numOfDirections*i, 1);
MatchFilterRes(:,:,i+1) = conv2(img,matchFilterKernel,'same');
GaussDerivativeRes(:,:,i+1) = (conv2(img,gaussDerivativeFilterKernel,'same'));
end
maxMatchFilterRes = max(MatchFilterRes,[],3);
maxGaussDerivativeRes = max(GaussDerivativeRes,[],3);
D = maxGaussDerivativeRes;
W = fspecial('average', 31);
Dm = imfilter(D, W);
%Normailzation
Dm = Dm - min(Dm(:));
Dm = Dm/max(Dm(:));
%muH = mean value of response image H
H = maxMatchFilterRes;
c = c_value;
muH = mean(H(:));
Tc = c * muH;
T = (1 + Dm) * Tc;
Mh = (H >= T);
vess = Mh & mask;
se = strel('square',3);
vess = imclose(vess,se);
vess = bwmorph(vess,'close');
[L, num] = bwlabel(vess, 8);
prop = regionprops(L, 'Area');
idx = find([prop.Area] > t);
vess = ismember(L,idx);
end