-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtry_vesselness_ETF.m
79 lines (65 loc) · 2.15 KB
/
try_vesselness_ETF.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
function [outIm,whatScale,Direction,Dx,Dy] = try_vesselness_ETF(tx,ty,tmag,I,sigmas,BlackWhite)
tx = tx.*tmag;
ty = ty.*tmag;
gx = ty;
gy = -tx;
% gx(ty<0 & tx>0) = -gx(ty<0 & tx>0);
% gy(ty<0 & tx>0) = -gy(ty<0 & tx>0);
% gx(ty<0 & tx<0) = -gx(ty<0 & tx<0);
% gy(ty<0 & tx<0) = -gy(ty<0 & tx<0);
% Make matrices to store all filterd images
ALLfiltered=zeros([size(I) length(sigmas)]);
ALLangles=zeros([size(I) length(sigmas)]);
ALLIx = ALLangles;
ALLIy = ALLangles;
beta = 2*0.5^2;
c = 2*15^2;
%% comparison
[Dxx,Dxy,Dyy] = Hessian2D(I,1);
addpath F:\Dropbox\Code\Download\frangi_filter_version2a
for i = 1:length(sigmas)
[Dxx,Dxy,Dyy] = Hessian2D(I,sigmas(i));
[Lambda1,Lambda2,Ix,Iy]=eig2image(Dxx,Dxy,Dyy,gx,gy);
% Compute the direction of the minor eigenvector
angles = atan2(Ix,Iy);
% Compute some similarity measures
Lambda1(Lambda1==0) = eps;
Rb = (Lambda2./Lambda1).^2;
S2 = Lambda1.^2 + Lambda2.^2;
% Compute the output image
Ifiltered = exp(-Rb/beta) .*(ones(size(I))-exp(-S2/c));
if(BlackWhite)
Ifiltered(Lambda1<0)=0;
else
Ifiltered(Lambda1>0)=0;
end
% store the results in 3D matrices
ALLfiltered(:,:,i) = Ifiltered;
ALLangles(:,:,i) = angles;
ALLIx(:,:,i) = Ix;
ALLIy(:,:,i) = Iy;
end
% Return for every pixel the value of the scale(sigma) with the maximum
% output pixel value
if length(sigmas) > 1,
[outIm,whatScale] = max(ALLfiltered,[],3);
outIm = reshape(outIm,size(I));
if(nargout>1)
whatScale = reshape(whatScale,size(I));
end
if(nargout>2)
Direction = reshape(ALLangles((1:numel(I))'+(whatScale(:)-1)*numel(I)),size(I));
Dx = reshape(ALLIx((1:numel(I))'+(whatScale(:)-1)*numel(I)),size(I));
Dy = reshape(ALLIy((1:numel(I))'+(whatScale(:)-1)*numel(I)),size(I));
end
else
outIm = reshape(ALLfiltered,size(I));
if(nargout>1)
whatScale = ones(size(I));
end
if(nargout>2)
Direction = reshape(ALLangles,size(I));
Dx = reshape(ALLIx,size(I));
Dy = reshape(ALLIy,size(I));
end
end