radxtools / collageradiomics

Python Implementation of the CoLlAGe radiomics descriptor. CoLlAGe captures subtle anisotropic differences in disease pathologies by measuring entropy of co-occurrences of voxel-level gradient orientations on imaging computed within a local neighborhood.
BSD 3-Clause "New" or "Revised" License
15 stars 11 forks source link

Error with Nifti Images. #84

Open umgpy opened 4 years ago

umgpy commented 4 years ago

Hi I was trying the collage module on the example jupyter notebook through the docker image. However on trying to pass a numpy array of a nifti image, collage.execute() results in an error. I am adding the error below, please let me know if anything more is required to replicate this error. Thanks

use_3D = True
...
print(image_data.shape)

>(183, 250, 250)

Error while calculating the collage features.

# Run CoLlage Algorithm.Prepare

full_images = collage.execute()

>Image shape = (183, 250, 250)
Mask size = 54x62x61
Image shape (cropped and padded) = (64, 72, 63)
Note: Dividing image values by 255 to convert to 0-1 range
Calculating pixel gradients:
Calculating pixel gradients done.
Calculating dominant gradient angles using SVD for each image patch of size 5x5
Window patch shape for dominant angle calculation = (11, 11, 1)
Calculating dominant gradient angles done.
Dominant angles shape = (54, 62, 63, 2)
Calculating haralick features of angles:
Calculating features for angle 0:
Rescaling dominant angles to 64 unique values.
Rescaling dominant angles done.

---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<ipython-input-157-f386c7d9cfe2> in <module>
      1 # Run CoLlage Algorithm.Prepare
----> 2 full_images = collage.execute()

/usr/local/lib/python3.8/dist-packages/collageradiomics.py in execute(self)
    565         for angle_index in range(angles_shape[3]):
    566             print(f'Calculating features for angle {angle_index}:')
--> 567             haralick_features[:,:,:,:,angle_index] = self.calculate_haralick_textures(dominant_angles[:,:,:,angle_index])
    568             print(f'Calculating features for angle {angle_index} done.')
    569         if self.verbose_logging:

/usr/local/lib/python3.8/dist-packages/collageradiomics.py in calculate_haralick_textures(self, dominant_angles)
    484         for z in range(depth):
    485             for y,x in product(range(height), range(width)):
--> 486                 if self.mask_array[y,x,z]:
    487                     haralick_image[y,x,z,:] = self.calculate_haralick_feature_values(dominant_angles_binned[:,:,z], x, y)
    488 

IndexError: index 61 is out of bounds for axis 2 with size 61
nathanhillyer commented 4 years ago

@umgpy We are working on this. Could you please provide the image and mask being used so we may verify the problem and solution?

umgpy commented 4 years ago

@nathanhillyer I may not be able to provide the image that I was using since it's part of our internal dataset, however I have replicated the error with the publicly available TCIA dataset. Image and mask used are uploaded here.

`# Run CoLlage Algorithm.Prepare

full_images = collage.execute()

Image shape = (240, 240, 155) Mask size = 14x17x24 Image shape (cropped and padded) = (24, 27, 26) Note: Dividing image values by 255 to convert to 0-1 range Calculating pixel gradients: Calculating pixel gradients done. Calculating dominant gradient angles using SVD for each image patch of size 5x5 Window patch shape for dominant angle calculation = (11, 11, 1) Calculating dominant gradient angles done. Dominant angles shape = (14, 17, 26, 2) Calculating haralick features of angles: Calculating features for angle 0: Rescaling dominant angles to 64 unique values. Rescaling dominant angles done.


IndexError Traceback (most recent call last)

in 1 # Run CoLlage Algorithm.Prepare ----> 2 full_images = collage.execute() /usr/local/lib/python3.8/dist-packages/collageradiomics.py in execute(self) 565 for angle_index in range(angles_shape[3]): 566 print(f'Calculating features for angle {angle_index}:') --> 567 haralick_features[:,:,:,:,angle_index] = self.calculate_haralick_textures(dominant_angles[:,:,:,angle_index]) 568 print(f'Calculating features for angle {angle_index} done.') 569 if self.verbose_logging: /usr/local/lib/python3.8/dist-packages/collageradiomics.py in calculate_haralick_textures(self, dominant_angles) 484 for z in range(depth): 485 for y,x in product(range(height), range(width)): --> 486 if self.mask_array[y,x,z]: 487 haralick_image[y,x,z,:] = self.calculate_haralick_feature_values(dominant_angles_binned[:,:,z], x, y) 488 IndexError: index 24 is out of bounds for axis 2 with size 24 `
nathanhillyer commented 4 years ago

@umgpy Thank you, we've corrected this issue on the latest version.

Please run docker pull radxtools/collageradiomics-examples:latest and try it out.

umgpy commented 4 years ago

@nathanhillyer Thank you for the quick fix, I shall give it a try.