Introduction
In this tutorial we will show how to use the algorithm Rapid Frequency Selective Reconstructiom (FSR) for image inpainting.
Basics
Image Inpainting is the process of reconstructing damaged or missing parts of an image. This is achieved by replacing distorted pixels by pixels similar to the neighboring ones. There are several algorithms for inpainting, using different approaches for such replacement.
One of those algorithms is called Rapid Frequency Selectice Reconstruction (FSR). FSR reconstructs image signals by exploiting the property that small areas of images can be represented sparsely in the Fourier domain. See [GenserPCS2018] and [SeilerTIP2015] for details.
FSR can be utilized for the following areas of application:
- Error Concealment (Inpainting): The sampling mask indicates the missing pixels of the distorted input image to be reconstructed.
- Non-Regular Sampling: For more information on how to choose a good sampling mask, please review [GroscheICIP2018] and [GroscheIST2018].
Example
The following sample code shows how to use FSR for inpainting. The non-zero pixels of the error mask indicate valid image area, while zero pixels indicate area to be reconstructed. You can create an arbitrary mask manually using tools like Paint or GIMP. Start with a plain white image and draw some distortions in black.
#include <opencv2/opencv.hpp>
#include <iostream>
int main(
int argc,
char** argv)
{
Mat original_, mask_;
original_ =
imread(
"images/kodim22.png");
Mat im_distorted(original_.size(), original_.type(), Scalar::all(0));
original_.copyTo(im_distorted,
mask);
Mat reconstructed;
imshow(
"orignal image", original_);
imshow(
"distorted image", im_distorted);
imshow(
"reconstructed image", reconstructed);
return 0;
}
GMat mask(const GMat &src, const GMat &mask)
Applies a mask to a matrix.
void imshow(const String &winname, InputArray mat)
Displays an image in the specified window.
int waitKey(int delay=0)
Waits for a pressed key.
@ IMREAD_GRAYSCALE
If set, always convert image to the single channel grayscale image (codec internal conversion).
Definition: imgcodecs.hpp:70
CV_EXPORTS_W Mat imread(const String &filename, int flags=IMREAD_COLOR_BGR)
Loads an image from a file.
void inpaint(InputArray src, InputArray inpaintMask, OutputArray dst, double inpaintRadius, int flags)
Restores the selected region in an image using the region neighborhood.
@ INPAINT_FSR_FAST
See INPAINT_FSR_BEST.
Definition: xphoto/include/opencv2/xphoto/inpainting.hpp:95
int main(int argc, char *argv[])
Definition: highgui_qt.cpp:3
Definition: core/include/opencv2/core.hpp:107
Original and distorted image:
Reconstruction:
Left image: fast quality profile (run time 8 seconds). Right image: best quality profile (1 minute 51 seconds).
Additional Resources
Comparison of FSR to existing inpainting methods in OpenCV