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

vb_get_brain_mask

PURPOSE ^

Get brain/cortex mask image from subject brain mask file

SYNOPSIS ^

function [avw ,Xcenter] = vb_get_brain_mask(fname,region_id,LR,step,Radius)

DESCRIPTION ^

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

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