Skip to content
This repository was archived by the owner on Mar 21, 2024. It is now read-only.
This repository was archived by the owner on Mar 21, 2024. It is now read-only.

A script loads 3D images, but 4D are expected for preprocessing #697

@fepegar

Description

@fepegar

I am trying to run inference locally, using the following command:

$ PYTHONPATH=/tmp/Hippocampus_ python \
    ~/git/RadiomicsNN/innereye-deeplearning/score.py \
    --data_folder /tmp/inputs \
    --model_folder /tmp/Hippocampus_ \
    --no-use_gpu

I got the following error:

Traceback (most recent call last):
  File "/home/fernando/git/RadiomicsNN/innereye-deeplearning/score.py", line 311, in <module>
    main()
  File "/home/fernando/git/RadiomicsNN/innereye-deeplearning/score.py", line 307, in main
    score_image(ScorePipelineConfig.parse_args())
  File "/home/fernando/git/RadiomicsNN/innereye-deeplearning/score.py", line 289, in score_image
    segmentation = run_inference(images, inference_pipeline, config)
  File "/home/fernando/git/RadiomicsNN/innereye-deeplearning/score.py", line 132, in run_inference
    photo_norm_images = [photo_norm.transform(image_with_header.image) for image_with_header in images_with_header]
  File "/home/fernando/git/RadiomicsNN/innereye-deeplearning/score.py", line 132, in <listcomp>
    photo_norm_images = [photo_norm.transform(image_with_header.image) for image_with_header in images_with_header]
  File "/home/fernando/git/RadiomicsNN/innereye-deeplearning/InnerEye/ML/photometric_normalization.py", line 99, in transform
    self.output_range, self.sharpen, self.tail, self.debug_mode
  File "/home/fernando/git/RadiomicsNN/innereye-deeplearning/InnerEye/ML/photometric_normalization.py", line 300, in mri_window
    min(max_foreground, level + tail[ichannel] * std_i * sharpen))
IndexError: list index out of range

In photometric_normalization.py:

Hence, this function expects a 4D image with the channels dimension being the first. However, images are loaded in

def read_image_as_array_with_header(file_path: Path) -> Tuple[np.ndarray, ImageHeader]:
"""
Read image with simpleITK as a ndarray.
:param file_path:
:return: Tuple of ndarray with image in Z Y X and Spacing in Z X Y
"""
image: sitk.Image = sitk.ReadImage(str(file_path))
img = sitk.GetArrayFromImage(image) # This call changes the shape to ZYX
spacing = reverse_tuple_float3(image.GetSpacing())
# We keep origin and direction on the original shape since it is not used in this library
# only for saving images correctly
origin = image.GetOrigin()
direction = image.GetDirection()
return img, ImageHeader(origin=origin, direction=direction, spacing=spacing)

which returns a 3D image.

I'm not sure what an appropriate solution would be. Maybe just adding a channels dimension at the beginning of PhotometricNormalization.transform and removing it before returning?

AB#5331

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions