Home > rest_20090422 > rest_loadmask.m

rest_loadmask

PURPOSE ^

Load mask for REST by Xiao-Wei Song

SYNOPSIS ^

function mask=rest_loadmask(AX, AY, AZ, AMaskFilename)

DESCRIPTION ^

Load mask for REST by Xiao-Wei Song
 AX, AY, AZ should be the same size as the Volume, this size should be set automatically, but I use this for compatibility. And I specially give the code  for many files' use already. And another reason is the null mask need it
 AMaskFilename should be the mask filename
------------------------------------------------------------------------------------------------------------------------------
    Copyright(c) 2007~2010
    State Key Laboratory of Cognitive Neuroscience and Learning in Beijing Normal University
    Written by Xiao-Wei Song 
    http://resting-fmri.sourceforge.net
 dawnsong, 20070509
------------------------------------------------------------------------------------------------------------------------------
Vesa.Kiviniemi@ppshp.fi found Yong He's bug in loading a null-mask
     Mail to Authors:  <a href="Dawnwei.Song@gmail.com">Xiaowei Song</a>; <a href="ycg.yan@gmail.com">Chaogan Yan</a> 
    Version=1.2;
    Release=20081225;
   Revised by YAN Chao-Gan 080610: NIFTI compatible
   Revised by Yan Chao-Gan 081225: use the new mask files.
   Revised by YAN Chao-Gan, 090420. Revise the input mask to ensure that it only contains 0 and 1.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

DOWNLOAD ^

rest_loadmask.m

SOURCE CODE ^

0001 function mask=rest_loadmask(AX, AY, AZ, AMaskFilename)
0002 %Load mask for REST by Xiao-Wei Song
0003 % AX, AY, AZ should be the same size as the Volume, this size should be set automatically, but I use this for compatibility. And I specially give the code  for many files' use already. And another reason is the null mask need it
0004 % AMaskFilename should be the mask filename
0005 %------------------------------------------------------------------------------------------------------------------------------
0006 %    Copyright(c) 2007~2010
0007 %    State Key Laboratory of Cognitive Neuroscience and Learning in Beijing Normal University
0008 %    Written by Xiao-Wei Song
0009 %    http://resting-fmri.sourceforge.net
0010 % dawnsong, 20070509
0011 %------------------------------------------------------------------------------------------------------------------------------
0012 %Vesa.Kiviniemi@ppshp.fi found Yong He's bug in loading a null-mask
0013 %     Mail to Authors:  <a href="Dawnwei.Song@gmail.com">Xiaowei Song</a>; <a href="ycg.yan@gmail.com">Chaogan Yan</a>
0014 %    Version=1.2;
0015 %    Release=20081225;
0016 %   Revised by YAN Chao-Gan 080610: NIFTI compatible
0017 %   Revised by Yan Chao-Gan 081225: use the new mask files.
0018 %   Revised by YAN Chao-Gan, 090420. Revise the input mask to ensure that it only contains 0 and 1.
0019     
0020     
0021 %Load mask, copy from reho.m revised by Dawnwei.Song, 20070504
0022 [pathstr, name, ext, versn] = fileparts(mfilename('fullpath'));
0023 
0024 if ( strcmp(AMaskFilename, '')|| (isnumeric(AMaskFilename) && AMaskFilename==0) )% like the old parameter, back-compatible  Xiaowei Song, 20070421
0025     mask=ones(AX, AY, AZ);
0026 elseif( strcmpi(AMaskFilename, 'Default')||( isnumeric(AMaskFilename) && AMaskFilename==1) ) % like the old parameter    , back-compatible  Xiaowei Song, 20070421
0027     switch int2str([AX, AY, AZ])
0028         case '79  95  69'   % 'default''[2 2 2]'
0029             [mask, vsizeTmp, Header]=rest_readfile([pathstr '/mask/BrainMask_05_79x95x69.img']); %YAN Chao-Gan 081225: New masks.
0030         case '53  63  46'   % 'default''[3 3 3]'
0031             [mask, vsizeTmp, Header]=rest_readfile([pathstr '/mask/BrainMask_05_53x63x46.img']); %YAN Chao-Gan 081225: New masks.
0032         case '91  109  91'  % 'template''[2 2 2]'
0033             [mask, vsizeTmp, Header]=rest_readfile([pathstr '/mask/BrainMask_05_91x109x91.img']); %YAN Chao-Gan 081225: New masks.
0034         case '61  73  61'   % 'template' '[3 3 3]'
0035             [mask, vsizeTmp, Header]=rest_readfile([pathstr '/mask/BrainMask_05_61x73x61.img']); %YAN Chao-Gan 081225: New masks.
0036         otherwise
0037             error(sprintf('There are no appropriate default mask file:\n\tVolume size=79*95*69 ,Voxel size=2*2*2;\n\tVolume size=53*63*46, Voxel size=3*3*3;\n\tVolume size=91*109*91, Voxel size=2*2*2;\n\tVolume size=61*73*61, Voxel size=3*3*3;\n Please set bMask = 0.'));
0038     end %end switch
0039 else        % new,  Xiaowei Song, 20070421
0040     if (ischar(AMaskFilename))
0041         %if is img file, read and load
0042         if strcmpi(AMaskFilename(end-3:end), '.img')
0043             [mask, vsizeTmp, Header]=rest_readfile(AMaskFilename);            
0044         else%if is mat file, direct load
0045             load(AMaskFilename);
0046         end
0047     else
0048         error('There are no appropriate mask file. Please set bMask = 0.');
0049     end
0050 end %mask select end
0051 
0052 mask =logical(mask); %Revised by YAN Chao-Gan, 090420. Revise the mask to ensure that it only contains 0 and 1.
0053 
0054 %Check whether mask is 3d
0055 if ndims(mask)~=3
0056     error('mask error, mask is not 3d');
0057 end    
0058 
0059 % Brutely check the mask's size to make sure whether the mask's size same to the required size
0060 if ~all(size(mask)==[AX, AY, AZ]),    
0061     %warning(sprintf('\n\tMask does not match. Brutely use "No Mask".\n\tMask size is %dx%dx%d, not equal to required size %dx%dx%d',size(mask), [AX, AY, AZ]));
0062     
0063     %20070820 Zang's advice
0064     error(sprintf('\n\tMask does not match.\n\tMask size is %dx%dx%d, not same with required size %dx%dx%d',size(mask), [AX, AY, AZ]));
0065     
0066     mask = ones(AX, AY, AZ);    
0067 end

Generated on Wed 29-Apr-2009 01:06:38 by m2html © 2005