A high-performance image processing library using Cython and NumPy for efficient operations on RGB images represented as 2D NumPy arrays.
- High-Performance: Cython-accelerated image processing functions
- NumPy Integration: Seamless operations on NumPy arrays
- Multiple Filters: Gaussian blur, sharpening, edge detection, brightness adjustment
- Easy to Use: Simple Python API with type hints
- Extensible: Template for creating your own Cython-based image processing projects
To quickly adapt this project for your own Cython-based image processing needs:
- Rename
cython-image-processingthroughout the project with your actual hyphenated project name - Rename
cython_image_processingthroughout the project with your actual underscored project name - Rename
chiplukeswith your actual GitHub username - Add new image processing functions to
image_filters.pyx - Update the Python interface in
cython_image_processing.py
- Python 3.8+
- NumPy
- Cython
- C compiler (MSVC on Windows, GCC on Linux/macOS)
- numpy: For efficient array operations
- cython: For compiling high-performance C extensions
- setuptools: For building and packaging
git clone git+https://github.com/chiplukes/cython-image-processing
cd cython-image-processing- Install dependencies:
pip install numpy cython- Build and install the package:
pip install -e .This will compile the Cython extensions and install the package in development mode.
To create a virtual environment for your Python project with uv:
- Navigate to your project directory:
cd cython-image-processing- Create the virtual environment:
uv venv- Activate the environment:
# On Windows
.venv\Scripts\activate
# On Unix/macOS
source .venv/bin/activate- Install dependencies and build:
uv pip install numpy cython
uv pip install -e .Run the package with various image processing operations:
# Basic blur operation on 256x256 image
python -m cython_image_processing
# Apply sharpening filter with custom image size
python -m cython_image_processing --width 512 --height 512 --operation sharpen
# Edge detection
python -m cython_image_processing --operation edge_detect
# Brightness adjustment
python -m cython_image_processing --operation brightness
# Enable debug mode for full demo
python -m cython_image_processing --debugimport numpy as np
import cython_image_processing
# Create a sample RGB image
image = cython_image_processing.create_sample_image(width=512, height=512)
print(f"Created image: {image.shape}, dtype: {image.dtype}")
# Apply different filters
blurred = cython_image_processing.process_image(image, "blur")
sharpened = cython_image_processing.process_image(image, "sharpen")
edges = cython_image_processing.process_image(image, "edge_detect")
brighter = cython_image_processing.process_image(image, "brightness")
# Work with your own images
your_image = np.random.randint(0, 256, (480, 640, 3), dtype=np.uint8)
processed = cython_image_processing.process_image(your_image, "blur")The Cython implementation provides significant performance improvements over pure Python:
- Gaussian Blur: ~10-50x faster than naive Python implementation
- Edge Detection: ~15-60x faster than pure Python with NumPy
- Memory Efficient: Operates directly on NumPy arrays without copying
- Add Cython function to
src/cython_image_processing/image_filters.pyx - Update Python interface in
src/cython_image_processing/cython_image_processing.py - Rebuild package:
pip install -e .
The project includes a convenience build script for manual Cython compilation:
python build.pyWhat it does:
- Runs
python setup.py build_ext --inplaceto compile Cython extensions - Builds
.pyxfiles directly in the source directory (in-place build) - Provides user-friendly build status messages
When to use:
- Development: Quick rebuilds after modifying
.pyxfiles - Manual builds: Alternative to
pip install -e .for testing changes - Debugging: Isolate compilation issues from package installation
Note: The standard installation process (pip install -e .) automatically handles Cython compilation and is the recommended approach for most users. The build.py script is primarily a developer convenience tool.
pytest tests/pre-commit install