Home > vbmeg > external > iso2mesh > thinbinvol.m

thinbinvol

PURPOSE ^

SYNOPSIS ^

function vol=thinbinvol(vol,layer,nobd)

DESCRIPTION ^

 vol=thinbinvol(vol,layer,nobd)

 thinning a binary volume by a given pixel width
 this is similar to bwmorph(vol,'thin',n) except 
 this does it in 3d and only run thinning for 
 non-zero elements (and hopefully faster)

 author: Qianqian Fang, <q.fang at neu.edu>

 input:
     vol: a volumetric binary image
     layer: number of iterations for the thickenining
     nobd: (optional) if set to 1, boundaries will not 
            erode. if not given, nobd=0.

 output:
     vol: the volume image after the thinning operations

 -- this function is part of iso2mesh toolbox (http://iso2mesh.sf.net)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function vol=thinbinvol(vol,layer,nobd)
0002 %
0003 % vol=thinbinvol(vol,layer,nobd)
0004 %
0005 % thinning a binary volume by a given pixel width
0006 % this is similar to bwmorph(vol,'thin',n) except
0007 % this does it in 3d and only run thinning for
0008 % non-zero elements (and hopefully faster)
0009 %
0010 % author: Qianqian Fang, <q.fang at neu.edu>
0011 %
0012 % input:
0013 %     vol: a volumetric binary image
0014 %     layer: number of iterations for the thickenining
0015 %     nobd: (optional) if set to 1, boundaries will not
0016 %            erode. if not given, nobd=0.
0017 %
0018 % output:
0019 %     vol: the volume image after the thinning operations
0020 %
0021 % -- this function is part of iso2mesh toolbox (http://iso2mesh.sf.net)
0022 %
0023 
0024 dim=size(vol);
0025 dxy=dim(1)*dim(2);
0026 fulllen=prod(dim);
0027 
0028 if(nargin<3)
0029     nobd=0;
0030 end
0031 
0032 if(nobd==1)
0033     bdmask=vol;
0034     if(ndims(vol)==2)
0035         bdmask(2:end-1,2:end-1)=0;
0036     elseif(ndims(vol)==3)
0037         bdmask(2:end-1,2:end-1,2:end-1)=0;
0038     end
0039 end
0040 
0041 for i=1:layer
0042     idx=find(~vol);
0043     idxnew=[idx+1; idx-1;idx+dim(1);idx-dim(1);idx+dxy;idx-dxy];
0044     idxnew=idxnew(find(idxnew>0 & idxnew<fulllen));
0045     vol(idxnew)=0;
0046         if(nobd)
0047              vol = vol | bdmask;
0048         end
0049 end

Generated on Mon 22-May-2023 06:53:56 by m2html © 2005