Home > phiwave > @slover > private > pr_volmaxmin.m

pr_volmaxmin

PURPOSE ^

returns max and min value in image volume

SYNOPSIS ^

function [mx,mn] = pr_volmaxmin(vol)

DESCRIPTION ^

 returns max and min value in image volume
 FORMAT [mx,mn] = pr_volmaxmin(vol)
 
 Input
 vol      - image name or vol struct
 
 Outputs
 mx       - maximum
 mn       - minimum
 
 $Id: pr_volmaxmin.m,v 1.1 2005/04/20 15:05:00 matthewbrett Exp $

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 function [mx,mn] = pr_volmaxmin(vol)
0002 % returns max and min value in image volume
0003 % FORMAT [mx,mn] = pr_volmaxmin(vol)
0004 %
0005 % Input
0006 % vol      - image name or vol struct
0007 %
0008 % Outputs
0009 % mx       - maximum
0010 % mn       - minimum
0011 %
0012 % $Id: pr_volmaxmin.m,v 1.1 2005/04/20 15:05:00 matthewbrett Exp $
0013 
0014 if nargin < 1
0015   error('Need volume to process'); 
0016 end
0017 if ischar(vol)
0018   vol = spm_vol(vol);
0019 end
0020 if ~isstruct(vol)
0021   error('vol did not result in vol struct');
0022 end
0023 if mars_struct('isthere', vol, 'imgdata')
0024   tmp = vol.imgdata(finite(vol.imgdata));
0025   mx = max(tmp);
0026   mn = min(tmp);
0027 else
0028     mx = -Inf;mn=Inf;
0029     for i=1:vol.dim(3),
0030       tmp = spm_slice_vol(vol,spm_matrix([0 0 i]),vol.dim(1:2),[0 NaN]);
0031       tmp = tmp(find(finite(tmp(:))));
0032       if ~isempty(tmp)
0033     mx = max([mx; tmp]);
0034     mn = min([mn; tmp]);
0035       end
0036     end
0037 end
0038 return
0039

Generated on Wed 06-Jul-2005 18:07:21 by m2html © 2003