The commonly used interpolation algorithm in image geometric transformation (scaling, rotation)

Source: Internet
Author: User
Tags abs sin

In the process of image geometric transformation, the commonly used interpolation methods are nearest neighbor interpolation (near sampling method), bilinear interpolation and three convolution method. nearest neighbor interpolation:

This is one of the simplest interpolation methods, in the image of the smallest unit is a single pixel, but in the process of rotating a scale, if there is a decimal, then the floating point coordinates for a simple rounding, to get an integer coordinate, the integer coordinate corresponding to the pixel value is the pixel value of the target pixel. The rounding is taken by taking the integer point in the top-left corner of the nearest-to-the-float coordinate.
As an example:
The grayscale image of the 3*3, with the gray level of each pixel as shown below.

We're going to zoom in and turn it into a 4*4 image, which is actually equivalent to zooming in 4/3 times times, from this multiple we can get this proportional relationship:

According to the formula, we can calculate the coordinates in the target image (0,0) and the corresponding coordinates in the original image (0,0).
(because the denominator cannot be 0, so we rewrite the formula)

Then we can determine the pixel grayscale of the (0,0) coordinates in the target image, which is 234.

We then determine the (0,1) coordinates in the target image with the corresponding coordinates in the original image, applying the same formula:

We found that there is a decimal here, that is, it corresponds to the original image of the coordinates (0,0.75), the display is wrong, if we do not consider sub-pixel situation, then a pixel unit is the smallest unit in the image, then according to the nearest interpolation algorithm, We find the nearest integer nearest to 0.75, which is 1, so the corresponding original is the coordinates (0,1) and the pixel grayscale is 67. bilinear interpolation:

For a destination pixel, set the coordinates by the inverse transformation to obtain the floating point coordinates (I+U,J+V), where I, j are non-negative integers, u, v is the [0,1] interval floating point number, then this pixel value f (i+u,j+v) can be from the original image coordinates (I,J), (I+1,j), (i,j+ 1), (i+1,j+1) corresponds to the value of the surrounding four pixels, namely:

f (i+u,j+v) = (1-u) (1-v) F (i,j) + (1-u) VF (i,j+1) + u (1-v) f (i+1,j) + UVF (i+1,j+1)

where F (i,j) represents the pixel value at the source image (I,j).

Then the above example, the target image (0,1) corresponding to the original image floating point coordinates (0,0.75), the above formula can be written as the coordinates (0+0,0+0.75), wherein i=0,j=0,u=0,v=0.75
Let's take a look at the final grayscale of the formula.
F (i+u,j+v) = 0.25*f (0,0) +0.75*f (0,1) =0.25*234+0.75*67
approximately equal to 108

This is the bilinear interpolation method. The bilinear interpolation method is computationally large, but the image quality is high after zooming, and there is no case of discontinuous pixel values. Because bilinear interpolation has the properties of low-pass filter, the high-frequency component is damaged, so the image contour may become blurred to some extent. Three convolution method:

In fact, this method seems to have a lot of names, it is named Inter_cubic in OpenCV, is the cubic (three times) meaning, now I take it and three times convolution method is considered to be the same algorithm, referring to a post inside the words:

Full-bicubic (three-time) convolution interpolation.
The code may be written differently, and the way it is implemented is a
This algorithm is an approximation to the function sin x/x, which means the effect of the original image on the target image.
equals the point at which the target point corresponds to the x distance around the original image point, weighted by the sin x/x scale.
Here x indicates that the surrounding point corresponds to the target point, x or Y axis corresponding to the relative position of the original.
The sin x/x is normalized, and the approximate formula is actually applied

F (i+u,j+v) = [A] * [B] * [C]
[A]=[S (U + 1) s (U + 0) s (u-1) s (u-2)]
┏f (I-1, j-1) F (i-1, j+0) F (i-1, j+1) F (i-1, j+2) ┓
[B]=┃f (I+0, j-1) F (i+0, j+0) F (i+0, j+1) F (i+0, j+2) ┃
┃f (i+1, j-1) F (i+1, j+0) F (i+1, j+1) F (i+1, j+2) ┃
┗f (i+2, j-1) F (i+2, j+0) F (i+2, j+1) F (i+2, j+2) ┛
┏s (v + 1) ┓
[C]=┃s (v + 0) ┃
┃s (V-1) ┃
┗s (V-2) ┛
┏1-2*abs (x) ^2+abs (x) ^3, 0<=abs (x) <1┓
S (x) ={4-8*abs (x) +5*abs (x) ^2-abs (x) ^3, 1<=abs (x) <2┃
┗0, Abs (x) >=2┛

S (x) is the approximation of Sin (X*PI)/x (pi is pi--π)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.