-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathmorphprofile_base.m
More file actions
146 lines (120 loc) · 3.61 KB
/
morphprofile_base.m
File metadata and controls
146 lines (120 loc) · 3.61 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
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
136
137
138
139
140
141
142
143
144
145
146
%% MORPHPROFILE_BASE - Base function for MORPHPROFILE.
%
%% Syntax
% DMP = MORPHPROFILE_BASE( I, op, se );
% DMP = MORPHPROFILE_BASE( I, op, se );
% [DMP, Phi, MP] = MORPHPROFILE_BASE( I, op, se, s1[, s2] );
%
%% See also
% Related:
% <MORPHPROFILE.html |MORPHPROFILE|>,
% <GRANULOMETRY_BASE.html |GRANULOMETRY_BASE|>,
% <ASF_BASE.html |ASF_BASE|>.
% Called:
% <IMRECONSTRUCTBY.html |IMRECONSTRUCTBY|>,
% <FLATSTREL.html |FLATSTREL|>.
%% Function implementation
function [DMP, Phi, varargout] = morphprofile_base( I, op, se, s1, s2 )
[X,Y] = size(I(:,:,1));
n = min(length(op),3);
if nargin>=3 && iscell(se) && strcmp(class(se{1}),'strel')
N = size(se,1);
% ignore all other parameters
elseif nargin>=3
if ischar(se)
shape = se;
if nargin>=4 && isnumeric(s1)
N = length(s1);
if nargin<5 || ~isnumeric(s2), s2 = cell(N,1); end
else
N = 10; s1 = cell(N,1); s2 = cell(N,1);
end
elseif isnumeric(se)
N = length(se);
if nargin>=4 && ischar(s1), shape = s1;
if nargin<5 || ~isnumeric(s2), s2 = cell(N,1); end
else
shape = []; s2 = cell(N,1);
end
s1 = se;
end
if ~iscell(s1), s1 = num2cell(s1); end
if ~iscell(s2), s2 = num2cell(s2); end
se = cell(N,1);
for i=1:N
se{i} = flatstrel(shape, s1{i}, s2{i});
end
end
R0 = I;
if any(strcmp(op,{'roc','oc','ed'}))
DMP = cell(1,2*N); % note: in principle, MP{0}=I
else
DMP = cell(1,N);
end
if strcmp(op(1:n),'roc'),
R00 = I;
if nargout>2,
switch op
case 'roc', varargout{1} = cell(2*N,1);
case 'rocmax', varargout{1} = cell(N,1);
end
end
end
%%
% compute the (derivative of the) morphological profile
for i=1:N
if strcmp(op(1),'r')
switch op
case {'roc','rocmax'}
R = imreconstructby_base(I, 'ro', se{i}); % Eq.(1) of [PB]
R2 = imreconstructby_base(I, 'rc', se{i}); % Eq.(2)
case {'rc','rclose','ro','ropen'}
R = imreconstructby_base(I, op, se{i});
end
else
switch op(1)
case {'o','open'}
R = imopen(I, se{i});
case {'c','close'}
R = imclose(I, se{i});
case {'e','erode'}
R = imerode(I, se{i});
case {'d','dilate'}
R = imdilate(I, se{i});
end
if length(op)>=2
if strcmp(op(1:2),'oc'), R2 = imclose(I, se{i});
elseif strcmp(op(1:2),'ed'), R2 = imdilate(I, se{i});
end
end
end
% if der
DMP{i} = abs(R - R0); % Eq.(3)
if nargout>2, varargout{1}{N+i} = R; end
if any(strcmp(op,{'roc','oc','ed'}))
DMP{2*N-i+1} = abs(R2 - R00); % Eq.(4)
elseif any(strcmp(op,{'rocmax','ocmax','edmax'}))
DMP{i} = max(cat(3, DMP{i}, R2 - R00), [], 3);
end
if nargout>2 && any(strcmp(op,{'roc','oc','ed','rocmax','ocmax','edmax'})),
varargout{1}{2*N-i+1} = R2;
end
% else
% MP{i} = R;
% if any(strcmp(op,{'roc','oc','ed'})),
% MP{2*N-i+1} = R2;
% end
% end
R0 = R;
if any(strcmp(op,{'roc','oc','ed','rocmax','ocmax','edmax'}))
R00 = R2;
end
end
%%
% compute the morphological multi-scale characteristics
Phi = zeros(size(I));
T = cell2mat(DMP);
for c = 1:size(T,3)
[~, Phi(:,:,c)] = max(reshape(T(:,:,c),[X,Y,length(DMP)]), [], 3);
end
end % end of morphprofile_base