Image scaling algorithm is more, the following is only the nearest neighbor interpolation algorithm and bilinear interpolation algorithm to introduce.
As shown in 1, represents the original image and the image after zooming.
Figure 1 Image scaling (original image à scaled image)
Image scaling is the behavior of mapping points in the original image to the point of the target image, that is, to find the point P1 in the target image corresponds to the midpoint p0 in the original image, simply to find a point p0.
Assume:
- The resolution of the original image src is (SRCW * SrcH);
- The resolution of the target image DST is (DSTW * dsth).
So:
The ratio of the original image width to the width of the target image
The ratio of the original image height to the target image
By
Therefore, the coordinates of the point p0 in the original image are calculated as x0, y0 (which may contain decimals).
- Nearest neighbor interpolation
- Principle
From the above derivation process can be obtained in the original image point P0 (x0, y0), but, in this process can be seen that the coordinate value of the point may contain decimals, so we must take a certain method (such as rounding) to discard the fractional part, so that the integer representation of the pixel coordinates, the process is the nearest interpolation method.
- Advantages and Disadvantages
The nearest neighbor interpolation is simple and intuitive, but the resulting image quality is not high, especially when the image is enlarged may produce significant aliasing.
- bilinear interpolation
- Principle
2, the nearest interpolation is when the p0 is obtained, directly find its neighboring point P1, p2, p3, p4 a pixel value as the target point of the pixel, and bilinear interpolation, is based on the P0 point and the surrounding 4 points (P1, p2, p3, p4) distance relationship calculation of the target point pixel values.
Figure 2 bilinear interpolation coordinate diagram
The original points obtained by calculation are p0 (x0, y0), and their 4-week points are:
Possible values for x0 are: sx1 = (int) x0, sx2 = sx1 + 1
Possible values for y0 are: sy1 = (int) y0, sy2 = sy1 + 1
In Figure 2:
S1 = y0–sy1
S2 = sx2–x0
S3 = 1.0–s1
S4 = 1.0–s2
Suppose P1, p2, p3, P4 pixel values were V1, v2, v3, v4,
The bilinear interpolation calculates the p0 point pixel value v0 formula:
V0 = v1*s1*s4 + v2*s1*s2 + v3*s2*s3 + v4*s3*s4
- Advantages and Disadvantages
- The bilinear interpolation method is computationally large, but the image quality is high after zooming, and there is no case of discontinuous pixel values.
- bilinear interpolation has the properties of a low-pass filter, which causes the high-frequency component to be damaged, so that the contour of the image may become blurred to some extent.
- Three convolution method
- Principle
In bilinear interpolation, the pixel value is taken into account by calculating the distance relationship of 4 points around the point P0 (x0, y0), whereas in three convolution, the surrounding 16 neighboring points of the point P0 (x0, y0) are considered.
Assume:
The pixel values of point p0 (x0, y0) calculated from the above are expressed as
which
I is x0 integral part, U is the fractional part of x0;
J is the integral part of the y0, and V is the fractional portion of the y0.
It can be expressed as:
which
S (x) is the approximation of the pair (pi is pi-π)
- Advantages and Disadvantages
The three-time convolution method can overcome the shortcomings of the nearest interpolation and bilinear interpolation two algorithms, the calculation precision is high, but the calculation is bright.
Image scaling algorithm