Skip to main content

A Python package to apply a super fast Gaussian blur through Fast Fourier Transform

Project description

GaussianBlur

Continuous Integration coverage license

GaussianBlur provide a high-performance interface to the underlying LibGaussianBlur C++ library, enabling efficient Gaussian blur image processing through a simple Python API.

Overview

LibGaussianBlur is a C++ library designed to apply Gaussian blur to images using the Fast Fourier Transform (FFT) multi-threaded for tiles. The Python bindings expose this powerful functionality in a user-friendly way, integrating with popular Python imaging libraries such as Pillow and numpy.

Key features include:

  • FFT-based Gaussian Blur: Apply precise Gaussian blur using FFT techniques.
  • Optimized Performance: Leverages parallel tile processing and multi-threading.
  • Cross-Platform Support: Efficiently processes images on multiple operating systems.
  • Flexible API: Easily integrate with existing Python image processing workflows.

Example Requirements

Note: The following packages are only required for running the usage example and are not mandatory dependencies of the module itself.

  • Python >= 3.11
  • Pillow – for image loading and saving
  • numpy – for numerical operations

Installation

Install the module from PyPI:

pip install gaussianblur

Alternatively, you can build it from source if needed. Make sure the underlying C++ library and its dependencies are correctly configured.

Usage Example

Below is a simple example demonstrating how to use the gaussianblur module:

from PIL import Image as PILImage
import numpy as np
import gaussianblur

# This is a simple example of how to use the gaussianblur module in Python.
def main():
    input_file = "input.png"
    output_file = "output.png"
    
    # Load image using Pillow
    pil_img = PILImage.open(input_file)
    
    # Create an instance of the gaussianblur.Image object
    img = gaussianblur.Image()
    img.geom.rows = pil_img.size[1]
    img.geom.cols = pil_img.size[0]
    img.geom.channels = len(pil_img.getbands())
    img.data = np.array(pil_img).flatten().tolist()
    
    # Set the sigma value for the Gaussian blur
    sigma = 7.5
    
    # If True, the alpha channel will be blurred as well (if present)
    apply_to_alpha_channel = True
    
    # Apply Gaussian blur
    gaussianblur.gaussianblur(img, sigma, apply_to_alpha_channel)
    print("Gaussian blur applied.")
    
    # Save the output image
    out_np_img = np.array(img.data, dtype=np.uint8).reshape(img.geom.rows, img.geom.cols, img.geom.channels)
    PILImage.fromarray(out_np_img, pil_img.mode).save(output_file)
    print("Output written to", output_file)

if __name__ == "__main__":
    main()

How It Works

The Python module leverages the robust and efficient algorithms implemented in the underlying C++ library:

  • Centered Kernel Generation: Automatically generates a centered Gaussian kernel to avoid circular convolution artifacts.
  • FFT-based Convolution: Performs FFT on both the kernel and image tiles to achieve efficient, high-performance convolution in each dimension and for each tile.
  • Multi-threading & SIMD Optimizations: Ensures speedy processing without fearing any large images, thanks to FFT and parallel processing.

Additional Information

For more details about the underlying C++ library and its capabilities, please refer to the LibGaussianBlur repository.

Contributing

Contributions are welcome! If you have suggestions or improvements, please open an issue or submit a pull request on GitHub.

License

This project is licensed under the Apache-2.0 License. See the LICENSE file for details.

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

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

gaussianblur-1.1.2-cp311-cp311-manylinux_2_34_x86_64.whl (145.7 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.34+ x86-64

gaussianblur-1.1.2-cp311-cp311-macosx_15_0_arm64.whl (114.8 kB view details)

Uploaded CPython 3.11macOS 15.0+ ARM64

File details

Details for the file gaussianblur-1.1.2-cp311-cp311-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for gaussianblur-1.1.2-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 ce38046e9d0dbe038b9e48fdb81952a3bebdca5d0dae769daa837fce4534a3db
MD5 74e9ba22c0069165449d60f5b013ddc6
BLAKE2b-256 4759e87bca8a64d33b9d5adda19cc6e5bec874a59aa44a3be06a0400dbc83527

See more details on using hashes here.

File details

Details for the file gaussianblur-1.1.2-cp311-cp311-macosx_15_0_arm64.whl.

File metadata

File hashes

Hashes for gaussianblur-1.1.2-cp311-cp311-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 bffebbd70dd5c12cba37e91819b1270752df78b6e678f19fead7d811cd11436c
MD5 f2f96ab081ce7820e16662c6153a3743
BLAKE2b-256 a8f4915cee910715781c6a2c772e6e859df7ce6e24355a603c283a5e7616be8a

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