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:
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.
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.
This project is licensed under the MIT License. See the LICENSE.md file for details.