MONAILabel icon indicating copy to clipboard operation
MONAILabel copied to clipboard

Scribbles functionality seems to be broken after MetaTensor update

Open masadcv opened this issue 3 years ago • 2 comments

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:

  1. Follow steps to setup and run radiology app
  2. 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.

masadcv avatar Aug 04 '22 14:08 masadcv

I tested the basic scribbles on 1-2 samples before release.. Is it not working at all?

SachidanandAlle avatar Aug 04 '22 14:08 SachidanandAlle

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.

masadcv avatar Aug 04 '22 17:08 masadcv

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

SachidanandAlle avatar Aug 17 '22 18:08 SachidanandAlle

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.

masadcv avatar Aug 17 '22 19:08 masadcv