Skip to main content

GPU-accelerated image filtering operations for pixtreme

Project description

pixtreme-filter

GPU-accelerated image filtering operations for pixtreme

Overview

pixtreme-filter provides high-performance image filtering operations running on CUDA-enabled GPUs. All operations are optimized for real-time performance and work directly on GPU memory.

Features

  • Gaussian Blur: GPU-accelerated Gaussian blur with separable kernels
  • Box Blur: Fast averaging filter using separable CUDA kernels
  • Unsharp Mask: Image sharpening by enhancing edges
  • Sobel Edge Detection: Gradient-based edge detection with separable kernels
  • Median Blur: Salt-and-pepper noise removal with edge preservation
  • Bilateral Filter: Edge-preserving smoothing filter
  • Morphology Operations: Erosion, dilation, opening, closing, morphological gradient
  • Zero-Copy Operations: Direct GPU memory processing via CuPy
  • OpenCV Compatibility: API and behavior compatible with OpenCV

Installation

Requirements:

  • Python >= 3.12
  • CUDA Toolkit 12.x
  • NVIDIA GPU with compute capability >= 6.0
pip install pixtreme-filter

Requires pixtreme-core and CUDA Toolkit 12.x.

Quick Start

import pixtreme_filter as pf
import pixtreme_core as px

# Read image (returns float32 in [0, 1] range)
img = px.imread("input.jpg")

# Apply filters
blurred = pf.gaussian_blur(img, ksize=15, sigma=3.0)
sharpened = pf.unsharp_mask(img, sigma=1.5, amount=1.0)
edges = pf.sobel(img, dx=1, dy=0, ksize=3)
denoised = pf.bilateral_filter(img, d=9, sigma_color=0.2, sigma_space=9.0)

# Save result
px.imwrite("output.jpg", denoised)

Important: Float32-Only Architecture

All filters require float32 input images. This is a core design principle of pixtreme.

import cupy as cp
from pixtreme_core.utils.dtypes import to_float32

# If you have uint8 images, convert explicitly:
img_uint8 = cp.random.randint(0, 256, (512, 512, 3), dtype=cp.uint8)
img_float = to_float32(img_uint8)  # Converts to float32 [0, 1]

# Then apply filters
result = pf.bilateral_filter(img_float, d=5, sigma_color=0.2, sigma_space=5.0)

Why float32-only?

  • Consistent precision across all operations
  • GPU optimization (float32 is native for CUDA)
  • Avoids implicit conversions and unexpected behavior
  • Users have explicit control over type conversions

API Reference

Blurring Filters

Gaussian Blur

# Separable Gaussian blur (fast, exact)
blurred = pf.gaussian_blur(image, ksize=15, sigma=3.0)

# Class-based API (for repeated operations)
blur = pf.GaussianBlur()
blurred = blur.get(image, ksize=15, sigma=3.0)

# Get kernel for custom operations
kernel = pf.get_gaussian_kernel(ksize=15, sigma=3.0)

Box Blur

# Fast averaging filter (uniform kernel)
blurred = pf.box_blur(image, ksize=5)
  • Matches cv2.blur() behavior (max error < 1e-5)
  • Uses BORDER_REPLICATE for edge handling
  • Separable implementation (horizontal + vertical passes)

Bilateral Filter

# Edge-preserving smoothing
filtered = pf.bilateral_filter(image, d=9, sigma_color=0.2, sigma_space=9.0)

Parameters:

  • d: Diameter of pixel neighborhood (recommended: 5 for real-time, 9 for quality)
  • sigma_color: Filter sigma in color space (typical: 0.05-0.5 for float32)
  • sigma_space: Filter sigma in coordinate space (typical: 5-50)

Features:

  • Edge-preserving noise reduction
  • Non-separable filter (slower than Gaussian)
  • Channels processed independently (OpenCV-compatible)

Sharpening

Unsharp Mask

# Sharpen image by enhancing edges
sharpened = pf.unsharp_mask(image, sigma=1.5, amount=1.0, threshold=0)

Parameters:

  • sigma: Gaussian blur standard deviation (0.5-10.0)
  • amount: Sharpening strength (0.5-2.5, where 0=no effect)
  • threshold: Minimum change required (not yet implemented, use 0)

