https://github.com/mathusanm6/blur-image
A Python tool for blurring images pixel by pixel using mathematical algorithms and also providing an approximate solution for sharpening the blurred image.
https://github.com/mathusanm6/blur-image
blind-richardson-lucy blur convolve image image-processing kernel-convolution richardson-lucy-deconvolution scipy sharpen sharpen-image
Last synced: 11 months ago
JSON representation
A Python tool for blurring images pixel by pixel using mathematical algorithms and also providing an approximate solution for sharpening the blurred image.
- Host: GitHub
- URL: https://github.com/mathusanm6/blur-image
- Owner: mathusanm6
- License: mit
- Created: 2024-03-22T20:34:06.000Z (almost 2 years ago)
- Default Branch: main
- Last Pushed: 2024-05-28T10:02:00.000Z (over 1 year ago)
- Last Synced: 2024-05-29T01:13:21.730Z (over 1 year ago)
- Topics: blind-richardson-lucy, blur, convolve, image, image-processing, kernel-convolution, richardson-lucy-deconvolution, scipy, sharpen, sharpen-image
- Language: Python
- Homepage:
- Size: 100 MB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# 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:
```bash
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:
```bash
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:
```bash
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:
## Richardson-Lucy Deconvolution Algorithm
**Input:** Blurred image `I`, PSF `P`, number of iterations `n_it`
**Output:** Restored image `J`
```python
# Initialize
J0 = I
# Iterative deconvolution
for n in range(1, n_it + 1):
# Convolve Jn with P to obtain a blurred estimation I_estimated
I_estimated = convolve(Jn, P)
# Calculate the relative blur ratio
Ratio = I / (I_estimated + epsilon)
# Convolve this ratio with the mirror of the PSF
Correction = convolve(Ratio, P_mirror)
# Update the estimation
Jn = Jn * Correction
# Return the final restored image
return Jn_it
```
#### Original Image
(1) Grayscale Flower
(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
Unblurred Images
5 Iterations
5 Iterations
5 Iterations
5 Iterations
5 Iterations
5 Iterations
5 Iterations
10 Iterations
10 Iterations
10 Iterations
10 Iterations
10 Iterations
10 Iterations
10 Iterations
15 Iterations
15 Iterations
15 Iterations
15 Iterations
15 Iterations
15 Iterations
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
Unblurred Images
5 Iterations
5 Iterations
5 Iterations
5 Iterations
5 Iterations
5 Iterations
5 Iterations
10 Iterations
10 Iterations
10 Iterations
10 Iterations
10 Iterations
10 Iterations
10 Iterations
15 Iterations
15 Iterations
15 Iterations
15 Iterations
15 Iterations
15 Iterations
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:
## Blind Richardson-Lucy Deconvolution Algorithm
**Input:** Blurred image `I`, initial PSF `P`, number of iterations for image `n_it`, number of iterations for PSF `psf_it`
**Output:** Restored image `J`, refined PSF `P`
```python
# Initialize
J0 = I
# Iterative deconvolution
for n in range(1, n_it + 1):
# Convolve Jn with P to obtain a blurred estimation I_estimated
I_estimated = convolve(Jn, P)
# Calculate the relative blur ratio
Ratio = I / (I_estimated + epsilon)
# Convolve this ratio with the mirror of the PSF
Correction = convolve(Ratio, P_mirror)
# Update the estimation
Jn = Jn * Correction
# PSF refinement
for m in range(1, psf_it + 1):
# Convolve Jn+1 with P to obtain a new blurred estimation I_estimated
I_estimated = convolve(Jn, P)
# Calculate the error ratio
E = I / (I_estimated + epsilon)
# Convolve this ratio with the mirror of the restored image Jn+1
PSF_Update = convolve(E, Jn_mirror)
# Update the PSF
P = P * PSF_Update
# Normalize the PSF
P = P / sum(P)
# Return the final restored image and refined PSF
return Jn_it, P
```
### Original Image
(A) Blurred tiger (Unknown Kernel)
### Processed Images
#### (A) Blurred Tiger (Unknown Kernel)
Average 3x3
Average 5x5
Average 11x11
Gaussian 5x5, sigma: 1.0
Gaussian 5x5, sigma: 2.0
15 Iterations, 25 PSF Iterations
15 Iterations, 25 PSF Iterations
15 Iterations, 25 PSF Iterations
15 Iterations, 25 PSF Iterations
15 Iterations, 25 PSF Iterations
30 Iterations, 25 PSF Iterations
30 Iterations, 25 PSF Iterations
30 Iterations, 25 PSF Iterations
30 Iterations, 25 PSF Iterations
30 Iterations, 25 PSF Iterations
60 Iterations, 25 PSF Iterations
60 Iterations, 25 PSF Iterations
60 Iterations, 25 PSF Iterations
60 Iterations, 25 PSF Iterations
60 Iterations, 25 PSF Iterations
120 Iterations, 25 PSF Iterations
120 Iterations, 25 PSF Iterations
120 Iterations, 25 PSF Iterations
120 Iterations, 25 PSF Iterations
120 Iterations, 25 PSF Iterations
## License
This project is licensed under the MIT License. See the [LICENSE.md](LICENSE.md) file for details.