Home > vbmeg > external > iso2mesh > bwislands.m

bwislands

PURPOSE ^

SYNOPSIS ^

function islands=bwislands(img)

DESCRIPTION ^

 islands=bwislands(img)

 return the indices of non-zero elements in a 2D or 3D image
 grouped by connected regions in a cell array

 author: Qianqian Fang (fangq <at> nmr.mgh.harvard.edu)

 input:
     img: a 2D or 3D array
 output:
     islands: a cell array, each cell records the indices 
          of the non-zero elements in img for a connected 
          region (or an island)

 -- 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 islands=bwislands(img)
0002 %
0003 % islands=bwislands(img)
0004 %
0005 % return the indices of non-zero elements in a 2D or 3D image
0006 % grouped by connected regions in a cell array
0007 %
0008 % author: Qianqian Fang (fangq <at> nmr.mgh.harvard.edu)
0009 %
0010 % input:
0011 %     img: a 2D or 3D array
0012 % output:
0013 %     islands: a cell array, each cell records the indices
0014 %          of the non-zero elements in img for a connected
0015 %          region (or an island)
0016 %
0017 % -- this function is part of iso2mesh toolbox (http://iso2mesh.sf.net)
0018 %
0019 
0020 img=logical(1-img);
0021 idx=find(1-img(:));
0022 islands={};
0023 
0024 count=1;
0025 while(length(idx))
0026         [I,J]=ind2sub(size(img),idx(1));
0027     imgnew=imfill(img,[I,J]);
0028     islands{count}=find(imgnew~=img);
0029     count=count+1;
0030     img=imgnew;
0031     idx=find(1-img(:));
0032 end
0033 
0034

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