Algorithm: sharpened = image + amount * (image - gaussian_blur(image, sigma))

Edge Detection

Sobel

# Detect vertical edges (horizontal gradient)
sobel_x = pf.sobel(image, dx=1, dy=0, ksize=3)

# Detect horizontal edges (vertical gradient)
sobel_y = pf.sobel(image, dx=0, dy=1, ksize=3)

# Compute gradient magnitude
magnitude = cp.sqrt(sobel_x**2 + sobel_y**2)

Parameters:

  • dx: Order of derivative in x-direction (0 or 1)

  • dy: Order of derivative in y-direction (0 or 1)

  • ksize: Kernel size (3, 5, or 7, default 3)

  • Matches cv2.Sobel() behavior (max error < 1e-5)

  • Separable implementation (smoothing + derivative)

Noise Removal

Median Blur

# Remove salt-and-pepper noise while preserving edges
clean = pf.median_blur(noisy_image, ksize=5)

Parameters:

  • ksize: Kernel size (odd number, 3-7 recommended)

Features:

  • Non-linear filter (median of ksize×ksize neighborhood)
  • Edge-preserving (better than Gaussian for impulse noise)
  • Non-separable (slower than box/Gaussian blur)

Morphology Operations

from pixtreme_filter.morphology import (
    erode, dilate, morphology_open, morphology_close, morphology_gradient
)

# Basic operations
eroded = erode(image, ksize=5)
dilated = dilate(image, ksize=5)

# Compound operations
opened = morphology_open(image, ksize=5)   # Erode → Dilate (remove salt noise)
closed = morphology_close(image, ksize=5)  # Dilate → Erode (fill pepper noise)
gradient = morphology_gradient(image, ksize=3)  # Dilate - Erode (edge detection)

# Custom kernels
import cupy as cp
kernel = cp.ones((5, 5), dtype=cp.float32)
eroded = erode(image, ksize=5, kernel=kernel, border_value=0.0)

Features:

  • GPU-accelerated CUDA kernels (8.5x faster than CuPy built-ins)
  • Supports custom kernels
  • Configurable border values (default 0.0)

Performance Notes

  • Fastest: box_blur, gaussian_blur (separable filters)
  • Medium: sobel, unsharp_mask, median_blur (ksize <= 7)
  • Slower: bilateral_filter (non-separable, exponential weighting)
  • GPU Memory: All operations work directly on GPU memory (zero-copy with CuPy)

Typical Performance (1024×1024 image, RTX 3090):

  • Gaussian blur (ksize=15): < 50ms
  • Box blur (ksize=15): < 50ms
  • Unsharp mask: < 100ms
  • Sobel (ksize=3): < 100ms
  • Median blur (ksize=5): < 200ms
  • Bilateral filter (d=5): < 500ms

License

MIT License - see LICENSE file for details.

Links

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pixtreme_filter-0.8.6.tar.gz (60.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pixtreme_filter-0.8.6-py3-none-any.whl (43.4 kB view details)

Uploaded Python 3

File details

Details for the file pixtreme_filter-0.8.6.tar.gz.

File metadata

  • Download URL: pixtreme_filter-0.8.6.tar.gz
  • Upload date:
  • Size: 60.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.8.18

File hashes

Hashes for pixtreme_filter-0.8.6.tar.gz
Algorithm Hash digest
SHA256 5576d5e7ccce29934a932e4fa006f586b73847c2ce5df0532b335b3d46bffcf6
MD5 861e19b56649b44c1618febcce0e9713
BLAKE2b-256 e202d5341a5b74bda37fbd4ab2db7ef7ee686825eaedb717b6d31b15ea3a8324

See more details on using hashes here.

File details

Details for the file pixtreme_filter-0.8.6-py3-none-any.whl.

File metadata

File hashes

Hashes for pixtreme_filter-0.8.6-py3-none-any.whl
Algorithm Hash digest
SHA256 13dddab0276882181d892999d5e7c3d25b5a8b148879f59c84f177311be9e5e8
MD5 b5d10c8df23e0c62224ca2668af78a57
BLAKE2b-256 841fd74725840362a093bbf258124b3c35f135bab039d64d83703f639bac5df7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page