Image blurring routines
Project description
pyblur
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 — any odd integer ≥ 3 (e.g. 3, 5, 7, 9, 11, …) |
angle |
float |
Motion direction in degrees; any value accepted, wrapped modulo 180° |
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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pyblur-1.2.0.tar.gz.
File metadata
- Download URL: pyblur-1.2.0.tar.gz
- Upload date:
- Size: 37.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dae7d03bac6f5d6fe55362697bbc9ee1593e58fffa0d0218bea8d7ba806887e7
|
|
| MD5 |
e24c69b489d22f0526059aa78a6dc0ab
|
|
| BLAKE2b-256 |
a327df81d7ae2e68535bdb622e473ab7e240ea4b5893770e0ccd3e8448c0c5c5
|
Provenance
The following attestation bundles were made for pyblur-1.2.0.tar.gz:
Publisher:
ci.yml on lospooky/pyblur
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyblur-1.2.0.tar.gz -
Subject digest:
dae7d03bac6f5d6fe55362697bbc9ee1593e58fffa0d0218bea8d7ba806887e7 - Sigstore transparency entry: 1155120247
- Sigstore integration time:
-
Permalink:
lospooky/pyblur@cefa6c151e1f3d15a13c82826ff952e5d87ef5b7 -
Branch / Tag:
refs/heads/master - Owner: https://github.com/lospooky
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@cefa6c151e1f3d15a13c82826ff952e5d87ef5b7 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file pyblur-1.2.0-py3-none-any.whl.
File metadata
- Download URL: pyblur-1.2.0-py3-none-any.whl
- Upload date:
- Size: 32.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
248eb60a946d59ccae731572ac8bb06fac44e13550182ae9c8f2d52d646b3ee3
|
|
| MD5 |
3df52f4039cb0a5dbd1da8a2c8499e08
|
|
| BLAKE2b-256 |
5f8b3e8444727726e5021ebcd02d71ad0992e763a4a21c8f4a2be5cc6b119e40
|
Provenance
The following attestation bundles were made for pyblur-1.2.0-py3-none-any.whl:
Publisher:
ci.yml on lospooky/pyblur
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pyblur-1.2.0-py3-none-any.whl -
Subject digest:
248eb60a946d59ccae731572ac8bb06fac44e13550182ae9c8f2d52d646b3ee3 - Sigstore transparency entry: 1155120248
- Sigstore integration time:
-
Permalink:
lospooky/pyblur@cefa6c151e1f3d15a13c82826ff952e5d87ef5b7 -
Branch / Tag:
refs/heads/master - Owner: https://github.com/lospooky
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
ci.yml@cefa6c151e1f3d15a13c82826ff952e5d87ef5b7 -
Trigger Event:
workflow_dispatch
-
Statement type: