-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Wrong type casting in GridPatch produces wrong locations for patches #4596
Description
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
Link to the line that creates the issue
MONAI/monai/transforms/spatial/array.py
Line 2765 in 23d9b52
| 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
MONAI/tests/test_grid_patch.py
Line 76 in 23d9b52
| assert_allclose(output_patch[0], expected_patch, type_test=False) |
