pyushkevich / c3d

Convert3D tool
GNU General Public License v3.0
33 stars 16 forks source link

-origin not using NIFTI coordinates #32

Open cookpa opened 1 year ago

cookpa commented 1 year ago
c3d -help origin
-origin                         : Set image origin

Syntax: `-origin vector `

Set the origin of the image. The origin is the world coordinate (in NIfTI coordinate space) of the center of the voxel (0,0,0) in the image. The origin should be specified in millimeters. 

    c3d input.img -origin 100x100x100mm -o output.img

But the code calls SetOrigin

https://github.com/pyushkevich/c3d/blob/master/ConvertImageND.cxx#L1515-L1521

which is not overridden in itkOrientedRASImage.h .

The coordinate of voxel 0,0,0 should be the value of the qoffset field in the NIFTI header. But if I do

% c3d tpl-MNI152NLin2009cAsym_res-01_T1w.nii.gz -info-full | grep qoffset
    qoffset_x = -96
    qoffset_y = -132
    qoffset_z = -78
% c3d tpl-MNI152NLin2009cAsym_res-01_T1w.nii.gz -origin -96x-132x-78mm -o origin_changed.nii.gz

the origin is changed

% c3d tpl-MNI152NLin2009cAsym_res-01_T1w.nii.gz -origin -96x-132x-78mm -info-full  | grep qoffset
    qoffset_x = 96
    qoffset_y = 132
    qoffset_z = -78