ROI on the surface or volume with a given centre and radius. Usage: ROImask = SurfStatROI( centre, radius, surf ); centre = id number of vertex, or 3 x 1 vector of [x; y; z] coordinates in mm. radius = radius, mm. surf.coord = 3 x v matrix of coordinates of surface. or surf.lat = nx x ny x nz array, 1=in, 0=out, clamped to the mask. surf.vox = 1 x 3 vector of voxel sizes in mm of the clamped mask. surf.origin = position in mm of the first voxel of the clamped mask. maskROI = 1 x v vector, 1=inside ROI, 0=outside.
0001 function maskROI = SurfStatROI( centre, radius, surf ); 0002 0003 %ROI on the surface or volume with a given centre and radius. 0004 % 0005 % Usage: ROImask = SurfStatROI( centre, radius, surf ); 0006 % 0007 % centre = id number of vertex, or 0008 % 3 x 1 vector of [x; y; z] coordinates in mm. 0009 % radius = radius, mm. 0010 % surf.coord = 3 x v matrix of coordinates of surface. 0011 % or 0012 % surf.lat = nx x ny x nz array, 1=in, 0=out, clamped to the mask. 0013 % surf.vox = 1 x 3 vector of voxel sizes in mm of the clamped mask. 0014 % surf.origin = position in mm of the first voxel of the clamped mask. 0015 % 0016 % maskROI = 1 x v vector, 1=inside ROI, 0=outside. 0017 0018 if isfield(surf,'coord') 0019 if length(centre)==1 0020 id=centre; 0021 centre=surf.coord(:,id); 0022 end 0023 d2=sum((centre*ones(1,size(surf.coord,2))-surf.coord).^2); 0024 maskROI=d2<radius^2; 0025 else 0026 if length(centre)==1 0027 id=centre; 0028 vid=int32(cumsum(surf.lat(:)).*surf.lat(:)); 0029 [i,j,k]=ind2sub(find(vid==id),size(surf.lat)); 0030 centre=(([i,j,k]-1).*surf.vox+surf.origin)'; 0031 end 0032 dim=size(surf.lat); 0033 x0=((1:dim(1))-1)*surf.vox(1)+surf.origin(1); 0034 y0=((1:dim(2))-1)*surf.vox(2)+surf.origin(2); 0035 z0=((1:dim(3))-1)*surf.vox(3)+surf.origin(3); 0036 [i,j,k]=ndgrid(x0,y0,z0); 0037 coord=[i(surf.lat) j(surf.lat) k(surf.lat)]'; 0038 d2=sum((centre*ones(1,size(coord,2))-coord).^2); 0039 maskROI=d2<radius^2; 0040 end 0041 0042 return 0043 end 0044