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.
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.
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 ).
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.
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.
What you want is called Inpainting.
OpenCV has an inpaint()
function that does what you want.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With