#8988·MONAI

CropForegroundd on ROI with text

Author: pure-rgbCreated Jul 9, 2026Updated Sep 22, 2026

Describe the bug

CropForegroundd works very well for mammography images that contain only the breast and background. However, some mammograms also contain foreground text or markers (e.g., laterality labels, acquisition text, scanner annotations). Since these annotations are non-zero pixels, they are detected as foreground by select_fn, causing the computed bounding box to include them and resulting in a larger crop than desired.

To Reproduce

input:

Image
python
import numpy as np
from monai.transforms import CropForegroundd

transform = CropForegroundd(
    keys=["image"],
    source_key="image",
)

output = transform({"image": input_array})
cropped = output["image"]
cropped = np.transpose(cropped, (1, 2, 0))

Output returns same as input with text label.

Expected behavior

Maybe only return the breast region.