Scribbles functionality seems to be broken after MetaTensor update
Describe the bug Running scribbles (Histogram+GraphCut), get the following error:
File "/data/MONAILabel-Dev/monailabel/scribbles/utils.py", line 121, in make_histograms
values = image[scrib == scribbles_bg_label]
IndexError: boolean index did not match indexed array along dimension 1; dimension is 185 but corresponding boolean dimension is 205
To Reproduce Steps to reproduce the behavior:
- Follow steps to setup and run radiology app
- Add scribbles and update
Expected behavior It should work without a problem.
Additional context
The scribbles methods expect image and label (providing scribbles).
When I look through the data transforms for scribbles, some transforms are throwing away MetaTensor information.
For example, AddBackgroundScribblesFromROId which adds scribbles from ROI (at: https://github.com/Project-MONAI/MONAILabel/blob/main/monailabel/scribbles/infer.py#L67). Below are affine matrix before and after this transform is applied for the image and label MetaTensor
Before:
d["image"].affine
tensor([[ 0.9023, 0.0000, 0.0000, -461.0978],
[ 0.0000, 0.9023, 0.0000, -461.0978],
[ 0.0000, 0.0000, 5.0000, 0.0000],
[ 0.0000, 0.0000, 0.0000, 1.0000]], dtype=torch.float64)
d["label"].affine
tensor([[ 0.9023, 0.0000, -0.0000, -461.0978],
[ 0.0000, 0.9023, -0.0000, -461.0978],
[ 0.0000, 0.0000, 5.0000, 0.0000],
[ 0.0000, 0.0000, 0.0000, 1.0000]], dtype=torch.float64)
After:
d["image"].affine
tensor([[ 2.5000, 0.0000, 0.0000, -461.0978],
[ 0.0000, 2.5000, 0.0000, -461.0978],
[ 0.0000, 0.0000, 5.0000, 0.0000],
[ 0.0000, 0.0000, 0.0000, 1.0000]], dtype=torch.float64)
d["label"].affine
tensor([[2.5000, 0.0000, 0.0000, 0.0000],
[0.0000, 2.5000, 0.0000, 0.0000],
[0.0000, 0.0000, 5.0000, 0.0000],
[0.0000, 0.0000, 0.0000, 1.0000]], dtype=torch.float64)
This becomes a problem when Spacingd tranform is applied next - leading to mismatched shapes for image and label.
I tested the basic scribbles on 1-2 samples before release.. Is it not working at all?
Not working on my side (I test on spleen data using Histogram+GraphCut), perhaps it hits a specific corner case... I will look into this and have a fix soon.
Are we good now.. I guess you have fixed for both 3D Slicer and OHIF usecases.. if all good then we can close this issue
Yes, all good. I might need to revisit OHIF in a few days to improve the scribbles implementation.
I am closing this now as this is fixed.