Home > marsbar > mars_vol_check.m

mars_vol_check

PURPOSE ^

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

SYNOPSIS ^

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

DESCRIPTION ^

 FORMAT [samef, msg, chgf] = mars_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 difference flags
_______________________________________________________________________
 Copyright (C) 2008 Wellcome Trust Centre for Neuroimaging

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function [samef, msg, chgf] = mars_vol_check(varargin)
0002 % FORMAT [samef, msg, chgf] = mars_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 difference flags
0010 %_______________________________________________________________________
0011 % Copyright (C) 2008 Wellcome Trust Centre for Neuroimaging
0012 
0013 % Copied from spm_vol_check.m
0014 % Matthew Brett
0015 % $Id: spm_vol_check.m 2696 2009-02-05 20:29:48Z guillaume $
0016 
0017 
0018 [fnames samef msg] = deal({},1,{});
0019 
0020 if nargin < 1,
0021     return;
0022 end
0023 
0024 for i = 1:numel(varargin),
0025     vols   = varargin{i};
0026     if ~isempty(vols),
0027         if i == 1,
0028             dims   = cat(3,vols(:).dim);
0029             mats   = cat(3,vols(:).mat);
0030         else
0031             dims   = cat(3,dims,vols(:).dim);
0032             mats   = cat(3,mats,vols(:).mat);
0033         end
0034         fnames = {fnames{:}, vols(:).fname};
0035     end
0036 end
0037   
0038 nimgs = size(dims, 3);
0039 if nimgs < 2,
0040     return;
0041 end
0042 
0043 labs = {'dimensions', 'orientation & voxel size'};
0044 
0045 dimf = any(diff(dims(:,1:3,:),1,3));
0046 matf = any(any(diff(mats,1,3)));
0047 chgf = logical([dimf(:) matf(:)]);
0048 chgi = find(any(chgf, 2));
0049 if ~isempty(chgi),
0050     samef = 0;
0051     e1    = chgi(1);
0052     msg   = {['Images don''t all have the same ' ...
0053           sepcat(labs(chgf(e1,:)),', ')],...
0054         'First difference between image pair:',...
0055         fnames{e1},...
0056         fnames{e1+1}};
0057 end
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 

Generated on Wed 11-May-2022 16:26:09 by m2html © 2003-2019