Skip to content

Reverse Pixel Mapping

Reverse pixel mapping is image distortion technique that is used by Lens.

Forward Pixel Mapping

Let's think about distortion as about mathematical function (well, actually it is). This functions parameters are source image point coordinates, and the function value is new coordinates of that point:

(x,y)=f(u,v)

where: u,v are source image point coordinates, x,y are destination (distorted) image coordinates and f() is distortion function. This function answers the question What is the new location of given point in destination image?

So now if we take each pixel of source image and 'move' it to it's new location — we will get distorted image. This is called Forward (Direct) Pixel Mapping.

But if we do so — we will face a problem. Our image is made of pixels, and pixel can have only integer coordinates. But our function value may be fractional. And then if we round the coords, it will result that some pixels of destination image won't get color value and will appear to be 'holes'. And also some pixels coords after rounding may have the same position, so in resulting image such pixels will cover each other, and only the last color will be present.

The solution of that problem is technique called Reverse Pixel Mapping.

Reverse Pixel Mapping

Instead of looking for new pixel locations in destination image, we can take an inverse function of f():

(u,v)=finv(x,y)

This function answers the question From which location of source image we should 'move' pixel to given point?

So now we can loop through each pixel in the destination image and find appropriate color in the source image. Thus we can be sure that every pixel will have one and only one color, so there will be no holes and covered pixels.

But this method leads to the other problem that is covered in Pixel Color Lookup.

TIP

You may wonder how we should know the dimensions of destination image. This is explained in Virtual Viewport article.