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. Both grayscale (L) and RGB images are supported. 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")   # L or RGB

# 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)

Supports any PIL image mode (delegates to PIL internally).

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. Supports L and RGB images.

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. Supports L and RGB images.

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. Supports L and RGB images.

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. Supports L and RGB images.

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.1.0.tar.gz (37.0 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.1.0-py3-none-any.whl (32.8 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for pyblur-1.1.0.tar.gz
Algorithm Hash digest
SHA256 98cc2aa8c522492598ce242f04daf2eed211d320e55123925cf382a76870d766
MD5 5913fee80cb0cf6c6b46b57197c607f8
BLAKE2b-256 fa3e0dcb16cb76ced99de0314cbfcf00f61c610a4bc1d3b83ee20a8e2f6b59a7

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyblur-1.1.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.1.0-py3-none-any.whl.

File metadata

  • Download URL: pyblur-1.1.0-py3-none-any.whl
  • Upload date:
  • Size: 32.8 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.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5f5a5da139bd2b1ea72296c62bc38bc869f85fdfd2b5afa8f3e71e7d77cc1422
MD5 9cf0e631665598d78b6a38037592ed8b
BLAKE2b-256 da98aacb484ff67e2c9c57d16092c6af05a16724b4a7877580ef23acda22126c

See more details on using hashes here.

Provenance

The following attestation bundles were made for pyblur-1.1.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