Print

Print


[log in to unmask] wrote:

Dear SPM helpers,

I recall some email from many months ago which said the additional
significant locations are stored in the XYZ.mat file.
This is a binary file, however, and since I'm not a matlab maven, I don't
know how to open it for viewing.
Do you have a "magic word" to give me?

Hi Ruth:

Here is a "magic" matlab script which writes the XYZ.mat file to disk as an 8-bit binary image.

Hope this helps,

Tim

-- 
Timothy M. Ellmore
Laboratory of Brain and Cognition
National Institute of Mental Health
Building 10, Rm 4C-104
10 Center Dr., Bethesda MD 20892-1366
phone: (301) 435-4939
fax: (301) 402-0921
email: [log in to unmask]


% Matlab script to write the XYZ.mat file generated in SPM96
% to disk as an 8-bit binary mask. The script assumes that
% the normalized images used in the analysis had the dimensions
% 79,95,34, but these parameters may be changed to accomodate
% other dimensions.


% set the filename of the output image

outfname = 'mask.img';

% Image volume dimensions
XDIM = 79;
YDIM = 95;
ZDIM = 34;

% Image volume voxel sizes
XVOX = 2;
YVOX = 2;
ZVOX = 4;

% ANALYZE Origins for Volume with Dimensions of 79,95,34
XORIG = 40;
YORIG = 57;
ZORIG = 14;

% Number of voxels per image volume
NUMVOX = XDIM*YDIM*ZDIM;

% Allocate memory for image mask
mask  = zeros(1,NUMVOX);

% Read in XYZ.mat
load XYZ;

% Convert Talairach coordinates to ZERO-offset ANALYZE coordinates
XYZ(1,:)=XYZ(1,:)/XVOX+XORIG;
XYZ(2,:)=XYZ(2,:)/YVOX+YORIG;
XYZ(3,:)=XYZ(3,:)/ZVOX+ZORIG;

% Convert ANALYZE coordinates to ONE-offset indices
% to accommodate MATLAB's convention
vox_index=(XYZ(3,:)*YDIM+XYZ(2,:))*XDIM+XYZ(1,:)+1;

% Set corresponding entries in mask to 1.
clear XYZ;
mask(vox_index)=ones(1,length(vox_index));

% Write mask to disk as 8-bit image
fid=fopen(outfname,'w');
fwrite(fid,mask,'uchar');
fclose(fid);