Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do i fill "holes" in an image?

I have photo images of galaxies. There are some unwanted data on these images (like stars or aeroplane streaks) that are masked out. I don't just want to fill the masked areas with some mean value, but to interpolate them according to surrounding data. How do i do that in python?

We've tried various functions in SciPy.interpolate package: RectBivariateSpline, interp2d, splrep/splev, map_coordinates, but all of them seem to work in finding new pixels between existing pixels, we were unable to make them fill arbitrary "hole" in data.

like image 659
miceuz Avatar asked Feb 28 '12 08:02

miceuz


People also ask

What is hole filling in image processing?

The first hole-filling method is to fill in the holes in the depth image captured from the sensors used for rendering. Background-oriented priority is proposed to determine the filling order, and a fusing method for finding patches to fill in a hole based on the color and depth information is also proposed.

How do I fill a hole in an image in OpenCV?

Steps for implementing imfill in OpenCVThreshold the input image to obtain a binary image. Flood fill from pixel (0, 0). Notice the difference between the outputs of step 2 and step 3 is that the background in step 3 is now white. Invert the flood filled image ( i.e. black becomes white and white becomes black ).

How do I use Imfill?

Shift-click, right-click, or double-click to select a final point and start the fill operation. Press Return to finish the selection without adding a point. BW2 = imfill( BW ,0, conn ) lets you override the default connectivity as you interactively specify locations.

What is Bwareafilt Matlab?

example. BW2 = bwareafilt( BW , range ) extracts all connected components (objects) from the binary image BW , where the area of the objects is in the specified range , producing another binary image BW2 . bwareafilt returns a binary image BW2 containing only those objects that meet the criteria.


3 Answers

What you want is called Inpainting.
OpenCV has an inpaint() function that does what you want.

like image 100
Adi Shavit Avatar answered Sep 22 '22 10:09

Adi Shavit


What you want is not interpolation at all. Interpolation depends on the assumption that data between known points is roughly contiguous. In any non-trivial image, this will not be the case.

You actually want something like the content-aware fill that is in Photoshop CS5. There is a free alternative available in The GIMP through the GIMP-resynthesize plugin. These filters are extremely advanced and to try to re-implement them is insane. A better choice would be to figure out how to use GIMP-resynthesize in your program instead.

like image 28
Swiss Avatar answered Sep 21 '22 10:09

Swiss


I made my first gimp python script that might help you: my scripts

It is called conditional filter as it is a matrix filter that fill all transparent pixels from an image according to the mean value of its 4 nearest neighbours that are not transparent. Be sure to use a RGBA image with only 0 and 255 transparent values.

Its is rough, simple, slow, unoptimized but bug free.

like image 35
Christian Avatar answered Sep 21 '22 10:09

Christian