0001 function [samef, msg, chgf] = mars_vol_check(varargin)
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
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
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