AIM-Harvard / pyradiomics

Open-source python package for the extraction of Radiomics features from 2D and 3D images and binary masks. Support: https://discourse.slicer.org/c/community/radiomics
http://pyradiomics.readthedocs.io/
BSD 3-Clause "New" or "Revised" License
1.14k stars 492 forks source link

Error in new radiomics version #742

Closed zandarina1 closed 2 years ago

zandarina1 commented 2 years ago

Dear all,

I get this warning if I use a shape of image (208, 156, 1) Size in specified 2D dimension (0) is greater than 1, cannot calculate 2D shape

when it should work but it considers it a 3d image and it does not work. It does not verify that third dimension is 1.

            image = nib.load(image).get_fdata()
            mask = nib.load(mask).get_fdata()
            image = image[...,cardiac_frame[tf]]
            mask = mask[...,cardiac_frame[tf]]
            print(image.shape)
            print(mask.shape)

            dimension = image.shape

            image.shape = (dimension[0], dimension[1])
            mask.shape = (dimension[0], dimension[1])

             result = extractor.execute(image, mask, label=int(lb))

If I reshape then and I do not get the warning but the results are not correct. Any help?

Thank you

JoostJM commented 2 years ago

In PyRadiomics there exist 2 orderings of xyz:

What ordering is your image (if you extract without shape2d, just firstorder or something, what do the diagnostic features say? There should be one called "diagnostics_Image-original_size", which is can be interpreted as x y z.

Force2DDimension assumes ordering z y x (so z = 0, y = 1 and x = 2). Lookup which dimension has size 1, and set that as de 2D dimension. e.g.:

Do you have resampling of pixel spacing enabled? if so, ensure your 2D dimension is 'reshaped' to pixel spacing 0, this retains the original spacing. Otherwise you may end up with multiple slices after resampling due to interpolation.

zandarina1 commented 2 years ago

Dear JoostJM,

Thank you for your answer. So by your answer, I undertand that to calculate radiomics if I do not compute the shape2d, It is not necessary to swap the axis, I can pass the image as it is after loading it using a SimpleITK.

The problem comes with shape2d, that it is necessary to indicate the change of axis with force2Ddimension.

I did that the problem that to make it work in a shape2d with (208, 256, 1) , I need to force the dimension as 2 to be able to remove the warning and to obtain the shape2d. So I do not understand why.

Thank you

JoostJM commented 2 years ago

Can you share the full log output of the extraction that is giving you the error?

For Shape2D in 3D input, PyRadiomics needs to know what you consider as a "slice". You do that by telling PyRadiomics which dimension constitutes your z axis (so the axis not defining your slice). This is input as "force2DDimension". The confusing part is the translation between x y z and the integer value.

I am sorry I currently cannot give you a more precise answer. Fact is that I don't fully understand how you build up your input. I assume your input is SimpleITK.Image objects fed into the feature extractor? Optionally you can also put in truly 2D input (SimpleITK and PyRadiomics support this). This removes the need for you to set the 2D dimension. See SimpleITK documentation on how to select a single slice from a 3D volume.

zandarina1 commented 2 years ago

Thank you very much. I reduced the dimensions as you suggested and that warning disappeared and I obtained the 2d shape features and the numbers I get are similar to the ones with slicer3d with radiomics so It is fine. I imagine now It is allowed to do this as in other versions it expected a 3d image as an input.

            dimension = image.shape
            image.shape = (dimension[0], dimension[1])
            print(image.shape)
            mask.shape = (dimension[0], dimension[1])
            print(mask.shape)

Thanks