Giter Club home page Giter Club logo

blur-image's Introduction

Blur-Image

Overview

Blur-Image is a compact image processing toolkit developed in Python, designed to improve image sharpness through advanced blurring techniques. Based on the Richardson-Lucy deconvolution algorithm, this toolkit allows users to apply different blur kernels and iterative enhancements to improve image quality.

Features

  • Blurring and sharpening: Implement Richardson-Lucy deconvolution for image blurring, as well as standard blurring techniques using different kernels.
  • Batch image processing: Process entire directories of images for bulk blurring and sharpening.
  • Quality measurements: Calculate and report the Peak Signal-to-Noise Ratio (PSNR) to measure the quality of processed images.
  • Visual logging: Color-coded console for easy monitoring of processing steps.

Installation

Clone the repository to your local machine:

git clone https://github.com/mathusanm6/Blur-Image.git
cd Blur-Image

Prerequisites

Ensure you have Python installed along with the following packages:

  • numpy
  • scipy
  • pillow (PIL)

You can install the required packages via pip:

pip install numpy scipy pillow

Usage

After tuning the parameters in the core.py and blind_core.py files, you can run the toolkit using the following command:

python ./run.sh

Richardson-Lucy Deconvolution

Below are some examples of images processed by the Blur-Image toolkit, showing the original images, the blurred versions, and the deblurred outputs after applying various kernels and iteration counts.

Process

Blurring are done using the following kernels:

  • Average 3x3
  • Average 5x5
  • Average 11x11
  • Gaussian 3x3, sigma: 1.0
  • Gaussian 3x3, sigma: 2.0
  • Gaussian 5x5, sigma: 1.0
  • Gaussian 5x5, sigma: 2.0

Sharpening are done knowing the kernel used for blurring and the number of iterations using the Richardson-Lucy deconvolution algorithm as follows:

Algorithm: Richardson-Lucy Deconvolution

Input:
    blurry_image: the blurred image to be deconvolved, which can be a single channel from a color image or a
    grayscale image.
    psf: the point spread function assumed to have caused the blur.
    iterations: the number of iterations for the algorithm.

Output:
    deblurred_image: the image after deconvolution.

Procedure:
1. Initialize:
    estimate = copy of blurry_image // Starting point for the estimation of the deblurred image.

2. Iterate from 1 to iterations:
    a. Convolve the estimate with the PSF
       convolved_estimate = convolve2d(estimate, psf)

    b. Compute the ratio of the blurry_image to the convolved_estimate
       ratio = blurry_image / (convolved_estimate + small_value) // small_value prevents division by zero.

    c. Convolve this ratio with the mirrored PSF (flip the PSF vertically and horizontally)
       error_estimate = convolve2d(ratio, flip(psf, vertically and horizontally))

    d. Update the estimate by multiplying it with the error_estimate
       estimate = estimate * error_estimate

3. Return the final estimate after all iterations as the deblurred_image.

Original Image

grayscale flower

(1) Grayscale Flower

tiger

(2) Tiger

Processed Images

(1) Grayscale Flower

Average 3x3

Average 5x5

Average 11x11

Gaussian 3x3, sigma: 1.0

Gaussian 3x3, sigma: 2.0

Gaussian 5x5, sigma: 1.0

Gaussian 5x5, sigma: 2.0

Blurred Images
blurred flower
blurred flower
blurred flower
blurred flower
blurred flower
blurred flower
blurred flower
Unblurred Images
unblurred flower

5 Iterations

unblurred flower

5 Iterations

unblurred flower

5 Iterations

unblurred flower

5 Iterations

unblurred flower

5 Iterations

unblurred flower

5 Iterations

unblurred flower

5 Iterations

unblurred flower

10 Iterations

unblurred flower

10 Iterations

unblurred flower

10 Iterations

unblurred flower

10 Iterations

unblurred flower

10 Iterations

unblurred flower

10 Iterations

unblurred flower

10 Iterations

unblurred flower

15 Iterations

unblurred flower

15 Iterations

unblurred flower

15 Iterations

unblurred flower

15 Iterations

unblurred flower

15 Iterations

unblurred flower

15 Iterations

unblurred flower

15 Iterations

(2) Tiger

Average 3x3

Average 5x5

Average 11x11

Gaussian 3x3, sigma: 1.0

Gaussian 3x3, sigma: 2.0

Gaussian 5x5, sigma: 1.0

Gaussian 5x5, sigma: 2.0

