-
Notifications
You must be signed in to change notification settings - Fork 7
/
imerode3D.m
50 lines (44 loc) · 1.5 KB
/
imerode3D.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
% imerode3D() - Erodes the image in 3D
%
% Usage:
% >> B = imerode3D(A, se);
%
% Inputs:
% A - input image
% se - structuring element
%
% Outputs:
% B - output image
%
% Author: Zeynep Akalin Acar, SCCN, 2008
% Copyright (C) 2007 Zeynep Akalin Acar, SCCN, [email protected]
%
% This program is free software; you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation; either version 2 of the License, or
% (at your option) any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with this program; if not, write to the Free Software
% Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
function B = imerode3D(A, se);
sz = size(A);
% axial
A1 = imerode(A, se);
A1 = A1 - min(min(min(A1)));
% sagittal
for i = 1:sz(2); R1(:,:,i) = (reshape(A(:,i,:),sz(1),sz(3))); end
R1 = imerode(R1, se);
for i=1:sz(3); R2(:,:,i) = reshape(R1(:,i,:),sz(1),sz(2)); end
R2 = R2 - min(min(min(R2)));
% coronal
for i = 1:sz(1); R3(:,:,i) = (reshape(A(i,:,:),sz(2),sz(3))); end
R3 = imerode(R3, se);
for i=1:sz(3); R4(:,:,i) = squeeze(R3(:,i,:))'; end
R4 = R4 - min(min(min(R4)));
B = A1 | R2 | R4;