serg66
serg66

Reputation: 1148

Image interpolation (bicubic or bilinear). What if there are no neighbor pixels?

Since there's no native implementation of interpolation in JavaScript (beside nearest-neighbor), I'm trying to make my own method. But considering that bicubic (or bilinear) interpolation requires neighbor pixels (16 or 4), what should I do with edge pixels that doesn't have needed amount of neighbors? Should I just ignore them? But the interpolation formula requires all pixels.

Upvotes: 4

Views: 7660

Answers (5)

Floris
Floris

Reputation: 518

Wanted to provide my contribution, even though this question was asked a long time ago.

Like Kendall said, you generally make up the point/pixel's value based on nearby values. How you should do this is determined by the interpolation of your choice. More specifically, it is determined by the order of the interpolation polynomial of your method. For the methods the OP mentioned, these are as follows:

  • Nearest-neighbour interpolation is a polynomial of order 0. The function itself is discontinuous (contains jumps), i.e.: its smoothness is C^0;
  • Linear interpolation is a first-order polynomial. The function is continuous (no jumps), but its derivative is not.
  • For (bi)cubic interpolation, the polynomial used is of order 2; the function and its first derivative are continuous (this is indeed the criterion upon which the method is based). This is a third-order approximation of the 'true' function; O(h^3).

When encountering the edge problem, you will want to infer the ghost point's value with an approximation of the same order as your algorithm of choice. For the (bi)cubic case that the OP asked, this is as follows. Suppose that [x1 x2 x3 x4 x5] are your input values; you will want to calculate x0 as:

x0 = 3*x1 - 3*x2 + x3 and, similarly: x6 = 3*x5 - 3*x4 + x3

Upvotes: 2

Michał Gawlas
Michał Gawlas

Reputation: 196

According to Don Lancaster's article "A Review of Some Image Pixel Interpolation Algorithms" (link), substituting the nearest known values is an accepted way of solving the problem. The article proposes (ab)using linear interpolation to extrapolate the values as an alternative - personally I found the results after applying nearest-neighbor completion more to my liking, though.

Upvotes: 1

andrew cooke
andrew cooke

Reputation: 46862

repeat the nearest pixel.

DON'T use white or black, as that will introduce a lighter or darker shade, respectively, right on the edge.

Upvotes: 7

huseyin tugrul buyukisik
huseyin tugrul buyukisik

Reputation: 11910

It is extrapolation if there are no neighbours in one side. If you want an extrapolation: http://en.wikipedia.org/wiki/Extrapolation

It is done by Lagrange's interpolation: http://en.wikipedia.org/wiki/Lagrange_interpolation

Upvotes: 4

Kendall Frey
Kendall Frey

Reputation: 44316

Generally, you make up a value for the imaginary edge pixels.

The easiest way is to set all edge pixels to white or black, but it's pretty easy to set them to the color of the nearest real pixel.

Upvotes: 3

Related Questions