Andreas,
you can use the reorient function from John Ashburner, attached.
best,
Denis
Andreas Frank wrote:
> Dear SPMers!
>
> A maybe simple question:
>
> I have an anatomical analyze-file (ana.img and ana.hdr), which I want to
> be reoriented for the use with other software. Using the "reorient
> image" function SPM99 reorients the image creating a ana.mat file.
> The problem is that the software that needs the analyze-file doesn´t
> understand *.mat-files.
> Somehow I have to reslice my img-image, putting the .mat-informations
> into the header. What is the best way to do that?
>
> Thanks in advance
>
> Andreas
function reorient(PP)
% Re-orient images
% The function reslices the input images to a resolution of 1mm.
% Output images (with the prefix "r") are written in the transverse
% orientation (using information from the ".mat" files).
%_______________________________________________________________________
% %W% John Ashburner %E%
if nargin<1, PP = spm_get(Inf,'*.img','Select file to reorient'); end;
VV = spm_vol(PP);
for V=VV',
d = V.dim(1:3);
c = [ 1 1 1 1
1 1 d(3) 1
1 d(2) 1 1
1 d(2) 1 1
d(1) 1 1 1
d(1) 1 d(3) 1
d(1) d(2) 1 1
d(1) d(2) 1 1]';
tc = V.mat(1:3,1:4)*c;
mx = round(max(tc,[],2)');
mn = round(min(tc,[],2)');
% to reorient in the transverse plane
mat = spm_matrix([mn-1]);
% to reorient in the coronal plane
% mat = spm_matrix([0 0 0 pi/2])*spm_matrix([mn-1]);
dim = (mat\[mx 1]')';
VO = V;
[lpath,name,ext] = fileparts(V.fname);
VO.fname = fullfile(lpath,['r' name ext]);
VO.dim(1:3) = dim(1:3);
VO.mat = mat;
spm_progress_bar('Init',dim(3),'reslicing...','planes completed');
VO = spm_create_image(VO);
for i=1:dim(3),
M = inv(spm_matrix([0 0 -i])*inv(VO.mat)*V.mat);
img = spm_slice_vol(V,M,dim(1:2),-9); % -9 for sinc
spm_write_plane(VO,img,i);
spm_progress_bar('Set',i)
end;
spm_progress_bar('Clear');
end;
return;
|