Home > rest_20090422 > rest_to4d.m

rest_to4d

PURPOSE ^

Build a 4D matrix for REST from series of Brain's volume/(time point). By Xiao-Wei Song

SYNOPSIS ^

function [AllVolume, VoxelSize, ImgFileList, Header] =rest_to4d(ADataDir)

DESCRIPTION ^

Build a 4D matrix for REST from series of Brain's volume/(time point). By Xiao-Wei Song
------------------------------------------------------------------------------------------------------------------------------
    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
     Mail to Authors:  <a href="Dawnwei.Song@gmail.com">Xiaowei Song</a>; <a href="ycg.yan@gmail.com">Chaogan Yan</a> 
    Version=1.3;
    Release=20090321;
   Revised by YAN Chao-Gan 080610: NIFTI compatible
   Last Revised by YAN Chao-Gan, 090321. Data in processing will not be converted to the format 'int16'.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

DOWNLOAD ^

rest_to4d.m

SOURCE CODE ^

0001 function [AllVolume, VoxelSize, ImgFileList, Header] =rest_to4d(ADataDir)
0002 %Build a 4D matrix for REST from series of Brain's volume/(time point). By Xiao-Wei Song
0003 %------------------------------------------------------------------------------------------------------------------------------
0004 %    Copyright(c) 2007~2010
0005 %    State Key Laboratory of Cognitive Neuroscience and Learning in Beijing Normal University
0006 %    Written by Xiao-Wei Song
0007 %    http://resting-fmri.sourceforge.net
0008 %     Mail to Authors:  <a href="Dawnwei.Song@gmail.com">Xiaowei Song</a>; <a href="ycg.yan@gmail.com">Chaogan Yan</a>
0009 %    Version=1.3;
0010 %    Release=20090321;
0011 %   Revised by YAN Chao-Gan 080610: NIFTI compatible
0012 %   Last Revised by YAN Chao-Gan, 090321. Data in processing will not be converted to the format 'int16'.
0013 
0014     theFileList = dir(ADataDir);    
0015     ImgFileList ={};
0016     for x = 3:size(struct2cell(theFileList),2)
0017         if strcmpi(theFileList(x).name(end-3:end), '.hdr') 
0018             if strcmpi(theFileList(x).name(1:end-4), theFileList(x+1).name(1:end-4))
0019                 ImgFileList=[ImgFileList; {theFileList(x).name(1:end-4)}];
0020             else
0021                 error('*.{hdr,img} should be pairwise. Please re-examin them.');
0022             end
0023         end
0024     end
0025     clear theFileList;
0026     
0027     if size(ImgFileList,1)<10,
0028         warning('There are too few time points.(i.e. The number of the time points is less than 10)');
0029     end
0030     
0031     %read the normalized functional images
0032     % -------------------------------------------------------------------------
0033     fprintf('\n\t Read 3D EPI functional images: "%s".', ADataDir);
0034     theDataType ='double';    %Default data-type I assumed!
0035     for x = 1:size(ImgFileList,1),            
0036         rest_waitbar(x/size(ImgFileList,1), ...
0037                     ImgFileList{x}, ...
0038                     'Build 3D+time Dataset','Child','NeedCancelBtn');
0039         theFilename = fullfile(ADataDir,ImgFileList{x});
0040         
0041         
0042         [theOneTimePoint, VoxelSize, Header] = rest_readfile(theFilename);
0043         
0044         %AllVolume(:,:,:,x) = uint16(theOneTimePoint);    %Dynamic decision of which data-type I choose! 20071031
0045         if theDataType=='uint16',
0046             AllVolume(:,:,:,x) = uint16(theOneTimePoint);
0047         elseif    theDataType=='double',
0048             AllVolume(:,:,:,x) = (theOneTimePoint);
0049         else
0050             rest_misc('ComplainWhyThisOccur');
0051         end
0052         if x==1,            
0053             tmpData=theOneTimePoint(0~=theOneTimePoint);
0054             if 0 %Revised by YAN Chao-Gan, 090321. Data will not be converted to the format 'int16'. %length(tmpData)>1000 && mean(abs(tmpData))>100,
0055                 theDataType ='uint16';
0056                 AllVolume =uint16(AllVolume);
0057                 AllVolume(:,:,:,x) = uint16(theOneTimePoint);
0058                 clear tmpData
0059                 
0060                 AllVolume =repmat(AllVolume, [1,1,1, size(ImgFileList,1)]);
0061             else
0062                 %Double!
0063                 theDataType ='double';
0064                 AllVolume =repmat(AllVolume, [1,1,1, size(ImgFileList,1)]);
0065             end
0066         end
0067         if ~mod(x,5)
0068             fprintf('.');        
0069         end
0070     end     
0071     VoxelSize = VoxelSize';
0072     fprintf('\n');

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