Interpolation of empty area in the image

I would like to interpolate values of empty places (value == 0) in my image (as shown below) without changing the values in other places.
I am able to create a mask of 0 and 1 with the places to interpolate, but I do not know how do the interpolation itself. I have tried roifill and imreconstruct functions, but it does not work properly for me. Function imfill also does not produce correct result as the empty places are not in closed areas.
Any ideas will be appreciated.

 Accepted Answer

Did you try regionfill()? If your region is not closed, like the zeros go out to the edge of the image, then you might have to write in some value along the edge of the region so that there is something in the layer of pixels just outside the zero region
mask = yourImage == 0;
newImage = regionfill(yourImage, mask);

3 Comments

I might give it a try, but first I would have to update Matlab...
I thought that roifill should work in the same way:
J = roifill(I, BW) uses BW (a binary image the same size as I) as a mask. roifill fills in the regions in I corresponding to the nonzero pixels in BW. If there are multiple regions, roifill performs the interpolation on each region independently.
but it does not give me any results - the image stays the same as the input one. I have tried with BW of both types double and logical.
Regarding your suggestion to enclose the area with some values around the image - wouldn't then the interpolation be calculated also based on those pixels? I can try to set them as low as possible just to satisfy >0 condition, but still it might influence the result.
No, roifill is kind of weird and non-intuitive - that's why they came up with regionfill(). With roifill(), you need to dilate the mask one layer with imdilate() before you can use roifill() or else it just smears in zeros. Kind of useless.
See Steve's blogs on the function: http://www.mathworks.com/search/site_search.html?q=roifill&c[]=blogs
OK, thank you for clarification and your suggestions.
For now I devised an iterative method based on the Gerchberg–Saxton algorithm. So it goes like this:
1. FFT(image)
2. low-pass filtering
3. iFFT(f_image)
4. new_image = image + iFFT .* mask
5. repeat 1. for new_image as input
Still it is dependent on the filter size, but gives reasonable results - at least in the central region:
When I will update Matlab to latest version, I will try the regionfill function.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!