1

I have an image and and am transforming it with a nonlinear spatial transformation. I have a written a function that, for every pixel (i, j) in the destination image array, returns a coordinate (y, x) in the source array.

The returned coordinate is a floating point value, meaning that it corresponds to a point that lies between the pixels in the source image.

Does anyone know if there an established method in PIL or opencv to interpolate the value of this subpixel, or should I roll my own? Thanks!

c-wilson
  • 395
  • 3
  • 11
  • related: https://stackoverflow.com/a/13301755/6464041 – Gábor Fekete Feb 13 '18 at 13:47
  • google opencv subpixel value would have given you the answer 30 minutes ago ;) – Piglet Feb 13 '18 at 13:49
  • @Piglet since that question imposes a restriction that isn't in this one, namely that they're looking for a bilinear interpolation, I don't consider them duplicate. I wouldn't settle for anything less than bicubic myself. – Mark Ransom Feb 13 '18 at 17:28
  • Thanks everyone, I was just seeing if there was a built-in method for this specifically. Coding the bicubic should be straightforward! – c-wilson Feb 13 '18 at 18:05

1 Answers1

0

There are two common methods:

  • bilinear interpolation,

  • bicubic interpolation.

These evaluate an intermediate value, based on the values at four or sixteen neighboring pixels, using weighting functions based on the fractional parts of the coordinates.

Lookup these expressions.

From my experience, the bilinear quality is often sufficient.