A MONAI transform pipeline for a 3D volume
Normalising the intensity of an MRI volume, cropping it and adding random augmentation.
Goal: Applying an ITK filter to a 3D image through its functional Python API.
import itk, numpy as np
arr = np.zeros((40, 40, 40), dtype=np.float32)
arr[10:30, 10:30, 10:30] = 100.0
image = itk.image_view_from_array(arr)
grad = itk.gradient_magnitude_recursive_gaussian_image_filter(image, sigma=1.0)
g = itk.array_from_image(grad)
print("Output shape:", g.shape)
print(f"Maximum value (at the edges): {g.max():.2f}")
print(f"Value at the centre of the cube: {g[20, 20, 20]:.4f}")
ITK provides thousands of filters and registration algorithms. Here we convert a NumPy array to an ITK image and apply a gradient magnitude filter with Gaussian smoothing, so high values appear only on the edges of the cube.
Output shape: (40, 40, 40) Maximum value (at the edges): 36.57 Value at the centre of the cube: 0.0001
This example was actually run and tested on 21 November 2026 on a CPU — itk 5.4.8, numpy 2.5.5, python 3.13.18
Normalising the intensity of an MRI volume, cropping it and adding random augmentation.
Harmonising voxel size (spacing) between scans from different machines.
Applying realistic distortions and extracting patches for training.
Sections
No section has this name. Press “Search” to search all site content.
Favourites
My results & certificates
My academy progressMy quiz resultsKids’ progressAcademy certificatesQuiz certificatesStart any lesson or quiz and it will show up here so you can get back to it quickly.
Settings
I am the AI Frameworks & Libraries Assistant. Describe your project or ask me about a library, a comparison or a code example, and I will answer from the encyclopedia's database with links and sources.
Answers from the encyclopedia's database only, without a language model and without sending your question to any third party.
The assistant can make mistakes, so check the attached sources.