Blurred Images
blurred tiger
blurred tiger
blurred tiger
blurred tiger
blurred tiger
blurred tiger
blurred tiger
Unblurred Images
unblurred tiger

5 Iterations

unblurred tiger

5 Iterations

unblurred tiger

5 Iterations

unblurred tiger

5 Iterations

unblurred tiger

5 Iterations

unblurred tiger

5 Iterations

unblurred tiger

5 Iterations

unblurred tiger

10 Iterations

unblurred tiger

10 Iterations

unblurred tiger

10 Iterations

unblurred tiger

10 Iterations

unblurred tiger

10 Iterations

unblurred tiger

10 Iterations

unblurred tiger

10 Iterations

unblurred tiger

15 Iterations

unblurred tiger

15 Iterations

unblurred tiger

15 Iterations

unblurred tiger

15 Iterations

unblurred tiger

15 Iterations

unblurred tiger

15 Iterations

unblurred tiger

15 Iterations

Blind Richardson-Lucy Deconvolution

Process

Sharpening are done not knowing the kernel used for blurring and the number of iterations using the Blind Richardson-Lucy deconvolution algorithm as follows:

Algorithm: Blind Richardson-Lucy Deconvolution

Input:
    blurry_image: the blurred image to be deconvolved.
    initial_psf: initial guess for the point spread function (PSF).
    iterations: number of iterations for the deconvolution process.
    psf_iterations: number of iterations for refining the PSF.

Output:
    deblurred_image: the image after deconvolution.

Procedure:
1. Initialize:
    estimate = copy of blurry_image // Starting estimate for the deblurred image.
    psf = initial_psf // Starting estimate for the PSF.

2. For each deconvolution iteration:
    a. Convolve the estimate with the current psf
       convolved_estimate = convolve2d(estimate, psf)

    b. Compute the ratio of the blurry_image to the convolved_estimate
       ratio = blurry_image / (convolved_estimate + small_value) // small_value prevents 
       division by zero.

    c. Convolve the ratio with the mirrored PSF
       error_estimate = convolve2d(ratio, flip(psf, vertically and horizontally))

    d. Update the estimate by multiplying it with the error_estimate
       estimate = estimate * error_estimate

    e. Update the PSF for a number of p-iterations:
       i. For each PSF iteration:
           A. Convolve the estimate with the current psf
              estimated_convolution = convolve2d(estimate, psf)

           B. Compute the ratio of the original blurry_image to the estimated_convolution
              error_ratio = blurry_image / (estimated_convolution + small_value)

           C. Convolve the error_ratio with the flipped estimate
              full_psf_update = convolve2d(error_ratio, flip(estimate, 
              vertically and horizontally))

           D. Crop the full_psf_update to match the PSF size and update the PSF
              psf_update = crop_center(full_psf_update, size of psf)
              psf = psf * psf_update
              psf = normalize(psf) // Ensures energy of the PSF is preserved.

3. Return the final estimate after all iterations as the deblurred_image.

Original Image

blurred tiger

(A) Blurred tiger (Unknown Kernel)

Processed Images

(A) Blurred Tiger (Unknown Kernel)

Average 3x3

Average 5x5

Gaussian 5x5, sigma: 1.0

Gaussian 5x5, sigma: 2.0

unblurred tiger

15 Iterations, 3 PSF Iterations

unblurred tiger

15 Iterations, 3 PSF Iterations

unblurred tiger

15 Iterations, 3 PSF Iterations

unblurred tiger

15 Iterations, 3 PSF Iterations

unblurred tiger

30 Iterations, 3 PSF Iterations

unblurred tiger

30 Iterations, 3 PSF Iterations

unblurred tiger

30 Iterations, 3 PSF Iterations

unblurred tiger

30 Iterations, 3 PSF Iterations

unblurred tiger

60 Iterations, 3 PSF Iterations

unblurred tiger

60 Iterations, 3 PSF Iterations

unblurred tiger

60 Iterations, 3 PSF Iterations

unblurred tiger

60 Iterations, 3 PSF Iterations

unblurred tiger

120 Iterations, 3 PSF Iterations

unblurred tiger

120 Iterations, 3 PSF Iterations

unblurred tiger

120 Iterations, 3 PSF Iterations

unblurred tiger

120 Iterations, 3 PSF Iterations

License

This project is licensed under the MIT License. See the LICENSE.md file for details.

blur-image's People

Contributors

mathusanm6 avatar

Watchers

 avatar

blur-image's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.