Image scaling algorithm

Source: Internet
Author: User

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:

    1. The resolution of the original image src is (SRCW * SrcH);
    2. 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).

    1. Nearest neighbor interpolation
      1. 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.

    1. 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.

    1. bilinear interpolation
      1. 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

    1. Advantages and Disadvantages
      1. The bilinear interpolation method is computationally large, but the image quality is high after zooming, and there is no case of discontinuous pixel values.
      2. 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.
    1. Three convolution method
      1. 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-π)

    1. 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

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.