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.
- 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.
Clone the repository to your local machine:
git clone https://github.com/mathusanm6/Blur-Image.git
cd Blur-Image
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
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
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.
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:
Input: Blurred image I
, PSF P
, number of iterations n_it
Output: Restored image J
# 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
Sharpening are done not knowing the kernel used for blurring and the number of iterations using the Blind Richardson-Lucy deconvolution algorithm as follows:
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
# 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
This project is licensed under the MIT License. See the LICENSE.md file for details.