Reputation: 1148
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
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:
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
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
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
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
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