ANTsX / ANTsPy

A fast medical imaging analysis library in Python with algorithms for registration, segmentation, and more.
https://antspyx.readthedocs.io
Apache License 2.0
608 stars 161 forks source link

nrrd spatial units not properly handled #514

Closed rueberger closed 5 months ago

rueberger commented 8 months ago

here is an nrrd file with a resolution of isotropic 0.38 microns. its header is

OrderedDict([('type', 'uint16'),
             ('encoding', 'gzip'),
             ('endian', 'big'),
             ('dimension', 3),
             ('sizes', array([1652,  768,  479])),
             ('space dimension', 3),
             ('space directions',
              array([[0.38, 0.  , 0.  ],
                     [0.  , 0.38, 0.  ],
                     [0.  , 0.  , 0.38]])),
             ('space units', ['microns', 'microns', 'microns'])])

the ants "header" for this file upon loading it with ants.image_read is

ANTsImage (RAI)
     Pixel Type : float (float32)
     Components : 1
     Dimensions : (1652, 768, 479)
     Spacing    : (0.38, 0.38, 0.38)
     Origin     : (0.0, 0.0, 0.0)
     Direction  : [1. 0. 0. 0. 1. 0. 0. 0. 1.]
cookpa commented 8 months ago

This is upstream of ANTs:

>>> import SimpleITK as sitk
>>> image = sitk.ReadImage("JRC2018_FEMALE_38um_iso_16bit.nrrd", imageIO="NrrdImageIO")
>>> image.GetSpacing()
(0.38, 0.38, 0.38)

As far as I know, ITK always works in mm units, so if it recognized microns it would represent the image spacing internally as 0.00038 mm. This can cause numerical issues in some filters, I would stay with the "0.38" units while doing image processing in the ANTs / ITK world.