Skip to main content

Blur Generator

PyPI pyversionsPyPI implementation

TestRelease

PyPI statusPyPI license

PyPI version fury.io

PyPI download monthPyPI download weekPyPI download day

forthebadge made-with-python

This tool is for generating blur on images.

There are 3 types of blur modes of motion, lens, or gaussian.

We can use the results on model training or something else.

You can find a simply use case with deep learning in https://github.com/NatLee/simply-blur-detector

Installation

pip install blurgenerator

Check it on Pypi.

Usage

blurgenerator --help
usage: blurgenerator [-h] [--input INPUT] [--input_depth_map INPUT_DEPTH_MAP] [--output OUTPUT] [--type TYPE] [--motion_blur_size MOTION_BLUR_SIZE] [--motion_blur_angle MOTION_BLUR_ANGLE] [--lens_radius LENS_RADIUS] [--lens_components LENS_COMPONENTS]
                     [--lens_exposure_gamma LENS_EXPOSURE_GAMMA] [--gaussian_kernel GAUSSIAN_KERNEL] [--depth_num_layers DEPTH_NUM_LAYERS] [--depth_min_blur DEPTH_MIN_BLUR] [--depth_max_blur DEPTH_MAX_BLUR]
                        Size for motion blur. Default is 100.
  --motion_blur_angle MOTION_BLUR_ANGLE
                        Angle for motion blur. Default is 30.
  --lens_radius LENS_RADIUS
                        Radius for lens blur. Default is 5.0.
  --lens_components LENS_COMPONENTS
                        Components for lens blur. Default is 4.
  --lens_exposure_gamma LENS_EXPOSURE_GAMMA
                        Exposure gamma for lens blur. Default is 2.
  --gaussian_kernel GAUSSIAN_KERNEL
                        Kernel for gaussian. Default is 100.
  --depth_num_layers DEPTH_NUM_LAYERS
                        Layer for depth blur. Default is 3.
  --depth_min_blur DEPTH_MIN_BLUR
                        Min. blur for depth blur. Default is 1.
  --depth_max_blur DEPTH_MAX_BLUR
                        Max. blur for depth blur. Default is 100.

Example and Result

Common use

  • Original image

original image

Usage

  • Motion blur

blurgenerator --type motion --input ./doc/test.png --output ./doc/motion.png

import cv2
from blurgenerator import motion_blur
img = cv2.imread('test.png')
result = motion_blur(img, size=100, angle=30)
cv2.imwrite('./output.png', result)

motion blur image

  • Lens blur

blurgenerator --type lens --input ./doc/test.png --output ./doc/lens.png

import cv2
from blurgenerator import lens_blur
img = cv2.imread('test.png')
result = lens_blur(img, radius=5, components=4, exposure_gamma=2)
cv2.imwrite('./output.png', result)

lens blur image

  • Gaussian blur

blurgenerator --type gaussian --input ./doc/test.png --output ./doc/gaussian.png

import cv2
from blurgenerator import gaussian_blur
img = cv2.imread('test.png')
result = gaussian_blur(img, 100)
cv2.imwrite('./output.png', result)

gaussian blur image

With depth map

Feature from this issue.

  • Original image

photo

  • Depth map

depth map

Usage

  • Motion blur with depth map

blurgenerator --input .\doc\depth-test.jpg --type motion --input_depth_map .\doc\depth-map-test.png --depth_num_layers 5 --depth_min_blur 1 --depth_max_blur 50 --output .\doc\depth-motion-output.png

import cv2
from blurgenerator import motion_blur_with_depth_map
img = cv2.imread('test.jpg')
depth_img = cv2.imread('test-depth.png')
result = motion_blur_with_depth_map(
   img,
   depth_map=depth_img,
   angle=30,
   num_layers=10,
   min_blur=1,
   max_blur=50
)
cv2.imwrite('./output.png', result)

depth motion blur image

  • Lens blur with depth map

blurgenerator --input .\doc\depth-test.jpg --type lens --input_depth_map .\doc\depth-map-test.png --depth_num_layers 3 --depth_min_blur 1 --depth_max_blur 50 --output .\doc\depth-lens-output.png

import cv2
from blurgenerator import lens_blur_with_depth_map
img = cv2.imread('test.jpg')
depth_img = cv2.imread('test-depth.png')
result = lens_blur_with_depth_map(
   img,
   depth_map=depth_img,
   components=5,
   exposure_gamma=5,
   num_layers=10,
   min_blur=1,
   max_blur=50
)
cv2.imwrite('./output.png', result)

depth lens blur image

  • Gaussian blur with depth map

blurgenerator --input .\doc\depth-test.jpg --type gaussian --input_depth_map .\doc\depth-map-test.png --depth_num_layers 3 --depth_min_blur 1 --depth_max_blur 50 --output .\doc\depth-gaussian-output.png

import cv2
from blurgenerator import gaussian_blur_with_depth_map
img = cv2.imread('test.jpg')
depth_img = cv2.imread('test-depth.png')
result = gaussian_blur_with_depth_map(
   img,
   depth_map=depth_img,
   sigma=5,
   num_layers=10,
   min_blur=1,
   max_blur=50
)
cv2.imwrite('./output.png', result)

depth gaussian blur image

Contributor

Nat Lee
Nat Lee

Reference

LICENSE

MIT

Release files for BlurGenerator 1.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for BlurGenerator 1.1.0
File Size Uploaded
blurgenerator-1.1.0.tar.gz 19.1 MB Details

Built distribution (wheel)

Table of built distributions (wheels) for BlurGenerator 1.1.0
File Interpreter ABI Platform
BlurGenerator-1.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 19.1 MB

Release files / blurgenerator-1.1.0.tar.gz

Download URL blurgenerator-1.1.0.tar.gz
Size 19.1 MB
Tags Source
SHA-256 checksum
How to use checksums
12d852de29f0da3623eba96c76ba0b86628396553e4ec494f01c4ffc27982313
BLAKE2b-256 checksum
How to use checksums
6d35231d49ae2620a686e89e0c11c394de62f7216aa6bea5a4216b2d8ad33132
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.12.3

Release files / BlurGenerator-1.1.0-py3-none-any.whl

Download URL BlurGenerator-1.1.0-py3-none-any.whl
Size 11.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ae227832c46fd486c5305aed72affb90c5cc5d1017076291e90fdabaca1fd563
BLAKE2b-256 checksum
How to use checksums
6cf62b9b53e1b771ea210228828cd7e62a9ca08f26aad74b5bb1cfcc8a8c53e8
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.0.0 CPython/3.12.3

Release history Release notifications | RSS feed

This release

1.1.0 This release

2 release files

1.0.4

2 release files

1.0.3

2 release files

1.0.2

2 release files

1.0.1

2 release files

1.0.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page