Home > rest_20090422 > rest_spm5_files > nic_getVol.m

nic_getVol

PURPOSE ^

USE SPM2 functions to read the volume and if any warning message appears

SYNOPSIS ^

function V = nic_getVol(files, number)

DESCRIPTION ^

 USE SPM2 functions to read the volume and if any warning message appears
 for ignoring hdr.hist.orient field then use spm5 function to get the
 volume

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

DOWNLOAD ^

nic_getVol.m

SOURCE CODE ^

0001 function V = nic_getVol(files, number)
0002 % USE SPM2 functions to read the volume and if any warning message appears
0003 % for ignoring hdr.hist.orient field then use spm5 function to get the
0004 % volume
0005 
0006 % number of files
0007 countFiles = size(files, 1);
0008 
0009 % first file
0010 firstFile = deblank(files(1, :));
0011 
0012 [pathstr, imFile, imExtn] = fileparts(firstFile);
0013 
0014 % Turn off all warnings
0015 warning off all;
0016 
0017 [spmPath, spm2Path, spm5Path] = nic_getSPMPath(imExtn);
0018 
0019 addpath(spmPath);
0020 
0021 oldDir = pwd;
0022 
0023 if strcmpi(imExtn, '.img')
0024     nic_check_hdr_file(firstFile);
0025 end
0026 
0027 try
0028 
0029     if strcmp(spmPath, spm2Path)
0030         % Use orientation to determine whether it is nifti compatible
0031         % analyze image or regular analyze image
0032         V = nic_spm_vol_ana(firstFile, 1); % Get mat file info using spm2
0033         spm2Mat = V(1).mat;
0034         VN = nic_spm_vol_nifti(firstFile, 1); % Get mat file info using spm5
0035         spm5Mat = VN(1).mat;
0036         % Get the differenic_e
0037         diffV = VN(1).mat(:, 4) - V(1).mat(:, 4);
0038         if length(find(diffV == 0)) ~= 4
0039             warning('Ignoring hdr.hist.orient field');
0040         end
0041 
0042     else
0043         V = nic_spm_vol_nifti(firstFile, 1);
0044     end
0045 
0046     warnMsg = lastwarn;
0047 
0048     lastwarn('');
0049 
0050     warning on;
0051 
0052     % USE SPM5 functions to deal this
0053     if nic_findstr(warnMsg, 'Ignoring hdr.hist.orient field')
0054         spmPath = spm5Path;
0055     end
0056 
0057     addpath(spmPath);
0058     
0059     if strcmpi(spmPath, spm5Path)
0060 
0061         clear V;
0062         try
0063             cd(spmPath);        
0064             V = nic_spm_vol(files);
0065 
0066             if exist('number', 'var')
0067                 if max(number) > length(V)
0068                     error(['Image number requested exceeds the number of images']);
0069                 end
0070                 V = V(number);
0071             end
0072             cd(oldDir);
0073         catch
0074 
0075             cd(oldDir);
0076             nic_displayErrorMsg;
0077 
0078         end
0079 
0080     else
0081 
0082 
0083         % different time points
0084         diffTimePoints = zeros(1, size(files, 1));
0085 
0086         % loop over files
0087         for ii = 1:size(files, 1)
0088             diffTimePoints(ii) = nic_get_countTimePoints(deblank(files(ii, :)));
0089         end
0090         % end loop over files
0091 
0092 
0093         if ~exist('number', 'var')
0094             number = [1:sum(diffTimePoints)];
0095         end
0096 
0097         % replicate volume
0098         V = repmat(V, sum(diffTimePoints), 1);
0099 
0100         count = 0;
0101         % loop over files
0102         for ii = 1:size(files, 1)
0103             % loop over different time points
0104             for jj = 1:diffTimePoints(ii)
0105                 count = count + 1;
0106                 V(count) = nic_spm_vol_ana(deblank(files(ii, :)), jj);
0107             end
0108             % end loop over different time points
0109         end
0110         % end loop over files
0111 
0112         V = V(number);
0113 
0114     end
0115 
0116     % add pixdim field
0117     if ~isfield(V(1).private.hdr, 'pixdim')
0118 
0119         for nVol = 1:length(V)
0120             V(nVol).private.hdr.pixdim = V(nVol).private.hdr.dime.pixdim;
0121         end
0122 
0123     end
0124 
0125 catch
0126     lastwarn('');
0127     warning on;
0128     nic_displayErrorMsg;
0129 end

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