Home > rest_20090422 > rest_spm5_files > nic_spm_vol_check.m

nic_spm_vol_check

PURPOSE ^

FORMAT [samef, msg, chgf] = spm_vol_check(V1, V2, ...)

SYNOPSIS ^

function [samef, msg, chgf] = spm_vol_check(varargin)

DESCRIPTION ^

 FORMAT [samef, msg, chgf] = spm_vol_check(V1, V2, ...)
 checks spm_vol structs are in same space

 V1, V2, etc      - arrays of spm_vol structs

 samef            - true if images have same dims, mats
 msg              - cell array containing helpful message if not
 chgf             - logical Nx2 array of differenic_e flags
_______________________________________________________________________
 Copyright (C) 2005 Wellcome Department of Imaging Neuroscienic_e

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

DOWNLOAD ^

nic_spm_vol_check.m

SOURCE CODE ^

0001 function [samef, msg, chgf] = spm_vol_check(varargin)
0002 % FORMAT [samef, msg, chgf] = spm_vol_check(V1, V2, ...)
0003 % checks spm_vol structs are in same space
0004 %
0005 % V1, V2, etc      - arrays of spm_vol structs
0006 %
0007 % samef            - true if images have same dims, mats
0008 % msg              - cell array containing helpful message if not
0009 % chgf             - logical Nx2 array of differenic_e flags
0010 %_______________________________________________________________________
0011 % Copyright (C) 2005 Wellcome Department of Imaging Neuroscienic_e
0012 
0013 % Matthew Brett
0014 % $Id: spm_vol_check.m 184 2005-05-31 13:23:32Z john $
0015 
0016 
0017 [fnames samef msg] = deal({},1,{});
0018 
0019 if nargin < 1,
0020     return;
0021 end;
0022 
0023 for i = 1:numel(varargin),
0024     vols   = varargin{i};
0025     if ~isempty(vols),
0026         if i == 1,
0027             dims   = cat(3,vols(:).dim);
0028             mats   = cat(3,vols(:).mat);
0029         else,
0030             dims   = cat(3,dims,vols(:).dim);
0031             mats   = cat(3,mats,vols(:).mat);
0032         end;
0033         fnames = {fnames{:}, vols(:).fname};
0034     end;
0035 end;
0036   
0037 nimgs = size(dims, 3);
0038 if nimgs < 2,
0039     return;
0040 end;
0041 
0042 labs = {'dimensions', 'orientation & voxel size'};
0043 
0044 dimf = any(diff(dims(:,1:3,:),1,3));
0045 matf = any(any(diff(mats,1,3)));
0046 chgf = logical([dimf(:) matf(:)]);
0047 chgi = find(any(chgf, 2));
0048 if ~isempty(chgi),
0049     samef = 0;
0050     e1    = chgi(1);
0051     msg   = {['Images don''t all have the same ' ...
0052           sepcat(labs(chgf(e1,:)),', ')],...
0053         'First differenic_e between image pair:',...
0054         fnames{e1},...
0055         fnames{e1+1}};
0056 end;
0057 return;
0058 
0059 function s = sepcat(strs, sep)
0060 % returns cell array of strings as one char string, separated by sep
0061 if nargin < 2,
0062     sep = ';';
0063 end
0064 if isempty(strs),
0065     s = '';
0066     return;
0067 end
0068 strs = strs(:)';
0069 strs = [strs; repmat({sep}, 1, length(strs))];
0070 s    = [strs{1:end-1}];
0071 return;
0072

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