general-discussion > niak_write_vol orientation issue.
Showing 1-3 of 3 posts
Display:
Results per page:
Sep 20, 2015  12:09 PM | Thomas Alderson
niak_write_vol orientation issue.
Dear Niakers!

When I open a file with niak_read_vol and then close a file with niak_write_vol (see below) the qform orientation is different form the original file. Why is this happening? How can I keep the orientations consistent?

fslhd wmparc2diff_1mm.nii (original)

qform_name Scanner Anat
qform_code 1
qto_xyz:1 -0.999872 0.000907 -0.015991 132.987595
qto_xyz:2 -0.015548 -0.294768 0.955442 -77.595352
qto_xyz:3 0.003847 -0.955569 -0.294744 163.080612
qto_xyz:4 0.000000 0.000000 0.000000 1.000000
qform_xorient Right-to-Left
qform_yorient Superior-to-Inferior
qform_zorient Posterior-to-Anterior
sform_name Scanner Anat
sform_code 1
sto_xyz:1 -0.999873 0.000833 -0.015935 132.987595
sto_xyz:2 -0.015473 -0.294768 0.955443 -77.595352
sto_xyz:3 0.003902 -0.955568 -0.294744 163.080612
sto_xyz:4 0.000000 0.000000 0.000000 1.000000
sform_xorient Right-to-Left
sform_yorient Superior-to-Inferior
sform_zorient Posterior-to-Anterior
file_type NIFTI-1+
file_code 1
descrip FreeSurfer May 13 2013
aux_file

fslhd wmparcmask_1mm.nii (opened and closed)

qform_name Scanner Anat
qform_code 1
qto_xyz:1 -0.999872 0.000907 0.015991 132.987595
qto_xyz:2 -0.015548 -0.294768 -0.955442 -77.595352
qto_xyz:3 0.003847 -0.955569 0.294744 163.080612
qto_xyz:4 0.000000 0.000000 0.000000 1.000000
qform_xorient Right-to-Left
qform_yorient Superior-to-Inferior
qform_zorient Anterior-to-Posterior
sform_name Scanner Anat
sform_code 1
sto_xyz:1 -0.999873 0.000833 -0.015935 132.987595
sto_xyz:2 -0.015473 -0.294768 0.955443 -77.595352
sto_xyz:3 0.003902 -0.955568 -0.294744 163.080612
sto_xyz:4 0.000000 0.000000 0.000000 1.000000
sform_xorient Right-to-Left
sform_yorient Superior-to-Inferior
sform_zorient Posterior-to-Anterior
file_type NIFTI-1+
file_code 1
descrip FreeSurfer May 13 2013
aux_file 

Code:

[wmparc2diff.hdr,wmparc2diff.img] = niak_read_vol([subj_path 'wmparc2diff_1mm.nii.gz']);

wmparc2diff.hdr.file_name = [masks_path 'wmparcmask_1mm.nii.gz'];

niak_write_vol(wmparc2diff.hdr,wmparc2diff.img);
Sep 23, 2015  10:09 AM | Pierre Bellec
RE: niak_write_vol orientation issue.
Hi Thomas,

Thanks a lot for the report. Sorry for the late answer, I had to dig through code I did not look at in years. I don't understand why this is happening, the niak reader/writer are not doing anything with the qform, at least when sform is present. The exact same bytes are supposed to be read and then written back again. So there is something I don't get here. Maybe it's actually another field of the nifti header that is causing this difference in the output of fslhd. Would you mind sharing an example file with me pierre.bellec [at] gmail.com?

Best,

Pierre
Sep 27, 2015  06:09 PM | Pierre Bellec
RE: niak_write_vol orientation issue.
Dear Thomas,

Thanks for sending out the volume. This was indeed a bug. In the qform there is a parameter qfact that happens to be stored in pixdim[0] and was not properly handled. http://nifti.nimh.nih.gov/nifti-1/documentation/nifti1fields/nifti1fields_pages/pixdim.html

I have fixed that. If you manually replace the file niak/commands/read_write/niak_write_nifti.m by the following:
https://raw.githubusercontent.com/SIMEXP...

This will fix this bug. I have also identified another problem for volumes which have only a qform (not the case in your example). You will need to replace niak/commands/formats/niak_quat2mat.m by https://raw.githubusercontent.com/SIMEXP/niak/master/commands/formats/niak_quat2mat.m

Alternatively, we will release a new minor version of NIAK (0.13.2) in the next couple of days which will include these fixes. Best,

Pierre