You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Inquiry Regarding Functionality of CropForeground in MONAI Library #7314
I have been using the CropForeground function to perform background segmentation for extracting foreground information. However, after the cropping operation, I've noticed that the original bounding box coordinates for the background are lost. I am inquiring whether there is a solution within MONAI to perform padding on the cropped background to a specific size while preserving the original background information.
In essence, I aim to pad the cropped background to a predetermined size based on the cropping operation, ensuring retention of the original background information. I would greatly appreciate your guidance or insights regarding any methods or alternative functions within MONAI that could address this requirement.
Thank you for your time and consideration in addressing this query.
Activity
77QiZhang commentedon Dec 13, 2023
the following code snippet related to my issue
import logging
import sys
import torch
import matplotlib.pyplot as plt
import json
from monai.config import print_config
from monai.data import Dataset
from monai.transforms import (
Compose,
LoadImaged,
EnsureChannelFirstd,
EnsureTyped,
CropForegroundd,
SpatialPadd,
)
logging.basicConfig(stream=sys.stdout, level=logging.INFO)

print_config()
train_json_path = 'my_data_path.json'
train_transforms = Compose([
LoadImaged(keys=["image", "label"]),
EnsureChannelFirstd(keys=["image", "label"]),
EnsureTyped(keys=["image"], dtype=torch.float32),
CropForegroundd(keys=["image"], source_key="label", lazy=True),
SpatialPadd(keys=["image"], spatial_size=(128,96,32), mode='median', lazy=True),
])
train_data = json.load(open(train_json_path))
train_ds = Dataset(
data=train_data,
transform=train_transforms,
)
for data in train_ds:
image = data['image']
plt.imshow(image[0,0,:,:], cmap='gray')
plt.show()
break
KumoLiu commentedon Dec 13, 2023
Hi @77QiZhang, thanks for the reporting.
It appears to be a bug in lazy mode, so I've created a PR to address it.
Thanks!
Fix `lazy` ignored in `SpatialPadd` (#7316)
Fix `lazy` ignored in `SpatialPadd` (Project-MONAI#7316)
Fix `lazy` ignored in `SpatialPadd` (Project-MONAI#7316)
Fix `lazy` ignored in `SpatialPadd` (Project-MONAI#7316)
Fix `lazy` ignored in `SpatialPadd` (Project-MONAI#7316)