-
Notifications
You must be signed in to change notification settings - Fork 5
/
rothwelledge_base.m
135 lines (114 loc) · 3.79 KB
/
rothwelledge_base.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
%% ROTHWELLEDGE_BASE - Base function for ROTHWELLEDGE.
%
%% Syntax
% [edgemap, mag, or] = ROTHWELLEDGE_BASE(I, sigma, low, alpha, samp, reduce);
% [edgemap, mag, or] = ROTHWELLEDGE_BASE(gx, gy, low, alpha, samp, reduce);
%
%% Acknowledgment
% This function uses the C function developped Heath et al. for the comparative
% study in [HSSB97]; the mex file in |ROTHWELL_MEX| calls directly the code
% made available by the authors in the page:
% <ftp://figment.csee.usf.edu/pub/Edge_Comparison/source_code/rothwell.src>
%
%% See also
% Related:
% <ROTHWELLEDGE.html |ROTHWELLEDGE|>,
% <EDGECORNER_BASE.html |EDGECORNER_BASE|>,
% <CANNYEDGE_BASE.html |CANNYEDGE_BASE|>,
% <CONGRUENCYEDGE_BASE.html |CONGRUENCYEDGE_BASE|>,
% <COMPASSEDGE_BASE.html |COMPASSEDGE_BASE|>,
% <ANISOEDGE_BASE.html |ANISOEDGE_BASE|>,
% <ELDERZUCKEREDGE_BASE.html |ELDERZUCKEREDGE_BASE|>,
% <KOETHEDGE_BASE.html |KOETHEDGE_BASE|>,
% <SDGDEDGE_BASE.html |SDGDEDGE_BASE|>,
% <PETROUEDGE_BASE.html |PETROUEDGE_BASE|>.
% Called:
% ROTHWELLEDGE_MEX.
%% Function implementation
function [edgemap,varargout] = rothwelledge_base(I, V, low, alpha, samp, reduce)
if nargin<5, samp = 1;
if nargin<6, reduce = false;
end
end; % we allow variable number of inputs
%%
% dealing with multispectral images
[X,Y,C] = size(I);
if C>1
if (islogical(reduce) && ~reduce) || ...
(ischar(reduce) && strcmpi(reduce,'eor'))
% process channel by channel
edgemap = false(X*samp, Y*samp, C);
for i=1:nargout-1,
varargout{i} = zeros(X*samp, Y*samp, C);
end
if isscalar(V), V = repmat(V, [1 1 3]); end
for c=1:C
[edgemap(:,:,c), mag, or] = ...
rothwelledge_base(I(:,:,c), V(:,:,c), low, alpha, samp);
if nargout>=2, varargout{1}(:,:,c) = or; end
if nargout==3, varargout{2}(:,:,c) = mag; end
end
if strcmpi(reduce,'eor')
for c=1:C
edgemap(:,:,1) = edgemap(:,:,1) | edgemap(:,:,c);
end
edgemap = bwmorph(edgemap(:,:,1),'thin',Inf);
end
return;
elseif islogical(reduce) || ...
(ischar(reduce) && any(strcmpi(reduce,{'isum','igray','imax'})))
% at that point, if reduce is logical, it is necessarly true
if C==3 && strcmpi(reduce,'igray')
I = rgb2gray(rescale(I,0,1));
elseif islogical(reduce) || strcmpi(reduce,'isum')
if C==3
I = 0.29*I(:,:,1) + 0.59*I(:,:,2) + 0.11*I(:,:,3);
I = rescale(I,0,1);
else
I = sum(rescale(I,0,1), 3);
end
elseif strcmpi(reduce,'imax')
I = max(rescale(I,0,1), [], 3);
end
end
end
I = rescale(I,0,255); % requirement when calling rothwelledge_mex...
%%
% set some internal parameter fo padding the input image (see function
if samp>1
S =[samp samp];
% perform interpolation channel by channel
I = upscalexy_base(I, S, 'linear');
end
%%
% |smooth_image| of |rothwell_mex|
if isscalar(V)
sigma = samp * V;
gy = [];
gauss_tail = 0.015;
kwidth = ceil(sigma*sqrt(2*log(1/gauss_tail))+1); %
A = padarray(I, [kwidth kwidth], 'symmetric', 'both');
elseif isnumeric(V)
sigma = [];
gy = V;
if samp>1, gy = upscalexy_base(gy, S, 'linear'); end
A = I;
kwidth = 0;
end
%%
% call the mex file
[edgemap, or, mag] = rothwelledge_mex(A, gy, sigma, low, alpha);
%%
% crop
if isscalar(V)
edgemap = edgemap(kwidth+1:kwidth+X*samp,kwidth+1:kwidth+Y*samp);
end
%%
% outputs
if nargout>=2
varargout{1} = mag(kwidth+1:kwidth+X*samp,kwidth+1:kwidth+Y*samp);
end
if nargout==3
varargout{2} = or(kwidth+1:kwidth+X*samp,kwidth+1:kwidth+Y*samp);
end
end % end of rothwelledge_base