liuguoyou / polyblur

An unofficial Python (Numpy and Pytorch) implementation of "Polyblur: Removing mild blur by polynomial reblurring" by Mauricio Delbracio and collaborators.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Non-official Python Implementation of Polyblur

Slightly out-of-focus image Deblurred result with Polyblur

This repository contains a Python implementation of Polyblur: Removing mild blur by polynomial reblurring in IEEE Transaction on Computational Imaging 2021 by Mauricio Delbracio, Ignacio Garcia-Dorado, Soungjoon Choi, Damien Kelly and Peyman Milanfar. We provide Pytorch and Numpy non-official implementations reproducing the quantitative and qualitative results of the original paper.

A description an analysis of the algorithm can be found in a companion IPOL paper: Breaking down Polyblur: Fast blind Correction of Small Anisotropic Blurs in Image Processing OnLine 2022 by Thomas Eboli, Jean-Michel Morel and Gabriele Facciolo.

Test

First install the requirements with

pip install -r requirements.txt

Second install the module with

python setup.py install

The Pytorch implementation of this code runs ONLY with torch 1.10+ versions (because of torch.fft for the computation of the gradients with the pytorch implementation).

Once done, you can test the blind deblurring technique with

python main.py --impath ./pictures/peacock_defocus.png --N 3 --alpha 6 --beta 1

You can modify several parameters, e.g. the number of Polyblur iterations and the deconvolution filter's parameters alpha and beta

Description

After installation, the package is imported to any project with

import polyblur

The code contains functional and module blocks: The first is found in the path

polyblur.polyblur_deblurring

and is agnostic to (H,W,C) or (H,W) Numpy arrays or (B,C,H,W) Pytorch tensors. The latter inherits from torch.nn.module and either call deblurring.polyblur on the whole image or overlapping patches. This module is called with

polyblur.PolyblurDeblurring

Calibration

We also provide a code for reproducing the calibration curves of the original paper with our FFT-based implementation of the gradients, or any other one one can image. To compute the slope and intercept of the model, please run

python calibration_blur_parameters.py

Below is an example of the predicted curves for 1% additive Gaussian noise. If you use the exact same implementation of the gradients as in this repo, you should find something like (0.362, -0.468) for the affine model parameters. You should first provide the path to the DVI2K validation set.

Principal blur direction Orthogonal blur direction

Roadmap

This code reproduces the results of the TCI'22 article but is not as fast. Even though it is not the goal of this repository, here are some elements I will enhance in a near future:

  • polybur.domain_transform should be implemented with a C++ or CUDA-based normalized convolution to be faster.
  • the convolution are too slow with FFT. I should implement it with separable filters as in the TCI paper.

Contact

If you encounter any problem with the code, please contact me at thomas.eboli@ens-paris-saclay.fr.

About

An unofficial Python (Numpy and Pytorch) implementation of "Polyblur: Removing mild blur by polynomial reblurring" by Mauricio Delbracio and collaborators.

License:MIT License


Languages

Language:Python 100.0%