Repository: Project-MONAI/MONAI

Issue:
Spacing transform does not return affines
**Describe the bug**
Calling an instance of `Spacing` transform does not return the original and current affines. This is also seen in the [source code](https://docs.monai.io/en/stable/_modules/monai/transforms/spatial/array.html#Spacing.__call__) linked in the docs. The expected return is a tuple (data_array, original affine, current affine), but only `data_array` is returned.

**To Reproduce**
Call `Spacing` transform on any valid input.

**Expected behavior**
Return a tuple (data_array, original affine, current affine)

**Environment**

Ensuring you use the relevant python executable, please paste the output of:

```
================================
Printing MONAI config...
================================
MONAI version: 0.9.1
Numpy version: 1.22.3
Pytorch version: 1.11.0+cu102
MONAI flags: HAS_EXT = False, USE_COMPILED = False, USE_META_DICT = False
MONAI rev id: 356d2d2f41b473f588899d705bbc682308cee52c
MONAI __file__: package/venv/lib64/python3.8/site-packages/monai/__init__.py

Optional dependencies:
Pytorch Ignite version: NOT INSTALLED or UNKNOWN VERSION.
Nibabel version: 3.2.2
scikit-image version: 0.19.2
Pillow version: 9.1.0
Tensorboard version: 2.9.0
gdown version: NOT INSTALLED or UNKNOWN VERSION.
TorchVision version: NOT INSTALLED or UNKNOWN VERSION.
tqdm version: 4.64.0
lmdb version: NOT INSTALLED or UNKNOWN VERSION.
psutil version: 5.9.0
pandas version: 1.4.2
einops version: NOT INSTALLED or UNKNOWN VERSION.
transformers version: NOT INSTALLED or UNKNOWN VERSION.
mlflow version: NOT INSTALLED or UNKNOWN VERSION.
pynrrd version: NOT INSTALLED or UNKNOWN VERSION.

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: CentOS Linux 7 (Core)
Platform: Linux-3.10.0-1160.66.1.el7.x86_64-x86_64-with-glibc2.2.5
Processor: x86_64
Machine: x86_64
Python version: 3.8.11
Process name: python
Command: ['python', '-c', 'import monai; monai.config.print_debug_info()']
Num physical CPUs: 16
Num logical CPUs: 32
Num usable CPUs: 32
CPU usage (%): [19.8, 17.7, 26.3, 21.3, 17.1, 23.3, 10.9, 25.5, 66.9, 31.1, 39.6, 21.6, 36.7, 28.4, 43.3, 50.4, 2.9, 3.5, 4.5, 3.7, 2.8, 3.6, 3.7, 5.0, 5.7, 10.7, 7.8, 23.4, 7.8, 10.1, 7.4, 3.6]
CPU freq. (MHz): 2
Load avg. in last 1, 5, 15 mins (%): [70.4, 65.9, 49.4]
Disk usage (%): 91.5
Avg. sensor temp. (Celsius): UNKNOWN for given OS
Total physical memory (GB): 187.6
Available memory (GB): 83.4
Used memory (GB): 103.2

================================
Printing GPU config...
================================
Num GPUs: 1
Has CUDA: True
CUDA version: 10.2
cuDNN enabled: True
cuDNN version: 7605
Current device: 0
Library compiled for CUDA architectures: ['sm_37', 'sm_50', 'sm_60', 'sm_70']
GPU 0 Name: Tesla V100-PCIE-32GB
GPU 0 Is integrated: False
GPU 0 Is multi GPU board: False
GPU 0 Multi processor count: 80
GPU 0 Total memory (GB): 31.7
GPU 0 CUDA capability (maj.min): 7.0
```

**Additional context**
Add any other context about the problem here.



Discussion:
Hi @amissert,
As of v0.9.0, we roll out a major refactoring of the data representation using `MetaTensor`, and make many of the image transformations support metadata handling. All meta information will be stored in `MetaTensor`, you can simply use `data.affine` to get your data's affine and `data.meta` to get all meta information. 
More migration reference documents can be found in https://colab.research.google.com/drive/1T4iAys-cC2qL80oJkIbAXAPlWNPwp4H7.
Hope it will help you!
Thanks! May be worthwhile to update the documentation then.
Yes, as of monai v0.9.1, the MetaTensor API is made available and supported across the monai modules and we have create a discussion serves as additional documentation and tracks any frequently asked questions during the migration. 
You can find in https://github.com/Project-MONAI/MONAI/discussions/4764.
Thanks in advance!
Hi @KumoLiu, I think it's more about the wrong documentation in the code, for example this line: https://github.com/Project-MONAI/MONAI/blob/483190953c5ec17832d798a9654cf5fa0b1ab1f7/monai/transforms/spatial/array.py#L511
Oh, I see! I will try to update it.

Resolving patch:
diff --git a/monai/transforms/spatial/array.py b/monai/transforms/spatial/array.py
--- a/monai/transforms/spatial/array.py
+++ b/monai/transforms/spatial/array.py
@@ -389,7 +389,7 @@ def __call__(
             RuntimeError: When ``dst_meta`` is missing.
             ValueError: When the affine matrix of the source image is not invertible.
         Returns:
-            Resampled input image, Metadata
+            Resampled input tensor or MetaTensor.
         """
         if img_dst is None:
             raise RuntimeError("`img_dst` is missing.")
@@ -508,7 +508,7 @@ def __call__(
             ValueError: When ``pixdim`` is nonpositive.
 
         Returns:
-            data_array (resampled into `self.pixdim`), original affine, current affine.
+            data tensor or MetaTensor (resampled into `self.pixdim`).
 
         """
         original_spatial_shape = data_array.shape[1:]


Test patch: