Random Image Interpolation

I would like to ask a question about interpolation of a single-channel image. One channel is chosen simply for simplicity, otherwise I am working on several channel images. Suppose there is a single-channel image with a clean black background (pixel intensity 0), on which there are several pixels with non-zero intensity values. I want to apply the interpolation algorithm to fill the entire black area of โ€‹โ€‹the image with interpolated values โ€‹โ€‹coming from neighboring nonzero intensity pixels.

What interpolation algorithm would you recommend for smooth interpolation applicable to this problem?

As input, we, of course, know the location of these non-black pixels and their intensity. But the location is somewhat random (in one line there can be 10 pixels, in another line - only 8).

enter image description here

+7
source share
6 answers

Normal interp2 will not work here, since your points are not evenly spaced (not sitting on the grid). You can try TriScatteredInterp or download inpaint_nans from file sharing.

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 
+5
source

The best solution is to use gridfit . It is designed to enhance all Matlab built-in functions, such as TriScatteredInterp and griddata.

+3
source

Here is a solution based on the use of radial basis functions (in this case, Gaussian) for constructing interpolations for randomly spaced points with different intensities.

In essence, this reduces the Gaussian at each point, weighs it with the intensity of the point, and summarizes the result.

The sharpness of the interpolation function is controlled by the standard deviation of the selected Gaussian function.

Points:

Mathematica graphics

Interpolation:

Mathematica graphics

Viewing in 3D: Mathematica graphics

With a smaller standard deviation: Mathematica graphics

The code:

 pts = Table[{{RandomReal[{0, 200}], RandomReal[{0, 200}]}, RandomReal[]}, {20}] dists = Function[points, Plus @@ ((PDF[ MultinormalDistribution[#, 200 IdentityMatrix[2]], {x, y}] & /@ points[[All, 1]] ) points[[All, 2]])/ Length@points ] DensityPlot[dists[pts], {x, 0, 200}, {y, 0, 200}, PlotPoints -> 100] 
+3
source

For a relatively small number of points, the ideal way to interpolate them would be to create a triangular grid using only the vertices of each region to determine the pixels within that region, using a weighted average to determine each pixel color.

To find the color of a pixel inside the triangular region, the weights used for each pixel for points A, B and C are respectively (bc-A) / a, (ac-B) / b and (a * bC) / c. This ensures that every influence of the point worsens to zero when the point approaches the opposite edge, so that the transitions between the triangles are smooth.

Keep in mind that you can use any type of mean, including harmonic and geometric, and not just arithmetic, to perform calculations (appearances will vary, but other types of means may be better in any case).

Diagram labeling triangle parts

+2
source

Any interpolation will look very bad with these few non-zero points, but you can try drilling the image with a two-dimensional filter such as a Gaussian kernel and see if you like it.

0
source

As far as I know, there is a method of "multiscale semilocal interpolation with smoothing", which can interpolate good image quality and at the same time reduce smoothing artifacts. Judging by the article (IEEE Transactions on Image Processing, 2012), its quality is better than that of modern algorithms. The code for this method is located at https://github.com/KaiGuo-Vision/MultiscaleInterpolation

0
source

All Articles