Registry / data / itk-numerics

itk-numerics

JSON →
library5.4.6pypypiunverified

The `itk-numerics` package provides Python bindings for the Insight Toolkit's (ITK) Numerics module, offering a suite of algorithms for numerical optimization and cost function evaluation, essential for tasks like image registration and parameter fitting. ITK itself is a powerful, open-source, cross-platform toolkit for N-dimensional scientific image analysis. The current stable version of ITK is 5.4.5, with version 6.0 in active beta development, and releases typically follow a maintenance schedule for stable branches and active development for major versions.

pip install itk itk-numerics
INSTALL
IMPORT
SIG · ITK-NUMERICS
I
itk-numerics
datapythonv5.4.6
Install
19.6s avg
Import
615ms
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.615s · 1638.4MB
1638MB installed
● package 1638MB
Code
Verified usage

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

itk
import itk
All ITK functionality, including numerics components from itk-numerics, is typically accessed via the top-level `itk` module after installation.
itk.GradientDescentOptimizer
import itk optimizer = itk.GradientDescentOptimizer.New()
from itk.numerics import GradientDescentOptimizer
Numerics components integrate directly into the `itk` namespace, not a separate `itk.numerics` submodule.
itk.OptimizerParameters
import itk params = itk.OptimizerParameters[itk.D].New()
Parameter containers for optimizers are typically templated with a data type (e.g., `itk.D` for double).

This example demonstrates how to define a custom cost function and use the `GradientDescentOptimizer` to find the minimum of a simple 1D quadratic function. It showcases the typical pattern of instantiating ITK objects with `.New()` and setting parameters.

import itk import numpy as np # Define a simple cost function: f(x) = (x-5)^2 # This minimizes to x=5 class MyCostFunction(itk.SingleValuedCostFunction): def __init__(self): super().__init__() self.SetNumberOfParameters(1) def GetValue(self, parameters): x = parameters.GetElement(0) return (x - 5.0)**2 def GetDerivative(self, parameters, derivative): x = parameters.GetElement(0) derivative.SetElement(0, 2.0 * (x - 5.0)) # Instantiate the cost function and optimizer cost_function = MyCostFunction.New() optimizer = itk.GradientDescentOptimizer.New() # Configure the optimizer optimizer.SetCostFunction(cost_function) optimizer.SetLearningRate(0.1) optimizer.SetNumberOfIterations(100) # Set initial position for optimization initial_position = itk.OptimizerParameters[itk.D].New() initial_position.SetSize(1) initial_position.SetElement(0, 0.0) # Start optimization at x=0 optimizer.SetInitialPosition(initial_position) # Run the optimization print(f"Initial position: {initial_position.GetElement(0):.2f}") optimizer.StartOptimization() final_position = optimizer.GetCurrentPosition() print(f"Optimized position: {final_position.GetElement(0):.2f}")
Debug
Known issues
breakingITK 6.0 (currently in beta) introduces significant C++ modernization (requiring C++17) and changes to the build system (modern CMake module targets). While Python API breaking changes are not explicitly detailed in beta releases, a major version increment typically implies potential API shifts, especially for low-level or C++-wrapped interfaces. Review release notes carefully when upgrading from 5.x to 6.x.
fix
Consult the ITK 6.0 release notes and documentation for specific migration guides. Test your code thoroughly in a development environment before deploying 6.x.
affects: 6.0b01+
gotchaITK objects, including those from `itk-numerics`, are typically instantiated using a factory method `.New()` (e.g., `itk.GradientDescentOptimizer.New()`) instead of direct Python class instantiation (`itk.GradientDescentOptimizer()`). This is a common C++ pattern ported to Python bindings.
fix
Always use `.New()` when creating new ITK objects. Arguments are usually passed via setter methods (e.g., `optimizer.SetLearningRate(0.1)`) after instantiation.
affects: All versions
gotchaFunctionality provided by `itk-numerics` (e.g., optimizers, cost functions) is integrated directly into the main `itk` namespace. There is no separate `itk.numerics` submodule to import from.
fix
Access numerics components directly under `itk`, e.g., `itk.GradientDescentOptimizer`, after ensuring `itk-numerics` is installed alongside `itk`.
affects: All versions
gotchaMany ITK objects, especially images and data containers, are templated on data type and dimension in C++. In Python, this often translates to explicit type and dimension specifications using bracket notation (e.g., `itk.OptimizerParameters[itk.D]` for double parameters, or `itk.Image[itk.F, 3]` for a 3D float image).
fix
Be mindful of required template parameters. Common types include `itk.D` (double), `itk.F` (float), `itk.SS` (short), `itk.UC` (unsigned char). Dimensions are typically integers.
affects: All versions
Upgrade
Version history
5.4.6latest on PyPI · released Apr 23, 2026
Audit
Dependencies
itkrequiredProvides the core Insight Toolkit functionality that itk-numerics extends.
numpyoptionalCommonly used with ITK for array manipulation and data interchange, though not strictly required for all numerics operations.
Agent activity
10 hits · last 30 days
node
10
Resources
itk-numerics — pip install itk-numerics · libregistry