Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inquiry Regarding Functionality of CropForeground in MONAI Library #7314

Closed
77QiZhang opened this issue Dec 13, 2023 · 2 comments · Fixed by #7316
Closed

Inquiry Regarding Functionality of CropForeground in MONAI Library #7314

77QiZhang opened this issue Dec 13, 2023 · 2 comments · Fixed by #7316

Comments

@77QiZhang
Copy link

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.

@77QiZhang
Copy link
Author

77QiZhang commented 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()
version

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

plt_show

@KumoLiu
Copy link
Contributor

KumoLiu commented 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!

KumoLiu added a commit that referenced this issue Dec 18, 2023
Fixes #7314 #7315.


### Types of changes
<!--- Put an `x` in all the boxes that apply, and remove the not
applicable items -->
- [x] Non-breaking change (fix or new feature that would not break
existing functionality).
- [ ] Breaking change (fix or new feature that would cause existing
functionality to change).
- [ ] New tests added to cover the changes.
- [ ] Integration tests passed locally by running `./runtests.sh -f -u
--net --coverage`.
- [ ] Quick tests passed locally by running `./runtests.sh --quick
--unittests --disttests`.
- [ ] In-line docstrings updated.
- [ ] Documentation updated, tested `make html` command in the `docs/`
folder.

---------

Signed-off-by: YunLiu <55491388+KumoLiu@users.noreply.github.com>
Co-authored-by: Ben Murray <ben.murray@gmail.com>
marksgraham pushed a commit to marksgraham/MONAI that referenced this issue Jan 30, 2024
Fixes Project-MONAI#7314 Project-MONAI#7315.

### Types of changes
<!--- Put an `x` in all the boxes that apply, and remove the not
applicable items -->
- [x] Non-breaking change (fix or new feature that would not break
existing functionality).
- [ ] Breaking change (fix or new feature that would cause existing
functionality to change).
- [ ] New tests added to cover the changes.
- [ ] Integration tests passed locally by running `./runtests.sh -f -u
--net --coverage`.
- [ ] Quick tests passed locally by running `./runtests.sh --quick
--unittests --disttests`.
- [ ] In-line docstrings updated.
- [ ] Documentation updated, tested `make html` command in the `docs/`
folder.

---------

Signed-off-by: YunLiu <55491388+KumoLiu@users.noreply.github.com>
Co-authored-by: Ben Murray <ben.murray@gmail.com>
Signed-off-by: Mark Graham <markgraham539@gmail.com>
juampatronics pushed a commit to juampatronics/MONAI that referenced this issue Mar 25, 2024
Fixes Project-MONAI#7314 Project-MONAI#7315.

### Types of changes
<!--- Put an `x` in all the boxes that apply, and remove the not
applicable items -->
- [x] Non-breaking change (fix or new feature that would not break
existing functionality).
- [ ] Breaking change (fix or new feature that would cause existing
functionality to change).
- [ ] New tests added to cover the changes.
- [ ] Integration tests passed locally by running `./runtests.sh -f -u
--net --coverage`.
- [ ] Quick tests passed locally by running `./runtests.sh --quick
--unittests --disttests`.
- [ ] In-line docstrings updated.
- [ ] Documentation updated, tested `make html` command in the `docs/`
folder.

---------

Signed-off-by: YunLiu <55491388+KumoLiu@users.noreply.github.com>
Co-authored-by: Ben Murray <ben.murray@gmail.com>
Signed-off-by: Juan Pablo de la Cruz Gutiérrez <juampatronics@gmail.com>
Yu0610 pushed a commit to Yu0610/MONAI that referenced this issue Apr 11, 2024
Fixes Project-MONAI#7314 Project-MONAI#7315.

### Types of changes
<!--- Put an `x` in all the boxes that apply, and remove the not
applicable items -->
- [x] Non-breaking change (fix or new feature that would not break
existing functionality).
- [ ] Breaking change (fix or new feature that would cause existing
functionality to change).
- [ ] New tests added to cover the changes.
- [ ] Integration tests passed locally by running `./runtests.sh -f -u
--net --coverage`.
- [ ] Quick tests passed locally by running `./runtests.sh --quick
--unittests --disttests`.
- [ ] In-line docstrings updated.
- [ ] Documentation updated, tested `make html` command in the `docs/`
folder.

---------

Signed-off-by: YunLiu <55491388+KumoLiu@users.noreply.github.com>
Co-authored-by: Ben Murray <ben.murray@gmail.com>
Signed-off-by: Yu0610 <612410030@alum.ccu.edu.tw>
vgrau98 pushed a commit to vgrau98/MONAI that referenced this issue Apr 28, 2024
Fixes Project-MONAI#7314 Project-MONAI#7315.


### Types of changes
<!--- Put an `x` in all the boxes that apply, and remove the not
applicable items -->
- [x] Non-breaking change (fix or new feature that would not break
existing functionality).
- [ ] Breaking change (fix or new feature that would cause existing
functionality to change).
- [ ] New tests added to cover the changes.
- [ ] Integration tests passed locally by running `./runtests.sh -f -u
--net --coverage`.
- [ ] Quick tests passed locally by running `./runtests.sh --quick
--unittests --disttests`.
- [ ] In-line docstrings updated.
- [ ] Documentation updated, tested `make html` command in the `docs/`
folder.

---------

Signed-off-by: YunLiu <55491388+KumoLiu@users.noreply.github.com>
Co-authored-by: Ben Murray <ben.murray@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants