-
Notifications
You must be signed in to change notification settings - Fork 1.5k
generate_spatial_bounding_box looses first dimension #3723
Description
Describe the bug
The monai.transforms.utils generate_spatial_bounding_box returns one dimension less than the image dimensions.
Looks to be in:
MONAI/monai/transforms/utils.py
Line 896 in 8227cae
| data = select_fn(data).any(0) |
removing .any(0) fixes bug.
To Reproduce
import numpy as np
from monai.transforms.utils import generate_spatial_bounding_box
image = np.ones((10, 20, 30))
print(generate_spatial_bounding_box(image))
Output:
([0, 0], [20, 30])
Expected behavior
Documentation states:
The output format of the coordinates is:
[1st_spatial_dim_start, 2nd_spatial_dim_start, ..., Nth_spatial_dim_start],
[1st_spatial_dim_end, 2nd_spatial_dim_end, ..., Nth_spatial_dim_end]
Expected output:
([0, 0, 0], [10, 20, 30])
Environment
================================
Printing MONAI config...
================================
MONAI version: 0.8.0
Numpy version: 1.22.1
Pytorch version: 1.8.0a0+52ea372
MONAI flags: HAS_EXT = False, USE_COMPILED = False
MONAI rev id: 714d00d
Optional dependencies:
Pytorch Ignite version: 0.4.6
Nibabel version: 3.2.1
scikit-image version: 0.18.3
Pillow version: 9.0.0
Tensorboard version: 2.8.0
gdown version: 4.2.0
TorchVision version: 0.9.0a0
tqdm version: 4.53.0
lmdb version: 1.1.1
psutil version: 5.8.0
pandas version: 1.1.4
einops version: 0.4.0
transformers version: 4.15.0
mlflow version: 1.23.0
For details about installing the optional dependencies, please visit:
https://docs.monai.io/en/latest/installation.html#installing-the-recommended-dependencies
================================
Printing system config...
================================
System: Linux
Linux version: Ubuntu 20.04.1 LTS
Platform: Linux-5.11.0-40-generic-x86_64-with-glibc2.10
Processor: x86_64
Machine: x86_64
Python version: 3.8.5
Process name: python
Command: ['python', '-c', 'import monai; monai.config.print_debug_info()']
Open files: []
Num physical CPUs: 32
Num logical CPUs: 64
Num usable CPUs: 64
CPU usage (%): [8.6, 4.8, 4.8, 4.1, 4.8, 4.8, 5.4, 6.1, 20.5, 4.8, 17.8, 5.4, 5.4, 4.1, 4.8, 4.8, 5.4, 5.4, 4.8, 5.4, 4.8, 5.4, 4.8, 9.5, 5.4, 4.8, 4.8, 23.1, 4.8, 5.5, 6.1, 36.7, 5.4, 4.8, 4.8, 4.1, 5.4, 5.4, 4.1, 4.8, 5.4, 4.8, 5.4, 5.4, 5.4, 4.8, 4.8, 22.4, 4.8, 4.1, 4.8, 4.8, 4.8, 5.4, 4.8, 6.1, 5.4, 5.4, 4.8, 5.4, 5.4, 4.8, 6.1, 68.3]
CPU freq. (MHz): 2524
Load avg. in last 1, 5, 15 mins (%): [1.8, 1.9, 1.9]
Disk usage (%): 60.6
Avg. sensor temp. (Celsius): UNKNOWN for given OS
Total physical memory (GB): 251.6
Available memory (GB): 241.1
Used memory (GB): 8.1
================================
Printing GPU config...
================================
Num GPUs: 2
Has CUDA: True
CUDA version: 11.2
cuDNN enabled: True
cuDNN version: 8100
Current device: 0
Library compiled for CUDA architectures: ['sm_52', 'sm_60', 'sm_61', 'sm_70', 'sm_75', 'sm_80', 'sm_86', 'compute_86']
GPU 0 Name: NVIDIA RTX A6000
GPU 0 Is integrated: False
GPU 0 Is multi GPU board: False
GPU 0 Multi processor count: 84
GPU 0 Total memory (GB): 47.5
GPU 0 CUDA capability (maj.min): 8.6
GPU 1 Name: NVIDIA RTX A6000
GPU 1 Is integrated: False
GPU 1 Is multi GPU board: False
GPU 1 Multi processor count: 84
GPU 1 Total memory (GB): 47.5
GPU 1 CUDA capability (maj.min): 8.6
Additional context
Add any other context about the problem here.