Skip to content

Wrong type casting in GridPatch produces wrong locations for patches #4596

@vale-salvatelli

Description

@vale-salvatelli

Description
In the class GridPatch (monai/transforms/spatial/array.py) the type of the locations is inferred looking at the type of image array. This is erroneous because the type of the image array is related to the range of intensity value in the image, while the location type is related to the size of the image. For example, the image might contain values in the range 0-255 and be casted to uint8, while the image size might span range 0 -1000 (or more for pathology images). This forced conversion leads to completely erroneous returned locations in output.

Below a screenshot of where the problem is. The issue can be reproduced by:

  • loading images in uint8
  • applying GridPatch transform to the image
  • looking at the returned type (and values) of the locations

MicrosoftTeams-image

Link to the line that creates the issue

zip(convert_to_dst_type(src=patched_image, dst=array)[0], convert_to_dst_type(src=locations, dst=array)[0])

To be noted also that the test of this class run an assertion only on the returned patch, not the location

assert_allclose(output_patch[0], expected_patch, type_test=False)

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