Image Inpainting Using Python

Share:
In this blog we will talk about the image inpainting. What image inpainting is and how we will do this with the help of Python.Let's first see the definition of the image inpainting.

Definition:Image inpainting refers to the process of filling-in missing data in a designated region of the visual input.

Inpainting is a method of restoration where broken, decaying or missing pieces of an artwork are filled in to give a full picture. This process can be extended to both tangible and visual art forms such as oil or acrylic paints, chemical photographic prints, three-dimensional drawings, or visual photographs and film.
Picture painting is the practice of reconstructing missing parts of a picture so that viewers are unable to claim they have undergone restoration in these regions. Sometimes, this technique is used to delete unwanted artifacts from an image or to restore damaged parts of old images.The figures below show picture painting results for example.

Destroyed Image
Destroyed Image
Restored Image


The modern use of painting may be traced back to Pietro Edwards (1744-1821), Director of Public Picture Restoration in Venice, Italy. Taking a theoretical approach, Edwards focused his energies on restoring the artist's intentions.
Technological advancements led to new applications of inpainting. Widespread use of digital techniques range from entirely automatic computerized inpainting to tools used to simulate the process manually. Since the mid-1990s, the process of inpainting has evolved to include digital media.
Inpainting is the method of reconstructing parts of images and videos lost or worsened. In the world of museums, in the case of a valuable painting, a skilled art conservator or art renovator would perform this task. In the digital world, inpainting refers to sophisticated algorithms being applied to recover lost or damaged parts of image data.


How Program recreate destroyed image 

Deep learning over the last few years has had mind blowing success over computer vision and image processing.
OpenCV has two methods incorporated to it. The same function, cv2.inpaint(),can access both, which simply requires a destroyed image and a layer mask.

Destroyed

Mask


Fast Marching Method

The first is based on a Fast Marching Method, which begins to be unpainted from the region's perimeter and moves towards the apex, rapidly filling everything within the perimeter first.Each pixel is substituted by a weighted normalized sum of all known local pixels.Weight selection is an important topic. Those pixels lying near the perimeter of missing parts, like those near contours, are given more weighting. Using the Fast Marching Method, once a pixel is unpainted, it moves to the next closest pixel, ensuring that those pixels closest to the known pixels are first inpainted.
res = cv.inpaint(src=img_mask, inpaintMask=inpaintMask, inpaintRadius=2, flags=cv.INPAINT_TELEA)
cv.imshow("Inpaint output using FMM",res)


Heuristic Principle

The second method is based on a heuristic principle containing fluid dynamics as well as partial differential equations. It first goes from recognized regions to unknown regions along the edges (because edges are meant to be continuous).It continues to move along isophotes, which can be thought of as lines joining points with the same frequency, matching gradient vectors at the inpainting region's perimeter.

res = cv.inpaint(src=img_mask, inpaintMask=inpaintMask, inpaintRadius=2, flags=cv.INPAINT_NS)
cv.imshow("Inpaint output using NS",res)


 
👉Source code


Different Approaches of Image Inpainting Techniques

     A. Partial Differential Equation (PDE) based.
     B. Texture synthesis based.
     C. Exemplar based.
     D. Hybrid based.
     E. Semi-automatic and Fast.
     F. Wavelet transformation based.
     G. Discrete cosine transform based inpainting.

Pros and Cons

According to the theory and papers, inpainting based on Navier-Stokes is supposed to be slower and has a tendency to produce results which are more blurry than the method based on Fast Marching.
We did not find that to be the case in practice. In our tests INPAINT NS yielded better results and the speed was also marginally better than INPAINT TELEA.

Digital image painting has wide application as well as field of research. It plays an important role in recovering lost or degraded areas in an image and removing unwanted or undesirable part from the image. There are many techniques which are invented with corresponding merits and demerits for the same purpose. In this paper various techniques of image painting are studied.

Different steps taken in different techniques for image inpainting are explained. Their qualities and demerits are briefly debated. Researchers conducted experiments on pictures of different environmental conditions for different techniques. The inpainting formula is achieved depending on texture and structure.

A combined approach to synthesizing target patches using both textured and structural information provides better results compared to structural or textural synthesis only.

     click for more 👇 face-and-eye-detection

No comments