Home > functions > common > morphology > vb_get_cortex_mask.m

vb_get_cortex_mask

PURPOSE ^

Get brain/cortex mask image from subject brain mask file

SYNOPSIS ^

function [avw ,Xcenter] = vb_get_cortex_mask(fname,fana,LR,step,val,R)

DESCRIPTION ^

 Get brain/cortex mask image from subject brain mask file
  [avw ,Xcenter] = vb_get_cortex_mask(fname,fana,LR,step,val,R)
 --- Input
 fname = brain mask file
 fana  = analyze file
 --- Optional input
 LR = 'left' , 'right'
    if empty or not given, both hemisphere are included [Defoult]
 step : voxel size of mask image = 1  [mm]
 val  : threshold value for gray & white matter
 R    : Morphology R = [2 -2] [mm]
 --- Output
 avw.img  : 3D mask image (voxel size = step [mm])
 avw.hdr.dime.dim(2:4)    : mask image dimension
 avw.hdr.dime.pixdim(2:4) : voxel size [mm] = [step step step]
 
 Xcenter : Center of cortex to separate left/right (SPM_right_[m])

 2007/06/15 Masa-aki Sato

 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 [avw ,Xcenter] = vb_get_cortex_mask(fname,fana,LR,step,val,R)
0002 % Get brain/cortex mask image from subject brain mask file
0003 %  [avw ,Xcenter] = vb_get_cortex_mask(fname,fana,LR,step,val,R)
0004 % --- Input
0005 % fname = brain mask file
0006 % fana  = analyze file
0007 % --- Optional input
0008 % LR = 'left' , 'right'
0009 %    if empty or not given, both hemisphere are included [Defoult]
0010 % step : voxel size of mask image = 1  [mm]
0011 % val  : threshold value for gray & white matter
0012 % R    : Morphology R = [2 -2] [mm]
0013 % --- Output
0014 % avw.img  : 3D mask image (voxel size = step [mm])
0015 % avw.hdr.dime.dim(2:4)    : mask image dimension
0016 % avw.hdr.dime.pixdim(2:4) : voxel size [mm] = [step step step]
0017 %
0018 % Xcenter : Center of cortex to separate left/right (SPM_right_[m])
0019 %
0020 % 2007/06/15 Masa-aki Sato
0021 %
0022 % Copyright (C) 2011, ATR All Rights Reserved.
0023 % License : New BSD License(see VBMEG_LICENSE.txt)
0024 
0025 %% Label value
0026 %  1 = brain (CSF)
0027 %  2 = Gray
0028 %  3 = White
0029 %  4 = Cerebellum
0030 %  5 = Brainstem
0031 
0032 if ~exist('LR','var'), LR = ''; end;
0033 if ~exist('val','var'), val = 90; end;
0034 if ~exist('step','var'), step = 1; end;
0035 if ~exist('R','var'), R = [2 2 -2];end
0036 
0037 load(fname, 'avw', 'XYZspm');
0038 
0039 B = avw.img;
0040 
0041 % Index for gray/white region
0042 ix = find( B(:)==2 | B(:)==3);
0043 
0044 % Make mask for brain/cortex
0045 Vdim  = size(B);
0046 B = zeros(Vdim);
0047 B(ix) = 1;
0048 
0049 % Morphology smoothing
0050 B = vb_morphology_operation(B, R);
0051 
0052 % Background voxel index
0053 ix = find( B(:) == 0 );
0054 
0055 % Load subject MRI image
0056 [B, Vdim, Vsize] = vb_load_analyze_to_right(fana);
0057 
0058 % Remove background
0059 B(ix) = 0;
0060 
0061 % voxel larger than threshold
0062 ix = find( B(:) >= val );
0063 
0064 % Transform index to Analyze voxel coordinate (= 3D index)
0065 [x,y,z] = ind2sub(Vdim,ix);
0066 % Analyze mm-coordinate
0067 V = vb_analyze_to_analyze_mm([x,y,z],Vdim,Vsize);
0068 
0069 % Central region coordinate (SPM_right_[m] coordinate)
0070 Xcenter = mean(XYZspm{1}.xyz);
0071 
0072 % Mask image dimension (voxel size = step [mm])
0073 Dim = vb_mask_image_size(Vdim,Vsize,step); 
0074 
0075 % Transform  to voxel coordinate in mask image
0076 V  = V/step;
0077 J  = max(floor(V) , 1);
0078 ix = sub2ind(Dim, J(:,1),J(:,2),J(:,3));
0079 
0080 % Make mask image with voxel size = step [mm]
0081 B = zeros(Dim);
0082 B(ix) = 1;
0083 
0084 % Left/right center index
0085 x0 = vb_spm_right_to_analyze_right_mm(Xcenter,Vdim,Vsize);
0086 x0 = round(x0(1)/step);
0087 
0088 switch LR
0089 case    'left'
0090     B((x0+1):end,:,:) = 0;
0091 case    'right'
0092     B(1:x0-1,:,:) = 0;
0093 end
0094 
0095 avw.img = B;
0096 avw.hdr.dime.dim(2:4)    = Dim(:)';
0097 avw.hdr.dime.pixdim(2:4) = [step step step];
0098 
0099 return
0100

Generated on Tue 27-Aug-2013 11:46:04 by m2html © 2005