CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-simpleitk

SimpleITK is a simplified interface to the Insight Toolkit (ITK) for image registration and segmentation

Pending

Quality

Pending

Does it follow best practices?

Impact

Pending

No eval scenarios have been run

Overview
Eval results
Files

mathematical.mddocs/reference/filters/

Mathematical Filters

Pixel-wise mathematical operations including arithmetic, trigonometric, logarithmic, exponential, and comparison operations. All filters operate element-wise on pixel values.

Capabilities

Arithmetic Operations

Basic arithmetic operations on images.

# Addition
def Add(image1, image2):
    """Add two images pixel-wise."""

class AddImageFilter:
    def Execute(self, image1, image2):
        """Returns image1 + image2"""

# Subtraction
def Subtract(image1, image2):
    """Subtract image2 from image1 pixel-wise."""

# Multiplication
def Multiply(image1, image2):
    """Multiply two images pixel-wise."""

# Division
def Divide(image1, image2):
    """Divide image1 by image2 pixel-wise."""

# Modulus
def Modulus(image1, image2):
    """Compute modulus (remainder) pixel-wise."""

# Power
def Pow(image, exponent: float):
    """Raise pixels to power."""

# Square
def Square(image):
    """Square each pixel value."""

# Sqrt
def Sqrt(image):
    """Square root of each pixel."""

# Abs
def Abs(image):
    """Absolute value of each pixel."""

# UnaryMinus
def UnaryMinus(image):
    """Negate each pixel value."""

Exponential and Logarithmic

def Exp(image):
    """Compute e^pixel for each pixel."""

def Log(image):
    """Compute natural logarithm of each pixel."""

def Log10(image):
    """Compute base-10 logarithm of each pixel."""

Trigonometric Functions

def Sin(image):
    """Compute sine of each pixel (radians)."""

def Cos(image):
    """Compute cosine of each pixel (radians)."""

def Tan(image):
    """Compute tangent of each pixel."""

def Asin(image):
    """Compute arcsine of each pixel."""

def Acos(image):
    """Compute arccosine of each pixel."""

def Atan(image):
    """Compute arctangent of each pixel."""

def Atan2(image_y, image_x):
    """
    Compute two-argument arctangent (atan2) pixel-wise.

    Args:
        image_y: Y coordinates
        image_x: X coordinates

    Returns:
        Angle in radians for each pixel pair
    """

Comparison Operations

Generate binary (true/false) images from comparisons.

def Greater(image1, image2):
    """Return image1 > image2 pixel-wise."""

def GreaterEqual(image1, image2):
    """Return image1 >= image2 pixel-wise."""

def Less(image1, image2):
    """Return image1 < image2 pixel-wise."""

def LessEqual(image1, image2):
    """Return image1 <= image2 pixel-wise."""

def Equal(image1, image2):
    """Return image1 == image2 pixel-wise."""

def NotEqual(image1, image2):
    """Return image1 != image2 pixel-wise."""

Logical Operations

Boolean operations on binary images.

def And(image1, image2):
    """Logical AND of two images."""

def Or(image1, image2):
    """Logical OR of two images."""

def Xor(image1, image2):
    """Logical XOR of two images."""

def Not(image):
    """Logical NOT of image."""

def BitwiseNot(image):
    """Bitwise NOT of image."""

Minimum and Maximum

def Maximum(image1, image2):
    """Element-wise maximum of two images."""

def Minimum(image1, image2):
    """Element-wise minimum of two images."""

def Clamp(image, lowerBound: float, upperBound: float):
    """
    Clamp pixel values to range.

    Args:
        image: Input image
        lowerBound: Minimum value
        upperBound: Maximum value

    Returns:
        Image with values in [lowerBound, upperBound]
    """

Usage Examples

Arithmetic Operations

import SimpleITK as sitk

img1 = sitk.ReadImage('image1.png')
img2 = sitk.ReadImage('image2.png')

# Using procedural interface
sum_img = sitk.Add(img1, img2)
diff_img = sitk.Subtract(img1, img2)
product_img = sitk.Multiply(img1, img2)

# Using operators (equivalent)
sum_img = img1 + img2
diff_img = img1 - img2
product_img = img1 * img2

Mathematical Transformations

import SimpleITK as sitk

image = sitk.ReadImage('input.nii')

# Logarithmic transformation for visualization
log_img = sitk.Log(image + 1)  # Add 1 to avoid log(0)

# Exponential transformation
exp_img = sitk.Exp(image * 0.01)

# Power transformation (gamma correction)
gamma_corrected = sitk.Pow(image, 0.5)

Creating Masks with Comparisons

import SimpleITK as sitk

image = sitk.ReadImage('brain.nii')

# Create binary masks using comparisons
mask_high = sitk.Greater(image, 500)
mask_low = sitk.Less(image, 100)

# Combine masks with logical operations
mask_range = sitk.And(
    sitk.Greater(image, 100),
    sitk.Less(image, 500)
)

# Apply mask
masked_image = sitk.Multiply(image, sitk.Cast(mask_range, image.GetPixelID()))

Trigonometric Operations

import SimpleITK as sitk
import math

# Create phase image
phase_img = sitk.ReadImage('phase.nii')

# Compute sine and cosine for phase unwrapping
sin_phase = sitk.Sin(phase_img)
cos_phase = sitk.Cos(phase_img)

# Reconstruct phase from components
unwrapped_phase = sitk.Atan2(sin_phase, cos_phase)

Install with Tessl CLI

npx tessl i tessl/pypi-simpleitk

docs

index.md

tile.json