OpenGATE / GateTools

Python tools and functions for Gate
GNU Lesser General Public License v3.0
30 stars 22 forks source link

Convert Dicom with negative spacing or non-identity directions #13

Closed tbaudier closed 4 years ago

tbaudier commented 4 years ago

It's not a bug, but it could be a feature:

We have a lot of dicom images with negative spacing when we convert them to ITK mhd format (always a mystery for me) And it could lead to a lot of bug in another tools (crop, stitch, ...). So I suggest to add an option in gt_image_convert to be able to remove this negative spacing using gt_affine_transform automatically with:

 gt_affine_transform -i input.mhd -o output.mhd -fr

And by extension to remove the non-identity directions too. We can call this option:

@click.option('-r', '--resample', flag=True, help='Remove negative spacing and non-identity direction')

Moreover, with python ITK v5.1rc2, it is not correctly handled because with an image with a spacing in the .mhd: 4 4 -4. When I open it with python ITK

image = itk.imread("image.mhd")
print(image.GetSpacing())
print(itk.array_from_matrix(itk.GetDirection())

the output is:

4 4 4

1 0 0
0 1 0
0 0 -1

It is a feature of ITK: https://github.com/InsightSoftwareConsortium/ITK/commit/7501479a970694b0dd4a8c4bbf7cbcc033fe059c https://github.com/InsightSoftwareConsortium/ITK/commit/7501479a970694b0dd4a8c4bbf7cbcc033fe059c

What do you think?

tbaudier commented 4 years ago

Done with https://github.com/OpenGATE/GateTools/pull/19