Repository: Project-MONAI/MONAI

Issue:
generate_spatial_bounding_box looses first dimension 
**Describe the bug**
The monai.transforms.utils generate_spatial_bounding_box returns one dimension less than the image dimensions.
Looks to be in:
https://github.com/Project-MONAI/MONAI/blob/8227caebdad95ffece94ff5ab3daf4f0b00ba6cc/monai/transforms/utils.py#L896

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: 714d00dffe6653e21260160666c4c201ab66511b
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.



Discussion:
I think that's the expected format https://github.com/Project-MONAI/MONAI/blob/8227caebdad95ffece94ff5ab3daf4f0b00ba6cc/monai/transforms/utils.py#L880-L883 so that we can spatially crop the inputs with different number of channels https://github.com/Project-MONAI/MONAI/blob/8227caebdad95ffece94ff5ab3daf4f0b00ba6cc/monai/transforms/croppad/array.py#L351

and the input to this function is a channel-first array/tensor, let me update the docstring...

Resolving patch:
diff --git a/monai/transforms/utils.py b/monai/transforms/utils.py
--- a/monai/transforms/utils.py
+++ b/monai/transforms/utils.py
@@ -874,7 +874,7 @@ def generate_spatial_bounding_box(
     margin: Union[Sequence[int], int] = 0,
 ) -> Tuple[List[int], List[int]]:
     """
-    generate the spatial bounding box of foreground in the image with start-end positions (inclusive).
+    Generate the spatial bounding box of foreground in the image with start-end positions (inclusive).
     Users can define arbitrary function to select expected foreground from the whole image or specified channels.
     And it can also add margin to every dim of the bounding box.
     The output format of the coordinates is:
@@ -886,7 +886,7 @@ def generate_spatial_bounding_box(
     This function returns [-1, -1, ...], [-1, -1, ...] if there's no positive intensity.
 
     Args:
-        img: source image to generate bounding box from.
+        img: a "channel-first" image of shape (C, spatial_dim1[, spatial_dim2, ...]) to generate bounding box from.
         select_fn: function to select expected foreground, default is to select values > 0.
         channel_indices: if defined, select foreground only on the specified channels
             of image. if None, select foreground on the whole image.


Test patch: