mri_open - function to call various mri data tools Usage: [p] = mri_open(p) p is a parameter structure (see eeg_toolbox_defaults for more details). In this function, it should contain at least the following string fields: p.mri.path - the directory location of the file to load p.mri.file - the name of the file to load p.mri.type - the file format (Analyze, FreeSurfer) Analyze is documented in AVW_*_READ FreeSurfer: http://surfer.nmr.mgh.harvard.edu/ The return structure creates or updates p.mri.data, which contains: p.mri.data.hdr struct, eg see avw_hdr_read p.mri.data.img 3D matrix of image values To plot the data returned, set p.mri.plot = 1 before loading, or use: avw_view(p.mri.data) See also, avw_img_read, cor_img_read, avw_view
0001 function [p] = mri_open(p) 0002 0003 % mri_open - function to call various mri data tools 0004 % 0005 % Usage: [p] = mri_open(p) 0006 % 0007 % p is a parameter structure (see eeg_toolbox_defaults for 0008 % more details). In this function, it should contain at least 0009 % the following string fields: 0010 % 0011 % p.mri.path - the directory location of the file to load 0012 % p.mri.file - the name of the file to load 0013 % p.mri.type - the file format (Analyze, FreeSurfer) 0014 % 0015 % Analyze is documented in AVW_*_READ 0016 % FreeSurfer: http://surfer.nmr.mgh.harvard.edu/ 0017 % 0018 % The return structure creates or updates p.mri.data, which contains: 0019 % 0020 % p.mri.data.hdr struct, eg see avw_hdr_read 0021 % p.mri.data.img 3D matrix of image values 0022 % 0023 % To plot the data returned, set p.mri.plot = 1 before loading, or use: 0024 % 0025 % avw_view(p.mri.data) 0026 % 0027 % See also, avw_img_read, cor_img_read, avw_view 0028 % 0029 0030 % $Revision: 1.1 $ $Date: 2004/11/12 01:32:35 $ 0031 0032 % Licence: GNU GPL, no express or implied warranties 0033 % History: 08/2002, Darren.Weber_at_radiology.ucsf.edu 0034 % 11/2002, Darren.Weber_at_radiology.ucsf.edu 0035 % corrected some bugs and mistakes on p.mri.type 0036 % 0037 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% 0038 0039 version = '$Revision: 1.1 $'; 0040 fprintf('MRI_OPEN [v %s]\n',version(11:15)); 0041 0042 if ~exist('p','var'), 0043 [p] = eeg_toolbox_defaults; 0044 fprintf('...creating default p structure.\n'); 0045 elseif isempty(p), 0046 [p] = eeg_toolbox_defaults; 0047 fprintf('...creating default p structure.\n'); 0048 end 0049 0050 type = lower(p.mri.type); 0051 0052 switch type, 0053 0054 case 'analyze', 0055 0056 [path,name,ext] = fileparts(strcat(p.mri.path,filesep,p.mri.file)); 0057 file = fullfile(path,[name ext]); 0058 0059 fprintf('...loading Analyze MRI from:\n... %s\n\n',file); 0060 0061 % see avw_img_read for details about orientation 0062 switch p.mri.orient 0063 case 'auto', mriOrient = ''; 0064 case 'axial unflipped', mriOrient = 0; 0065 case 'coronal unflipped', mriOrient = 1; 0066 case 'sagittal unflipped', mriOrient = 2; 0067 case 'axial flipped', mriOrient = 3; 0068 case 'coronal flipped', mriOrient = 4; 0069 case 'sagittal flipped', mriOrient = 5; 0070 otherwise, mriOrient = ''; 0071 end 0072 0073 [ p.mri.data, p.mri.IEEEMachine ] = avw_img_read(file, mriOrient, p.mri.IEEEMachine); 0074 0075 case 'brainstorm', 0076 0077 fprintf('...BrainStorm not supported yet\n\n'); 0078 return 0079 %fprintf('...loading BrainStorm data from:\n... %s\n',file); 0080 0081 case {'cor','freesurfer'}, 0082 0083 % Get Freesurfer data 0084 [path,name,ext] = fileparts(strcat(p.mri.path,filesep,p.mri.file)); 0085 file = fullfile(path,[name ext]); 0086 0087 [ p.mri.data, p.mri.IEEEMachine ] = cor_img_read(path, p.mri.IEEEMachine); 0088 0089 otherwise, 0090 fprintf('...MRI format: %s\n', p.mri.type); 0091 fprintf('...Sorry, cannot load this data format at present.\n\n'); 0092 return; 0093 end 0094 0095 if p.mri.plot, avw_view(p.mri.data); end 0096 0097 return