-
Notifications
You must be signed in to change notification settings - Fork 73
/
imedge3d.m
37 lines (36 loc) · 1.15 KB
/
imedge3d.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
function imgdiff = imedge3d(binimg, isdiff)
%
% imgdiff=imedge3d(binimg,isdiff)
%
% Extract the boundary voxels from a binary image
%
% author: Aslak Grinsted <ag at glaciology.net>
% modified by Qianqian Fang <q.fang at neu.edu>
%
% input:
% binimg: a 3D binary image
% isdiff: if isdiff=1, output will be all voxels which
% is different from its neighbors; if isdiff=0 or
% ignored, output will be the edge voxels of the
% non-zero regions in binimg
%
% output:
% imgdiff: a 3D logical array with the same size as binimg
% with 1 for voxels on the boundary and 0 otherwise
%
% -- this function is part of iso2mesh toolbox (http://iso2mesh.sf.net)
%
invol = 1;
if (nargin == 2)
invol = isdiff;
end
binimg = logical(binimg);
imgdiff = xor(binimg, binimg(:, :, [1 1:end - 1]));
imgdiff = imgdiff | xor(binimg, binimg(:, :, [2:end end]));
imgdiff = imgdiff | xor(binimg, binimg(:, [1 1:end - 1], :));
imgdiff = imgdiff | xor(binimg, binimg(:, [2:end end], :));
imgdiff = imgdiff | xor(binimg, binimg([1 1:end - 1], :, :));
imgdiff = imgdiff | xor(binimg, binimg([2:end end], :, :));
if (invol)
imgdiff = imgdiff & binimg;
end