Img2Num Python Bindings
The Img2Num Python Bindings provide a Python interface to the core Img2Num image processing library via pybind11. These bindings wrap the underlying C++ functions, exposing high-performance image processing operations to Python projects.
Overview
The bindings wrap the underlying C++ functions (from core/) using pybind11 and operate on numpy.ndarray buffers. They provide access to key image processing operations such as filtering, clustering, and SVG conversion.
Key Functions
gaussian_blur_fft— Apply FFT-based Gaussian blurinvert_image— Invert pixel values in an imagethreshold_image— Apply thresholding to an imageblack_threshold_image— Apply black-thresholdingkmeans— Perform k-means clustering on image pixelsbilateral_filter— Apply bilateral filteringlabels_to_svg— Convert labeled image to SVGimage_to_svg— Convert image to SVG with configurable parameters
Each function is fully documented with Doxygen and mirrors the corresponding C++ function in core/img2num.h.
Building the Python Bindings
cmake -B build .
cmake --build build
cmake --install build
cmake --install buildmight need elevated permissions, but that shouldn't be a problem in the Docker container.
- The compiled
_img2nummodule is installed underimg2num/. - Ensure that the core
Img2Numlibrary is built and accessible.
Usage Example
:::important Proper Examples
See the example-apps/ folder for the most up-to-date usage examples.
:::
import numpy as np
from img2num import (
gaussian_blur_fft,
invert_image,
threshold_image,
image_to_svg,
)
# Load image as uint8 numpy array (H, W, C)
image = np.zeros((256, 256, 3), dtype=np.uint8)
# Apply Gaussian blur
blurred = gaussian_blur_fft(image, sigma=1.5)
# Invert colors
inverted = invert_image(blurred)
# Threshold
thresholded = threshold_image(inverted, num_thresholds=4)
# SVG conversion
svg_str = image_to_svg(thresholded)
Documentation
The Doxygen documentation provides detailed descriptions of all functions, their parameters, and usage examples. Refer to the generated docs for guidance on integrating the bindings into internal projects.