SimpleITK

2.5.3 · active · verified Mon Apr 13

SimpleITK is a simplified, open-source interface to the Insight Segmentation and Registration Toolkit (ITK) for image registration and segmentation. It supports multiple programming languages, including Python, and offers a high-level, procedural interface to ITK's extensive algorithms. It aims to make image analysis more accessible for rapid prototyping, education, and various applications, especially in medical imaging. The current version is 2.5.3, with regular releases.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to create a SimpleITK image, set pixel values, apply a Gaussian smoothing filter, read a pixel value, and save the resulting image to disk. For visualization, external tools like ImageJ/Fiji are typically used via `sitk.Show()`.

import SimpleITK as sitk

# Create a 2D image (e.g., 64x64 pixels, 16-bit integer)
image_size = [64, 64]
image = sitk.Image(image_size, sitk.sitkInt16)

# Set some pixel values (e.g., a square in the middle)
# Note: SimpleITK indexing is (x,y,z), while numpy conversion often reverses axes.
image[10:50, 10:50] = 100

# Apply a Gaussian smoothing filter
gaussian_filter = sitk.SmoothingRecursiveGaussianImageFilter()
gaussian_filter.SetSigma(2.0) # Set the standard deviation of the Gaussian
smoothed_image = gaussian_filter.Execute(image)

# Get a pixel value at a specific index
pixel_value = smoothed_image.GetPixel((32, 32))
print(f"Pixel value at (32,32) after smoothing: {pixel_value}")

# Save the image (e.g., to a MetaImage file format)
sitk.WriteImage(smoothed_image, "smoothed_image.mha")
print("Saved smoothed_image.mha")

# To visualize the image, you would typically use an external viewer
# For example, if ImageJ/Fiji is installed and configured:
# sitk.Show(smoothed_image, 'Smoothed Image')

view raw JSON →