> I was wondering how to obtain the maximum intensity value of a t-
> map, which I have generated using a different program. I had a
> MINC file, which we smoothed, which resulted in a .IMG file. We
> want do determine the max intensity of this .IMG file.
Copy/paste the following into Matlab:
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Select one .img file
P = spm_get(1,'*.img');
% Read header/mat file information about the image
V = spm_vol(P);
% Initialise maximum value to the most negative possible
mx = -Inf;
% loop over planes (dim(1:3) is the size of the image)
for i=1:V.dim(3),
% The dimensions of the output image. Co-ordinates
% in this image are x = 1..d(1) and y = 1..d(2)
d = V.dim(1:2);
% An affine transformation mapping from x,y to some
% position in the image, such that the co-ordinate
% x,y in the output image has the following
% co-ordinate in the 3D volume:
% pos = M(1:3,:)*[x y 0 1]';
M = spm_matrix([0 0 i]);
% Sample the volume V, according to the transformation
% matrix M, to create a d(1) by d(2) image using
% interpolation method 0 (nearest neighbour).
img = spm_slice_vol(V,M,d,0);
% Maximum value in this plane is:
mxp = max(img(:));
% Maximum value encountered so far is:
mx = max(mx,mxp);
end;
% Display the maximum value
fprintf('Maximum value is %g\n', mx);
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
I included a few extra comments in the code because someone may
find them of interest.
Best regards,
-John
--
Dr John Ashburner.
Functional Imaging Lab., 12 Queen Square, London WC1N 3BG, UK.
tel: +44 (0)20 78337491 or +44 (0)20 78373611 x4381
fax: +44 (0)20 78131420 http://www.fil.ion.ucl.ac.uk/~john
|