I would like to ask a question regarding single channel image interpolation. Single channel is chosen just for simplicity otherwise I'm working on multiple channel images. Assume there is a single channel image with pure black background ( pixel intensity 0) on which there are some pixels with non-zero intensity values. I want to apply an interpolation algorithm to fill the entire black area of the image with interpolated values coming from the neighboring non-zero intensity pixels.
What interpolation algorithm would you recommend for a smooth interpolation applicable to this problem?
As inputs, we of course know the location of those non-black pixels and their intensity. But the location is somewhat random ( in one row may be 10 pixels, in another row only 8).
The regular interp2
will not work here, since your points are not located at regular intervals (Not sitting on a grid).
You can either try TriScatteredInterp
or download inpaint_nans
from the file exchange.
Here is the solution in your case with TriScatteredInterp
:
function solveStackOverflowProblem()
im = imread('https://i.sstatic.net/lMaYR.png');
im = im(:,:,2);
[i,j] = find(im);
y = j; x = i;
indexes = sub2ind(size(im),i,j);
interpolator = TriScatteredInterp(x,y,double(im(indexes)));
[Y,X] = meshgrid( 1:size(im,2),1:size(im,1));
reconstructedImage = interpolator(X,Y);
figure;imshow(reconstructedImage/255)
end