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.1-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.1-cp311-cp311-macosx_15_0_arm64.whl (114.7 kB view details)

Uploaded CPython 3.11macOS 15.0+ ARM64

File details

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

File metadata

File hashes

Hashes for gaussianblur-1.1.1-cp311-cp311-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 39b17804cf8a953666e187f44b25e443075327562e445d8b12e2abaec7310d72
MD5 c18bf4dc503f33359efb067d79648dee
BLAKE2b-256 d93d0b999d0afe19eece700a74bb7f84fb52bc5469856d8271cbce45bd9e9b74

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for gaussianblur-1.1.1-cp311-cp311-macosx_15_0_arm64.whl
Algorithm Hash digest
SHA256 c02a976e70e7db4bd89b2288c244b76ca64cae5170cf72734e989eeb99a86451
MD5 086662c31ac52fb6cfe45507cdd67a3a
BLAKE2b-256 3a484c8c1523f1fee74fd1ef96c2204979830e4eff5c5f30c82d2c0d042fff81

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