Skip to main content

Image blurring routines

Project description

pyblur

CI PyPI version Python versions License: MIT

Image blurring library for Python. Provides Gaussian, defocus (disk), box, linear motion, and point-spread-function (PSF) blur kernels, plus a randomized dispatcher that picks one at random.

All functions accept a PIL.Image.Image and return a new PIL.Image.Image of the same size. Every blur type exposes a deterministic variant (explicit parameters) and a random variant (parameters sampled automatically).

PSF kernels are taken from Convolutional Neural Networks for Direct Text Deblurring.


Installation

pip install pyblur

Requirements: Python ≥ 3.10, numpy, pillow, scikit-image, scipy.


Quick start

from PIL import Image
import pyblur

img = Image.open("photo.png")

# Pick a specific blur
blurred = pyblur.gaussian_blur(img, bandwidth=1.5)

# Or let pyblur choose everything at random
blurred = pyblur.randomized_blur(img)

API reference

gaussian_blur(img, bandwidth)

Parameter Type Description
bandwidth float > 0 Standard deviation of the Gaussian kernel
blurred = pyblur.gaussian_blur(img, bandwidth=1.5)
blurred = pyblur.gaussian_blur_random(img)   # bandwidth ∈ {0.5, 1.0, …, 3.5}

defocus_blur(img, dim)

Simulates a circular (disk) aperture blur.

Parameter Type Description
dim int Kernel size — one of 3, 5, 7, 9
blurred = pyblur.defocus_blur(img, dim=5)
blurred = pyblur.defocus_blur_random(img)

box_blur(img, dim)

Uniform box (average) blur.

Parameter Type Description
dim int Kernel size — one of 3, 5, 7, 9
blurred = pyblur.box_blur(img, dim=7)
blurred = pyblur.box_blur_random(img)

linear_motion_blur(img, dim, angle, linetype)

Simulates camera or subject motion along a straight line.

Parameter Type Description
dim int Kernel size — one of 3, 5, 7, 9
angle float Motion direction in degrees; snapped to the nearest valid angle for the kernel size
linetype str "full" — symmetric; "right" / "left" — half-kernel
blurred = pyblur.linear_motion_blur(img, dim=5, angle=45.0, linetype="full")
blurred = pyblur.linear_motion_blur_random(img)

psf_blur(img, psfid)

Applies one of 100 real-world point-spread-function kernels captured from camera hardware.

Parameter Type Description
psfid int Kernel index — 0 to 99
blurred = pyblur.psf_blur(img, psfid=42)
blurred = pyblur.psf_blur_random(img)

randomized_blur(img)

Randomly selects one of the five blur types above and samples its parameters uniformly. Useful for data augmentation pipelines where you want diverse blur without manual configuration.

blurred = pyblur.randomized_blur(img)

Maintenance

This project is maintained on a best-effort, irregular basis. Issues and PRs are welcome but response times are not guaranteed.


Migrating from v0.2

All public functions were renamed to snake_case in v1.0.0 The old PascalCase names (GaussianBlur, BoxBlur, etc.) were removed in v1.0.

v0.2 v1.0+
GaussianBlur(img, bw) gaussian_blur(img, bandwidth=bw)
GaussianBlur_random(img) gaussian_blur_random(img)
DefocusBlur(img, dim) defocus_blur(img, dim)
DefocusBlur_random(img) defocus_blur_random(img)
BoxBlur(img, dim) box_blur(img, dim)
BoxBlur_random(img) box_blur_random(img)
LinearMotionBlur(img, dim, angle, linetype) linear_motion_blur(img, dim, angle, linetype)
LinearMotionBlur_random(img) linear_motion_blur_random(img)
PsfBlur(img, psfid) psf_blur(img, psfid)
PsfBlur_random(img) psf_blur_random(img)
RandomizedBlur(img) randomized_blur(img)

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

pyblur-1.0.0.tar.gz (35.8 kB view details)

Uploaded Source

Built Distribution

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

pyblur-1.0.0-py3-none-any.whl (32.0 kB view details)

Uploaded Python 3

File details

Details for the file pyblur-1.0.0.tar.gz.

File metadata

  • Download URL: pyblur-1.0.0.tar.gz
  • Upload date:
  • Size: 35.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pyblur-1.0.0.tar.gz
Algorithm Hash digest
SHA256 68d1ff03689f35f8a6b3960ac69ae9b4f7398b5908333e4c6a8a1141e2114523
MD5 849447dcff9e0750f4f090fd51e3854b
BLAKE2b-256 38d6ec032aca1f18d0979012f5e5c174ce2bc1b53983c46b8011987f47ec9e04

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyblur-1.0.0.tar.gz:

Publisher: ci.yml on lospooky/pyblur

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pyblur-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: pyblur-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 32.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pyblur-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 13a04e34dbdf2b662f80f47208b2022214b8a9e4b3a8ce099df2a573d33a617a
MD5 7071a2e8ef7e49f2b7ce5e5373ae423a
BLAKE2b-256 4dd633b9032f28ad2d9061d0ba00042de917c7ffe44d4efb80d9294be0bc0cdf

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyblur-1.0.0-py3-none-any.whl:

Publisher: ci.yml on lospooky/pyblur

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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