Dear Thomas,
if you have an image with the desired dimensions and voxelsize, try the
attached piece of code by running it from the matlab command line.
Please check, wheter it works for your purpose, since I have originally
used it in some other context.
You may want to choose another an interpolation method in line 15
dr(:,:,slice)=spm_slice_vol(Vr,M,Vi.dim(1:2),0);
the last number (0) sets nearest neighbour interpolation for remapping
voxels (e.g., a binary mask). Please refer to spm_slice_vol.m for
possible interpolation methods.
Good luck,
Kai
Thomas Whitford schrieb:
>Dear SPMers,
>
>Would someone please be able to tell me how to change the voxel size of an
>image without changing its dimensions? I do not currently have an image in
>the desired space with the desired voxel size.
>
>Thanks in advance
>Tom
>
>
>
--
_______________________________
Dr. Kai Lutz
Psychologisches Institut,
Lehrstuhl für Neuropsychologie
Treichlerstr. 10
8032 Zürich
Switzerland
Phone: 0041-1 634 1573
Fax : 0041-1 634 4342
function chg_vx;
Timg = spm_get(1,'*.img','select image with desired dimension');
ROIimg = spm_get(inf,'*.img','select images with ''wrong'' dimension');
for r=1:size(ROIimg,1)
Vi = spm_vol(Timg(1,:)); di = spm_read_vols(Vi);
Vr = spm_vol(ROIimg(r,:)); dr = spm_read_vols(Vr);
%interpolate, if dimensions are different
step = Vr.dim(1:3) ./ Vi.dim(1:3);
if any(step~=1)
dr=zeros(Vi.dim(1:3));
for slice=1:Vi.dim(3)
M = inv(spm_matrix([0 0 -slice 0 0 0 1 1 1])*inv(Vi.mat)*Vr.mat);
dr(:,:,slice)=spm_slice_vol(Vr,M,Vi.dim(1:2),0); %0 -> nearest neighbour, -3 -> sinc interpolation
end
%save remapped image
[prname frname rext]=fileparts(ROIimg(r,:));
nname=fullfile(prname,[frname 'i' rext]);
Vo=Vi;
Vo.fname=nname;
spm_write_vol(Vo,dr);
end
end
|