0001 function V = nic_getVol(files, number)
0002
0003
0004
0005
0006
0007 countFiles = size(files, 1);
0008
0009
0010 firstFile = deblank(files(1, :));
0011
0012 [pathstr, imFile, imExtn] = fileparts(firstFile);
0013
0014
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
0031
0032 V = nic_spm_vol_ana(firstFile, 1);
0033 spm2Mat = V(1).mat;
0034 VN = nic_spm_vol_nifti(firstFile, 1);
0035 spm5Mat = VN(1).mat;
0036
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
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
0084 diffTimePoints = zeros(1, size(files, 1));
0085
0086
0087 for ii = 1:size(files, 1)
0088 diffTimePoints(ii) = nic_get_countTimePoints(deblank(files(ii, :)));
0089 end
0090
0091
0092
0093 if ~exist('number', 'var')
0094 number = [1:sum(diffTimePoints)];
0095 end
0096
0097
0098 V = repmat(V, sum(diffTimePoints), 1);
0099
0100 count = 0;
0101
0102 for ii = 1:size(files, 1)
0103
0104 for jj = 1:diffTimePoints(ii)
0105 count = count + 1;
0106 V(count) = nic_spm_vol_ana(deblank(files(ii, :)), jj);
0107 end
0108
0109 end
0110
0111
0112 V = V(number);
0113
0114 end
0115
0116
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