Spacing Transform only rescales spacing on 2 out of 3 Dimensions #7241
Unanswered
leopold-franz
asked this question in
Q&A
Replies: 1 comment
-
Hi @leopold-franz, seems you missing the channel dim. Could you please try to add |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Describe the bug
When running the Spacingd transform to a 3D image (dicom read using LoadImage & ITKReader), only the first two dimensions are rescaled.
To Reproduce
Steps to reproduce the behavior:
from monai.transforms import LoadImaged, Spacingd
batch = {"image": dicom_path}
batch = LoadImaged(
reader="monai.data.ITKReader",
keys=["image"],
image_only=True,
)(batch)
print("Original image: ")
print(batch["image"].shape)
print(batch["image"].meta["spacing"])
print(batch["image"].meta["original_affine"])
print(batch["image"].meta["affine"])
print(batch["image"].meta["spatial_shape"])
print(h5_resolution)
batch = Spacingd(keys=["image"], pixdim=np.array([0.157288, 0.157288, 0.157288]), scale_extent=True, diagonal=True)(batch)
print("Transformed image: ")
print(batch["image"].shape)
print(batch["image"].meta["spacing"])
print(batch["image"].meta["original_affine"])
print(batch["image"].meta["affine"])
print(batch["image"].meta["spatial_shape"])
Expected behavior
A clear and concise description of what you expected to happen.
I expected the image to be rescaled along all 3 dimensions like when running the rescale function from skimage.transform.
Screenshots

Here you can see how the image dimensions change. Im expecting a shape of (329, 141, 299) (when run with the skimage rescale function).
Environment
================================
Printing MONAI config...
MONAI version: 1.3.0
Numpy version: 1.25.1
Pytorch version: 2.0.1
MONAI flags: HAS_EXT = False, USE_COMPILED = False, USE_META_DICT = False
MONAI rev id: 865972f
MONAI file: /Users//mambaforge/envs/follicle_tracker_311/lib/python3.11/site-packages/monai/init.py
Optional dependencies:
Pytorch Ignite version: NOT INSTALLED or UNKNOWN VERSION.
ITK version: 5.3.0
Nibabel version: NOT INSTALLED or UNKNOWN VERSION.
scikit-image version: 0.21.0
scipy version: 1.11.1
Pillow version: 10.0.0
Tensorboard version: 2.13.0
gdown version: NOT INSTALLED or UNKNOWN VERSION.
TorchVision version: 0.15.2
tqdm version: 4.65.0
lmdb version: NOT INSTALLED or UNKNOWN VERSION.
psutil version: 5.9.5
pandas version: 2.0.3
einops version: 0.6.1
transformers version: NOT INSTALLED or UNKNOWN VERSION.
mlflow version: NOT INSTALLED or UNKNOWN VERSION.
pynrrd version: NOT INSTALLED or UNKNOWN VERSION.
clearml 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: Darwin
Mac version: 14.1
Platform: macOS-14.1-x86_64-i386-64bit
Processor: i386
Machine: x86_64
Python version: 3.11.4
Process name: python3.11
Command: ['python', '-c', 'import monai; monai.config.print_debug_info()']
Open files: []
Num physical CPUs: 4
Num logical CPUs: 8
Num usable CPUs: UNKNOWN for given OS
CPU usage (%): [62.6, 10.3, 53.1, 9.6, 44.0, 10.3, 40.6, 11.0]
CPU freq. (MHz): 2000
Load avg. in last 1, 5, 15 mins (%): [77.6, 48.9, 40.8]
Disk usage (%): 75.9
Avg. sensor temp. (Celsius): UNKNOWN for given OS
Total physical memory (GB): 16.0
Available memory (GB): 5.1
Used memory (GB): 9.7
================================
Printing GPU config...
Num GPUs: 0
Has CUDA: False
cuDNN enabled: False
NVIDIA_TF32_OVERRIDE: None
TORCH_ALLOW_TF32_CUBLAS_OVERRIDE: None
Additional context
Beta Was this translation helpful? Give feedback.
All reactions