imgdiff=imedge3d(binimg,isdiff) Extract the boundary voxels from a binary image author: Aslak Grinsted <ag at glaciology.net> modified by Qianqian Fang <fangq at nmr.mgh.harvard.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)
0001 function imgdiff=imedge3d(binimg,isdiff) 0002 % 0003 % imgdiff=imedge3d(binimg,isdiff) 0004 % 0005 % Extract the boundary voxels from a binary image 0006 % 0007 % author: Aslak Grinsted <ag at glaciology.net> 0008 % modified by Qianqian Fang <fangq at nmr.mgh.harvard.edu> 0009 % 0010 % input: 0011 % binimg: a 3D binary image 0012 % isdiff: if isdiff=1, output will be all voxels which 0013 % is different from its neighbors; if isdiff=0 or 0014 % ignored, output will be the edge voxels of the 0015 % non-zero regions in binimg 0016 % 0017 % output: 0018 % imgdiff: a 3D logical array with the same size as binimg 0019 % with 1 for voxels on the boundary and 0 otherwise 0020 % 0021 % -- this function is part of iso2mesh toolbox (http://iso2mesh.sf.net) 0022 % 0023 0024 invol=1; 0025 if(nargin==2) 0026 invol=isdiff; 0027 end 0028 binimg=logical(binimg); 0029 imgdiff=xor(binimg,binimg(:,:,[1 1:end-1])); 0030 imgdiff=imgdiff|xor(binimg,binimg(:,:,[2:end end])); 0031 imgdiff=imgdiff|xor(binimg,binimg(:,[1 1:end-1],:)); 0032 imgdiff=imgdiff|xor(binimg,binimg(:,[2:end end],:)); 0033 imgdiff=imgdiff|xor(binimg,binimg([1 1:end-1],:,:)); 0034 imgdiff=imgdiff|xor(binimg,binimg([2:end end],:,:)); 0035 if(invol) 0036 imgdiff=imgdiff&binimg; 0037 end