Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Image interpolation from random pixels

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).

enter image description here

like image 731
C graphics Avatar asked Sep 14 '12 17:09

C graphics


2 Answers

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:

enter image description here

function solveStackOverflowProblem()
    im = imread('http://i.stack.imgur.com/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
like image 179
Andrey Rubshtein Avatar answered Sep 23 '22 11:09

Andrey Rubshtein


Your best solution is to use gridfit. Its designed to improve on all the native Matlab functions like TriScatteredInterp and griddata.

like image 22
twerdster Avatar answered Sep 23 '22 11:09

twerdster