[Insight-developers] request help with orientation and spm5
compatability
Richard Beare
richard.beare at gmail.com
Tue Sep 19 02:22:31 EDT 2006
Hi Everyone,
I'm striking what is probably a common issue. I hope someone has
suggestions to help clarify the best way forward.
I have images in minc form generated using dcm2mnc, and I want to use
the tissue classification facility in spm5. I have a script (at the
bottom of this message) that avoids the spm gui. Spm5 can deal with
either analyze of nifti files. I'd prefer to use nifti. I get a
variety of results depending on the way in which I convert from minc
to analyze/nifti. Problems seem to occur if the origin of the nifti
file isn't set correctly. I attempted to modify the setting using ITK,
but still fail. Here's a summary of what I've tried and what happens.
> mnc2nii -v
program: 2.0.10
libminc: 2.0.10
netcdf : 3.6.0-p1 of May 31 2005 14:23:06 $
HDF5 : 1.6.5
# initial minc file
> mincinfo A.mnc
image: signed__ short 0 to 8158
image dimensions: zspace yspace xspace
dimension name length step start
-------------- ------ ---- -----
zspace 256 0.898438 0
yspace 256 0.898438 0
xspace 248 0.6 0
1) mnc2nii -analyze -short A.mnc A.hdr
Display in spm5 reports:
voxsize= -0.6 x 0.898 x 0.898
origin = 124 128 128
Dir cos = [1 0 0, 0 1 0, 0 0 1 ]
2) mnc2nii -short A.mnc A.nii
report by mnc2nii
sto_xyz_matrix = '0.6 0 0 0 0 0.898438 0 0 0 0 0.898438 0 0 0 0 1'
sto_ijk matrix = '1.66667 0 0 0 0 1.11304 0 0 0 0 1.11304 0 0 0 0 1'
Display in spm5 reports:
voxsize= 0.6 x 0.898 x 0.898
origin = 1 1 1
Dir cos = [1 0 0, 0 1 0, 0 0 1 ]
avwhd from fsl reports:
qform_name Unknown
qform_code 0
qto_xyz:1 0.600000 0.000000 0.000000 0.000000
qto_xyz:2 0.000000 0.898438 0.000000 0.000000
qto_xyz:3 0.000000 0.000000 0.898438 0.000000
qto_xyz:4 0.000000 0.000000 0.000000 1.000000
qform_xorient Left-to-Right
qform_yorient Posterior-to-Anterior
qform_zorient Inferior-to-Superior
sform_name Scanner Anat
sform_code 1
sto_xyz:1 0.600000 0.000000 0.000000 0.000000
sto_xyz:2 0.000000 0.898438 0.000000 0.000000
sto_xyz:3 0.000000 0.000000 0.898438 0.000000
sto_xyz:4 0.000000 0.000000 0.000000 1.000000
sform_xorient Left-to-Right
sform_yorient Posterior-to-Anterior
sform_zorient Inferior-to-Superior
3) set origin using itkChangeInformationImageFilter->CenterImageOn()
Display in spm5 reports:
voxsize= 0.6 x 0.898 x 0.898
origin = -123 -127 129
Dir cos = [1 0 0, 0 1 0, 0 0 1 ]
avwhd from fsl reports:
qto_xyz:1 0.600000 0.000000 0.000000 74.100006
qto_xyz:2 0.000000 0.898438 0.000000 114.550842
qto_xyz:3 0.000000 0.000000 0.898438 -114.550842
qto_xyz:4 0.000000 0.000000 0.000000 1.000000
qform_xorient Left-to-Right
qform_yorient Posterior-to-Anterior
qform_zorient Inferior-to-Superior
sform_name Scanner Anat
sform_code 1
sto_xyz:1 0.600000 0.000000 -0.000000 74.100006
sto_xyz:2 0.000000 0.898438 -0.000000 114.550842
sto_xyz:3 0.000000 0.000000 0.898438 -114.550842
sto_xyz:4 0.000000 0.000000 0.000000 1.000000
sform_xorient Left-to-Right
sform_yorient Posterior-to-Anterior
sform_zorient Inferior-to-Superior
file_type NIFTI-1+
-------------------------------------------------------
Version 1) appears to segment sensibly in spm5, while the others
don't. Spm seems to assume that the centre of the image is the origin
when using an analyze file. However I don't have any success when
trying to reset the origin of nifti files using ITK based tools.
Am I approaching this the right way???
----------------------------------------------------------
% matlab script.
function doSegmentation(filen, fwhm)
%Performs segmentation analysis in SPM5. It outputs files c1*, wc1*,
mwc1* for grey matter,
%c2*, wc2*, mwc2* for white matter, and c3* wc2*, mwc2 for CSF.
%and smooth gray matter using fwhm kernel
%fwhm is not passed then no smooth will performed
%You can then run stats on wc1* using SPM or SnPM.
%-----------***Set Defaults and Paths***-----------------
%addpath /usr/local/spm5;
templatename='/usr/local/spm5b/templates/T1.nii';
root='/usr/local/spm5b/tpm';
%filen =fullfile(pwd, ImN);
%spm_defaults
global defaults
%defaults.analyze.flip=0;
%make voxels 1mm^3
%defaults.normalise.write.vox = [1 1 1];
%rmfield(defaults.normalize.write, 'bb');
%define the inputs to spm_preproc
opts.tpm = char(fullfile(root,'grey.nii'),...
fullfile(root,'white.nii'),...
fullfile(root,'csf.nii')); %use the default segmented templates
opts.ngaus = [3 2 2 5]; %number of Gaussians. Should I change this
to [2 2 2 4]?
opts.warpreg = 1; %if normalized images appear distorted, increase this to 10
opts.warpco = 25; %decrease for more detailed deformations, but this
will increase run time
opts.biasreg = 0.01; %medium bias regularization
opts.biasfwhm = 75; %higher for images with less bias, keep for now...
opts.regtype = 'mni'; %when using the mni templates .... otherwise
select'subj'?
opts.fudge = 5; %what does this do?
opts.samp = 3; %smaller values sample more of the data, but make
the script run slower
%mask=fullfile(subj_folder, 'Images_Pre/T1/Analyze/mlimage_1.img');
%opts.msk = mask; %mask the lesions
opts.msk ='';
%define the writing options
opts2.biascor =1; %write bias corrected images
opts2.GM =[1 1 1]; %write modulated, unmodulated normalized,
and native GM
opts2.WM =[1 1 1]; %write modulated, unmodulated normalized,
and native WM
opts2.CSF =[1 1 1]; %write modulated, unmodulated normalized,
and native CSF
opts2.cleanup = 0; %Do not cleanup
%get the image information
V=spm_vol(filen);
% get segmentation information
results = spm_preproc(V, opts);
% convert segmentation information to sn-files
[po,pin] = spm_prep2sn(results);
% write segmented data
spm_preproc_write(po,opts2);
%save the segmentation information
[pth fn ext] = fileparts(filen);
save(fullfile(pth, [fn '_seg_sn.mat']), '-struct', 'po');
save(fullfile(pth, [fn '_seg_inv_sn.mat']), '-struct', 'pin');
%define the images to normalize
grey = fullfile(pth, ['c1' fn '.nii']);
white = fullfile(pth, ['c2' fn '.nii']);
csf = fullfile(pth, ['c3' fn '.nii']);
Vgrey = spm_vol(grey);
Vwhite = spm_vol(white);
Vcsf = spm_vol(csf);
%write unmodulated normalized
spm_write_sn(Vgrey,po);
spm_write_sn(Vwhite,po);
spm_write_sn(Vcsf,po);
%------------------------***Smooth the Images***---------------------
%smooth the normalized grey matter images using an Gaussian kernel = fwhm
%create name strings for the images that need to be smoothed
if nargin >1
%fwhm = 12;
smoothed_grey =fullfile(pth, ['swc1' fn ext]);
pre_grey = fullfile(pth, ['wc1' fn ext]);
%smooth gray matter
Vpre_grey=spm_vol(pre_grey);
spm_smooth(Vpre_grey, smoothed_grey_pre, fwhm);
end
More information about the Insight-developers
mailing list