Skip to content

ENH: Fix header printing#1912

Merged
cookpa merged 5 commits intomasterfrom
fix_matrix_header_print
Oct 7, 2025
Merged

ENH: Fix header printing#1912
cookpa merged 5 commits intomasterfrom
fix_matrix_header_print

Conversation

@cookpa
Copy link
Member

@cookpa cookpa commented Oct 2, 2025

Print matrices and vectors, remove redundant info

Fixes #960

@cookpa
Copy link
Member Author

cookpa commented Oct 2, 2025

I took the orientation code logic from c3d, making clear that the codes (LPI, etc) are FROM orientations, rather than "to" orientations. Nibabel uses the signifier +, RAS+ means increasing towards Right, Anterior, Superior.

In ITK 6.0, the spatial orientation enums are replaced by a new class itkAnatomicalOrientation, which uses unambiguous terms like "RightToLeft" but can also provide the traditional three letter codes.

@gdevenyi
Copy link
Contributor

gdevenyi commented Oct 2, 2025

Can you post a diff of the output of PrintHeader before and after for a file here?

@cookpa
Copy link
Member Author

cookpa commented Oct 2, 2025

Old is on the left

Spacing [1, 1, 1]					      <	
Origin [96, 132, -78]					      <	
Direction 						      <	
-1 0 0							      <	
0 -1 0							      <	
0 0 1							      <	
   							
Size : 193 229  193					      <	
   						      <	
 Image Dimensions   : [193, 229, 193]				  Image Dimensions   : [193, 229, 193]
 Bounding Box       : {[96 132 -78], [289 361 115]}		  Bounding Box       : {[96 132 -78], [289 361 115]}
   						      >	  Origin             : [96, 132, -78]
 Voxel Spacing      : [1, 1, 1]				  Voxel Spacing      : [1, 1, 1]
 Intensity Range    : [0, 10000]				  Intensity Range    : [0, 10000]
 Mean Intensity     : 2986.67					  Mean Intensity     : 2986.67
   						      >	  Canon. FROM Orient : LPI
 Direction Cos Mtx. : 						  Direction Cos Mtx. : 
