Registry / ai-ml / itk
library5.4.6pypypi✓ verified 84d ago

ITK (Insight Toolkit) is an actively developed, open-source C++ library with Python bindings for N-dimensional scientific image analysis, processing, segmentation, and registration. It's widely used in medical imaging and computer vision research. The current stable version is 5.4.5, with frequent maintenance releases and major versions (e.g., 6.0) released periodically after beta testing.

pip install itk
INSTALL
IMPORT
SIG · ITK
I
itk
ai-mlpythonv5.4.6
Install
19.6s avg
Import
616ms
Disk
1638MB
Pass rate
5/ 10
Env Coverage5 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v5.4.6 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.910 runs
build_error
glibc
py 3.103.910 runs
installs and imports cleanly · install 19.6s · import 0.616s · 1638.4MB
1638MB installed
● package 1638MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

itk
import itk
The primary way to import ITK functionality.

This quickstart demonstrates how to read an image, apply a basic image filter (Gamma correction), and save the result. It highlights ITK's strong typing with `itk.Image[pixel_type, dimension]` and the common `itk.imread`/`itk.imwrite` functions. A test image path is used for a runnable example.

import itk import os # Load a test image (ensure itk.test_data is available or provide your own path) # Example: itk.test_data.dir() + '/BrainProtonDensitySlice.png' # Or download one, e.g., from https://itk.org/Doxygen/html/itkTestingData_2itkTestingData_8h-example.html # For demonstration, we'll try to find a suitable test image try: input_image_path = itk.test_data.dir() + '/BrainProtonDensitySlice.png' except AttributeError: print("itk.test_data not found. Please provide a path to a test image.") # Fallback to a placeholder, won't run without a real image input_image_path = "path/to/your/image.png" if not os.path.exists(input_image_path): # Ensure the path actually exists print(f"Warning: Test image not found at {input_image_path}. Please provide a valid image path to run this example.") # Create a dummy image for the rest of the code to parse if test data isn't there # This part won't execute if os.path.exists is true or real path given image = itk.Image[itk.F, 2].New() image.SetRegions(itk.ImageRegion[2]([0,0], [10,10])) image.Allocate() print("Using a dummy image for processing.") else: # Read the image, specifying the pixel type (itk.F for float) image = itk.imread(input_image_path, itk.F) print(f"Read image with dimensions: {image.GetLargestPossibleRegion().GetSize()} and pixel type: {image.GetPixelID()}')") # Define the image type (float, 2D) for the filter pixel_type = itk.F image_type = itk.Image[pixel_type, 2] # Create a Gaussian filter instance gamma_filter = itk.GammaImageAdaptor[image_type, pixel_type].New() # Set the input image gamma_filter.SetInputImage(image) # Apply a gamma correction (e.g., gamma = 0.5) gamma_filter.SetGamma(0.5) # Update the filter to execute gamma_filter.Update() output_image = gamma_filter.GetOutput() # Write the output image output_file_name = "gamma_corrected_output.png" # Ensure a real image was processed before trying to write if os.path.exists(input_image_path): itk.imwrite(output_image, output_file_name) print(f"Processed image and saved to {output_file_name}") else: print("Skipped writing output because a real input image was not processed.")
Debug
Known issues
breakingITK 6.0 introduces major build system changes with modern CMake module targets. While Python users primarily rely on pre-built wheels, this is a breaking change for those building ITK from source or developing custom C++ modules that link ITK.
fix
Review the official ITK 6.0 documentation and migration guides for updated CMake usage and build configurations if you are building ITK or custom C++ modules.
affects: 6.0 and later
breakingITK 5.4 and later versions (including 6.0) require a C++17 compliant compiler. This primarily affects users building ITK from source or developing custom C++ modules.
fix
Ensure your C++ development environment is configured to use C++17 or newer. For Python users, this is typically handled by the pre-built `itk` wheels.
affects: 5.4 and later
gotchaITK utilizes strong typing for image objects (e.g., `itk.Image[itk.F, 3]` for a 3D float image). Incorrect pixel types or dimensions when passing images to filters can lead to `TypeError` or unexpected behavior.
fix
Explicitly specify the `PixelType` and `Dimension` when creating or reading images (`itk.imread(path, itk.F)`) and ensure compatibility with the filters being used. Use `itk.CastImageFilter` when type conversion is necessary.
affects: All versions
gotchaProcessing very large N-dimensional images (high resolution, many slices, multiple channels) with ITK can be memory-intensive, potentially leading to `MemoryError` or system performance issues.
fix
Consider using streaming filters (`itk.StreamingImageFilter`), processing images in chunks, or downsampling images where appropriate. Monitor memory usage and ensure sufficient RAM is available.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'itk'
The `itk` Python package is not installed in your current environment.
fix
Run `pip install itk` to install the library.
RuntimeError: itk::ExceptionObject: ... Could not read image file ... No ImageIO loading filter is able to read the given file
The specified image file path is incorrect, the file does not exist, the file is corrupt, or ITK does not support the image format (or the necessary ImageIO module is not loaded/compiled).
fix
Verify the image file path and filename. Check the file's integrity and format. Ensure ITK has been compiled with support for the specific image format (e.g., DICOM, JPEG2000, TIFF).
TypeError: itk.Image: No constructor matches the arguments given: ...
You are attempting to create an `itk.Image` or use an ITK function with arguments that do not match any of its overloaded C++ constructors or expected Python types.
fix
Review the ITK documentation for the specific class or function you're using. Pay close attention to the required pixel type and dimension arguments (e.g., `itk.Image[itk.F, 2].New()`).
TypeError: in method 'CastImageFilter_New_int_itkImage_int_itkImage', argument 1 of type 'itk::Image<float, 2u> *'
This specific `TypeError` (or similar for other filters) indicates an incompatibility between the input image's pixel type/dimension and what the filter expects. Here, `int_itkImage_int_itkImage` implies an integer image, but a float image was provided.
fix
Ensure the input image's pixel type and dimension exactly match the filter's template parameters. Use `itk.CastImageFilter` to explicitly convert the image to the required type (e.g., `itk.CastImageFilter[InputImageType, OutputImageType].New()`) before applying the filter.
Upgrade
Version history
5.4.6latest on PyPI · released Apr 23, 2026
Audit
Dependencies

No dependency data recorded yet.

Agent activity
8 hits · last 30 days
node
8
Resources
itk — pip install itk · libregistry