Home > vbmeg > functions > common > morphology > vb_face_to_mask.m

vb_face_to_mask

PURPOSE ^

Make mask from face vertex

SYNOPSIS ^

function B = vb_face_to_mask(V,F,DIM,vsize,zmin,plot_mode,zindx)

DESCRIPTION ^

 Make mask from face vertex
  B = vb_face_to_mask(V,F,DIM)
  B = vb_face_to_mask(V,F,DIM,vsize,zmin)
  B = vb_face_to_mask(V,F,DIM,vsize,zmin,plot_mode,zindx)
 --- Input
 V     : face vertex
 F     : patch index
 DIM = [NX, NY, NZ] : Dimension of mask image
 --- Optional Input
 vsize : voxcel size
 zmin  : minimum value for mask in z-axis
 plot_mode, zindx
 --- Output
 B     : Output mask image

 Copyright (C) 2011, ATR All Rights Reserved.
 License : New BSD License(see VBMEG_LICENSE.txt)

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function   B = vb_face_to_mask(V,F,DIM,vsize,zmin,plot_mode,zindx)
0002 % Make mask from face vertex
0003 %  B = vb_face_to_mask(V,F,DIM)
0004 %  B = vb_face_to_mask(V,F,DIM,vsize,zmin)
0005 %  B = vb_face_to_mask(V,F,DIM,vsize,zmin,plot_mode,zindx)
0006 % --- Input
0007 % V     : face vertex
0008 % F     : patch index
0009 % DIM = [NX, NY, NZ] : Dimension of mask image
0010 % --- Optional Input
0011 % vsize : voxcel size
0012 % zmin  : minimum value for mask in z-axis
0013 % plot_mode, zindx
0014 % --- Output
0015 % B     : Output mask image
0016 %
0017 % Copyright (C) 2011, ATR All Rights Reserved.
0018 % License : New BSD License(see VBMEG_LICENSE.txt)
0019 
0020 if ~exist('vsize','var'), vsize = 2; end;
0021 if ~exist('plot_mode','var'), plot_mode = 0; end;
0022 if ~exist('zmin','var'),  
0023     zmin = [];
0024 else
0025     zmin = ceil(zmin/vsize);
0026 end;
0027 
0028 tic
0029 %fprintf('surface to mask\n')
0030 
0031 if isempty(zmin)
0032     % Make surface closed
0033     [F,V] = vb_close_surf(F,V);
0034     
0035     % Make mask image from CSF head surface
0036     B = vb_surf_to_filled_mask(V, F, DIM, vsize);
0037 else
0038     % dmin    : minimum length for edge
0039     dmin  = vsize/2;
0040     
0041     B = vb_surf_to_mask(V,F,vsize,dmin,DIM);
0042     
0043     % voxcel value for filled voxcel
0044     filval = 1;
0045     level  = 0.5;
0046     
0047     % Scaling by voxcel size
0048     V = V/vsize;
0049     % Start point for filling in
0050     zmid  = (max(V(:,3)) + min(V(:,3)))/2;
0051     ix = find( ( V(:,3) >= (zmid - 5) )&( V(:,3) <= (zmid + 5) ) );
0052     Vcenter = round(mean(V(ix,:),1));
0053     
0054     if plot_mode > 0
0055         zindx = Vcenter(3);
0056         vb_plot_slice( B, V, zindx, 1, [1 1]);
0057         hold on
0058         plot(Vcenter(2),Vcenter(1),'ro')
0059     end
0060     
0061     % Set mask value at zmin to stop filling outside
0062     B(:,:,zmin) = 1;
0063     
0064     fprintf('face flood fill\n')
0065     
0066     B = vb_flood_fill_3d(B, Vcenter, filval, level);
0067     
0068     % Remove mask for lower than zmin
0069     B(:,:,1:zmin) = 0;
0070 end
0071 
0072 vb_ptime(toc)
0073 
0074 if plot_mode > 1
0075     zindx = (min(V(:,3)):20:max(V(:,3)));
0076     zindx = ceil(zindx);
0077     vb_plot_slice( B, V, zindx, 1);
0078 end

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