Dear SPM/VBMers:
Someone has been asked if there is a quick fix for automatically
re-centerimg the AC into the origin for structural images. Apparently,
the spm_maff in the segmentation does not work very well if your initial
position is too far away, so we have asked people to manually reorient
the origin within the radius of 3mm around AC. It is a little bit
laborious if you have hundreds of brains. The following codes will be a
quick fix for reorienting T1 structural images. It is not very
efficient, but it works (at least in my case, for 300 brains).
John will probabaly suggest people to try the segmentation in SPM8b, as
the segmentation routine now includes the skull and scalp templates ,
and should be more robust for the mutual information affine registration.
The attached picture showed how robust this fix is. The bottom image is
in the wrong orientation, and it is also far away from the origin. The
top image is the re-oriented version after running this code. All the
routines were written by John, I just put them all together.
To run the code,
p=spm_select(inf,'image');
auto_reorient(p)
function auto_reorient(p)
spmDir=which('spm');
spmDir=spmDir(1:end-5);
tmpl=[spmDir 'canonical\avg152T1.nii'];
vg=spm_vol(tmpl);
flags.regtype='rigid';
%p=spm_select(inf,'image');
for i=1:size(p,1)
f=strtrim(p(i,:));
spm_smooth(f,'temp.nii',[12 12 12]);
vf=spm_vol('temp.nii');
[M,scal] = spm_affreg(vg,vf,flags);
M3=M(1:3,1:3);
[u s v]=svd(M3);
M3=u*v';
M(1:3,1:3)=M3;
N=nifti(f);
N.mat=M*N.mat;
create(N);
end
function auto_reorient(p)
spmDir=which('spm');
spmDir=spmDir(1:end-5);
tmpl=[spmDir 'canonical\avg152T1.nii'];
vg=spm_vol(tmpl);
flags.regtype='rigid';
%p=spm_select(inf,'image');
for i=1:size(p,1)
f=strtrim(p(i,:));
spm_smooth(f,'temp.nii',[12 12 12]);
vf=spm_vol('temp.nii');
[M,scal] = spm_affreg(vg,vf,flags);
M3=M(1:3,1:3);
[u s v]=svd(M3);
M3=u*v';
M(1:3,1:3)=M3;
N=nifti(f);
N.mat=M*N.mat;
create(N);
end
|