Susana,
This little function might be close to what you need. Let me know if you have any questions.
You could try this, although I'm assuming the coordinates you have are the same as the MNI T1 template coordinates. Also, I haven't tested this, but it should work unless I made a typo.
%%----%%
function V = create_mask
% function V = create_mask
% creates a 2x2x2 mm (91x109x91 voxels) mask in MNI space
%
% I am assuming the voxels are 2x2x2 mm, and size of your mask is
% 91x109x91 voxels. This could be modified of course.
% Therefore, the numbers you are entering should be voxel coordinates.
% e.g. coordinate [0,0,1] is 2 mm from the origin along the z-axis.
% You could modify this code to allow for coordinates to be expressed in
% mm, and/or to allow for arbitrary voxel sizes in the final mask image.
V = spm_vol(fullfile(spm('Dir'),'templates','T1.mnc'));
fname = fullfile(pwd,input('enter output file name for mask','s'));
[pth,nam,ext] = fileparts(fname);
fname = fullfile(pth,[nam,'.img']);
V.fname = fname;
Y = zeros(V.dim(1:3));
mask = input('voxels to mask?'); % n-by-3 matrix n>=0
% at this point you should type in, or copy/paste, the voxel coordinates
% as a MATLAB matrix, where x,y,z are in the 1st,2nd,3rd columns
% respectively (e.g. mask = [0,0,1; 0,0,2; 0,0,3]).
if size(mask,2)~=3,
error('mask should be n-by-3');
end
for i=1:size(mask,1),
Y(mask(i,:))=1;
end
V = spm_write_vol(V,Y);
return;
-Matt Senjem
On 2005-03-08 (Tue) at 18:35:39 -0500, Susana Novais Santos
<[log in to unmask]> wrote:
> Dear All,
> I need to create a mask in order to display a certain set of voxels. I
> have the MNI coordinates of the voxels of interest but do not know how
> to use that information to create an actual image. I would like to
> build a mask by setting those voxels to 1 and the remaining to 0. How
> do I construct the volume matrix?
> Thanks in advance for any help,
> Susana
|