Exploring Image Deblurring via Encoded Blur Kernel Space

Oct 25, 2023 | Data Science

In the realm of image processing, deblurring is akin to restoring a picture that has fallen prey to the unpredictable elements of motion or focus discrepancies. Today, we unravel an approach that meticulously encodes blur operators of sharp-blur image pairs into a blur kernel space, ultimately crafting a pathway to clearer images. Let’s delve into this fascinating method of image deblurring.

About the Project

This project introduces a novel way to encode the blur operators found within an arbitrary dataset comprised of sharp and blurred image pairs. By leveraging this encoded kernel space, we propose an alternating optimization algorithm for blind image deblurring. The process approximates unseen blur operators by corresponding kernels in the encoded space, while also searching for the sharp images that have unfortunately been obscured. Given its design, the encoded kernel space boasts full differentiability, making it seamlessly integrable into deep neural network models.

Blur kernel space

Getting Started

Prerequisites

  • Python = 3.7
  • Pytorch = 1.4.0
  • CUDA = 10.0

Installation

To set up your environment, follow these steps:

sh
git clone https://github.com/VinAIResearch/blur-kernel-space-exploring.git
cd blur-kernel-space-exploring
conda create -n BlurKernelSpace -y python=3.7
conda activate BlurKernelSpace
conda install --file requirements.txt

Training and Evaluation

Preparing Datasets

Datasets can be downloaded from the model zoo section. For customized datasets, ensure they are organized as follows:

root
   ├── blur_imgs
   │       ├── 000
   │       │       ├── 00000000.png
   │       │       ├── 00000001.png
   │       ├── 001
   │       │       ├── 00000000.png
   │       │       ├── 00000001.png
   └── sharp_imgs
           ├── 000
           │       ├── 00000000.png
           │       ├── 00000001.png
           ├── 001
                   ├── 00000000.png
                   ├── 00000001.png

After organizing your dataset, run the following scripts to create an LMDB dataset:

sh
python create_lmdb.py --H 720 --W 1280 --C 3 --img_folder REDS/train_sharp --name train_sharp_wval --save_path ../datasets/REDS/train_sharp_wval.lmdb
python create_lmdb.py --H 720 --W 1280 --C 3 --img_folder REDS/train_blur --name train_blur_wval --save_path ../datasets/REDS/train_blur_wval.lmdb

Where (H, C, W) represent the shape of the images, ensuring all images share the same dimensions.

Training the Model

To initiate image deblurring, the blur encoding network (referred to as F in the paper) must be trained. After creating the dataset, modify dataroot_HQ and dataroot_LQ in the options/kernel_encoding/REDSwoVAE.yml file to match your dataset paths. Execute the following command:

python train.py -opt options/kernel_encoding/REDSwoVAE.yml

Training details, logs, and states will be preserved in experiments/modelName.

Testing

Data Augmentation

To augment your dataset:

sh
python data_augmentation.py --target_H=720 --target_W=1280 --source_H=720 --source_W=1280 --augmented_H=256 --augmented_W=256 --source_LQ_root=datasets/REDS/train_blur_wval.lmdb --source_HQ_root=datasets/REDS/train_sharp_wval.lmdb --target_HQ_root=datasets/REDS/test_sharp_wval.lmdb --save_path=results/GOPRO_augmented --num_images=10 --yml_path=options/data_augmentation/default.yml

Generate Novel Blur Kernels

To create a blurred image from a sharp reference:

sh
python generate_blur.py --yml_path=options/generate_blur/default.yml --image_path=imgs/sharp_imgs/mushishi.png --num_samples=10 --save_path=.res.png

This command requires that the model was trained with the –VAE flag, and input images must be divisible by 128.

Generic Deblurring

For deblurring an image:

sh
python generic_deblur.py --image_path imgs/blur_imgs/blur1.png --yml_path options/generic_deblur/default.yml --save_path=.res.png

The final output will save a sharp version of the blurry image.

Model Zoo

We provide pretrained models and corresponding datasets, which can be found in the model zoo section. For detailed instructions on manipulating models and augmenting data, refer to the testing section.

Troubleshooting

If you encounter any errors while setting up or running your scripts, consider these troubleshooting tips:

  • Ensure all dependencies are correctly installed and compatible with your Python version.
  • Double-check the directory structure of your datasets for consistency.
  • If scripts do not execute, verify that your terminal is in the correct directory of the cloned repository.
  • Memory issues may arise; consider lowering the batch size as a potential fix.

For more insights, updates, or to collaborate on AI development projects, stay connected with fxis.ai.

At fxis.ai, we believe that such advancements are crucial for the future of AI, as they enable more comprehensive and effective solutions. Our team is continually exploring new methodologies to push the envelope in artificial intelligence, ensuring that our clients benefit from the latest technological innovations.

Conclusion

Image deblurring via encoded blur kernel space is a pioneering approach that makes sharp images practically accessible, illuminating the pathway for a slew of applications in imaging technology, from photography to medical imaging. With the outlined methods, clear images are just a code execution away!

Stay Informed with the Newest F(x) Insights and Blogs

Tech News and Blog Highlights, Straight to Your Inbox