-1 0 0							      |	           -1.00000    0.00000    0.00000
0 -1 0							      |	            0.00000   -1.00000    0.00000
0 0 1							      |	            0.00000    0.00000    1.00000
   						      <	
 Voxel->RAS x-form  : 						  Voxel->RAS x-form  : 
   						      >	            1.00000   -0.00000   -0.00000  -96.00000
   						      >	           -0.00000    1.00000   -0.00000 -132.00000
   						      >	            0.00000    0.00000    1.00000  -78.00000
   						      >	            0.00000    0.00000    0.00000    1.00000
 Image Metadata: 						  Image Metadata: 
   ITK_FileNotes = mnc2nii mni_icbm152_nlin_asym_09c/mni_icb	    ITK_FileNotes = mnc2nii mni_icbm152_nlin_asym_09c/mni_icb
   ITK_original_direction of unsupported type N3itk6MatrixId |	    ITK_original_direction =
   ITK_original_spacing of unsupported type NSt3__16vectorId |	           -1.00000   -0.00000   -0.00000
   						      >	           -0.00000   -1.00000   -0.00000
   						      >	            0.00000    0.00000    1.00000
   						      >	    ITK_original_spacing = [1.00000, 1.00000, 1.00000]
   ITK_sform_corrected = NO					    ITK_sform_corrected = NO
   bitpix = 16							    bitpix = 16
   cal_max = 10000						    cal_max = 10000
   cal_min = 0							    cal_min = 0
   datatype = 4						    datatype = 4
   descrip = mnc2nii mni_icbm152_nlin_asym_09c/mni_icbm152_t	    descrip = mnc2nii mni_icbm152_nlin_asym_09c/mni_icbm152_t
   dim[0] = 3							    dim[0] = 3
   dim[1] = 193						    dim[1] = 193
   dim[2] = 229						    dim[2] = 229
   dim[3] = 193						    dim[3] = 193
   dim[4] = 1							    dim[4] = 1
   dim[5] = 1							    dim[5] = 1
   dim[6] = 0							    dim[6] = 0
   dim[7] = 0							    dim[7] = 0
   dim_info = 0						    dim_info = 0
   intent_code = 0						    intent_code = 0
   intent_p1 = 0						    intent_p1 = 0
   intent_p2 = 0						    intent_p2 = 0
   intent_p3 = 0						    intent_p3 = 0
   nifti_type = 1						    nifti_type = 1
   pixdim[0] = 0						    pixdim[0] = 0
   pixdim[1] = 1						    pixdim[1] = 1
   pixdim[2] = 1						    pixdim[2] = 1
   pixdim[3] = 1						    pixdim[3] = 1
   pixdim[4] = 0						    pixdim[4] = 0
   pixdim[5] = 1						    pixdim[5] = 1
   pixdim[6] = 0						    pixdim[6] = 0
   pixdim[7] = 0						    pixdim[7] = 0
   qfac = 1						      |	    qfac = 1.00000
   qform_code = 4						    qform_code = 4
   qform_code_name = NIFTI_XFORM_MNI_152			    qform_code_name = NIFTI_XFORM_MNI_152
   qoffset_x = -96						    qoffset_x = -96
   qoffset_y = -132						    qoffset_y = -132
   qoffset_z = -78						    qoffset_z = -78
   qto_xyz of unsupported type N3itk6MatrixIfLj4ELj4EEE      |	    qto_xyz =
   						      >	            1.00000    0.00000    0.00000  -96.00000
   						      >	            0.00000    1.00000    0.00000 -132.00000
   						      >	            0.00000    0.00000    1.00000  -78.00000
   						      >	            0.00000    0.00000    0.00000    1.00000
   quatern_b = 0						    quatern_b = 0
   quatern_c = 0						    quatern_c = 0
   quatern_d = 0						    quatern_d = 0
   scl_inter = 0						    scl_inter = 0
   scl_slope = 1						    scl_slope = 1
   sform_code = 4						    sform_code = 4
   sform_code_name = NIFTI_XFORM_MNI_152			    sform_code_name = NIFTI_XFORM_MNI_152
   slice_code = 0						    slice_code = 0
   slice_duration = 0						    slice_duration = 0
   slice_end = 0						    slice_end = 0
   slice_start = 0						    slice_start = 0
   srow_x = 1 0 0 -96						    srow_x = 1 0 0 -96
   srow_y = 0 1 0 -132						    srow_y = 0 1 0 -132
   srow_z = 0 0 1 -78						    srow_z = 0 0 1 -78
   toffset = 0							    toffset = 0
   vox_offset = 352						    vox_offset = 352
   xyzt_units = 10						    xyzt_units = 10

@cookpa
Copy link
Member Author

cookpa commented Oct 2, 2025

IDK why qfac is a float now, will fix

@cookpa
Copy link
Member Author

cookpa commented Oct 2, 2025

Actually, it would need to be fixed upstream. The ITK metadata stores qfac as a float, and the rest of the pixdims as strings.

@cookpa
Copy link
Member Author

cookpa commented Oct 2, 2025

Clarifying that the "Voxel->RAS" transform is Voxel->RAS+.

@cookpa
Copy link
Member Author

cookpa commented Oct 6, 2025

I'm thinking about removing the "Voxel->RAS+ x-form" output because I think it might become confusing, we use ITK LPS+ coordinates throughout ANTsX.

@cookpa cookpa merged commit 164c8f1 into master Oct 7, 2025
1 check passed
@cookpa cookpa deleted the fix_matrix_header_print branch October 7, 2025 19:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Error messages about invalid direction in PrintHeader

2 participants