Image scaling method and apparatus, and device and storage medium

Calculate image scaling coefficients and interpolation coefficients through fixed-point operations, avoiding floating point operations, improving the efficiency of image scaling, and solving the problems of large computational complexity and low efficiency in traditional methods.

WO2024212665A1PCT designated stage expired Publication Date: 2024-10-17TENCENT TECHNOLOGY (SHENZHEN) CO LTD
View PDF 6 Cites 0 Cited by

Patent Information

Application Number
PCT/CN2024/073743
Authority / Receiving Office
WO · WO
Patent Type
Applications
Current Assignee / Owner
Priority Date
2023-04-12
Filing Date
2024-01-24
Publication Date
2024-10-17

AI Technical Summary

Technical Problem

In the traditional image scaling method, the bilinear interpolation algorithm uses floating point division when calculating the scaling coefficient, resulting in a large number of complex floating point operations in the subsequent calculation process, which is large in computational complexity and low in efficiency.

Method used

Calculate the horizontal scaling coefficient and vertical scaling coefficient in the form of integers through fixed-point operations, determine the coordinates and interpolation coefficients of the pixels to be processed in the original image, avoid floating point operations, and directly perform data operations in the form of integers.

Benefits of technology

It reduces the amount of calculations and improves the calculation efficiency of image scaling. It is suitable for embedded devices with high power consumption requirements and which do not support floating point operations.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN2024073743_17102024_PF_FP_ABST
    Figure CN2024073743_17102024_PF_FP_ABST
Patent Text Reader

Abstract

The present application relates to the technical field of image processing. Disclosed are an image scaling method and apparatus, and a device and a storage medium. The method comprises: according to the width and height of an original image, the width and height of a target image, and an integral displacement value, obtaining a transverse scaling coefficient and a longitudinal scaling coefficient by means of a fixed-point operation; for each pixel point to be processed in the target image, according to the coordinates of the pixel point to be processed, the transverse scaling coefficient, the longitudinal scaling coefficient and the displacement value, obtaining, from the original image and by means of a fixed-point operation, the coordinates of an original pixel point corresponding to the pixel point to be processed, and a fixed-point interpolation coefficient; according to the pixel value of the original pixel point, the fixed-point interpolation coefficient and the displacement value, obtaining, by means of a fixed-point operation, the pixel value of the pixel point to be processed; and on the basis of the pixel value of each pixel point to be processed in the target image, obtaining a target image after the original image is scaled. The fixed-point operation is used in the whole image scaling process, thereby avoiding a floating-point operation, and reducing the operation amount and improving the operation efficiency.
Need to check novelty before this filing date? Find Prior Art

Description

Image scaling method, device, equipment and storage medium

[0001] This application claims priority to the Chinese patent application filed with the China Patent Office on April 12, 2023, application number 202310440006.X, and application name “Image Scaling Method, Device, Equipment and Storage Medium”, the entire contents of which are incorporated by reference into this application. Technical Field

[0002] The present application relates to the field of image processing technology, and in particular to image scaling technology. Background Art

[0003] Image scaling technology is widely used in various scenarios, such as XR (Extended Reality), autonomous driving, face recognition, gesture recognition, etc., aiming to adjust images to the appropriate size for subsequent processing.

[0004] Among traditional image scaling methods, bilinear interpolation is widely used. Specifically, a scaling factor is calculated based on the target image size and the original image size. This scaling factor is then used to determine the coordinates of several original pixels on the original image corresponding to the target pixel. Interpolation coefficients are also determined simultaneously. The pixel value of the target pixel is ultimately determined based on these original pixel values ​​and the interpolation coefficients.

[0005] The bilinear interpolation algorithm provided by the above-mentioned related technologies uses floating-point division when calculating the scaling coefficient, and the subsequent calculation process also includes a large number of complex floating-point operations, resulting in a large amount of calculation and low calculation efficiency.

[0006] Summary of the Invention

[0007] The embodiments of the present application provide an image scaling method, apparatus, device, and storage medium. The technical solutions provided by the embodiments of the present application are as follows:

[0008] According to one aspect of an embodiment of the present application, a method for image scaling is provided, the method being executed by a computer device, the method comprising:

[0009] According to the size of the original image, the size of the target image and the displacement value in integer form, a horizontal scaling factor and a vertical scaling factor in integer form are obtained through fixed-point operation;

[0010] For each pixel to be processed in the target image, obtain the coordinates of the original pixel corresponding to the pixel to be processed in the original image and a fixed-point interpolation coefficient in integer form through fixed-point calculation based on the coordinates of the pixel to be processed, the horizontal scaling factor, the vertical scaling factor, and the displacement value;

[0011] Obtaining the pixel value of the pixel to be processed by fixed-point operation according to the pixel value of the original pixel, the fixed-point interpolation coefficient and the displacement value;

[0012] The target image after scaling the original image is obtained based on the pixel value of each of the to-be-processed pixels in the target image.

[0013] According to one aspect of an embodiment of the present application, an image scaling apparatus is provided, the apparatus being deployed on a computer device, the apparatus comprising:

[0014] A scaling factor determination module is used to obtain an integer horizontal scaling factor and an integer vertical scaling factor through fixed-point calculation based on the width and height of the original image, the width and height of the target image, and the integer displacement value;

[0015] an interpolation coefficient determination module configured to obtain, for each pixel to be processed in the target image, the coordinates of the original pixel corresponding to the pixel to be processed in the original image and a fixed-point interpolation coefficient in integer form through fixed-point calculation based on the coordinates of the pixel to be processed, the horizontal scaling coefficient, the vertical scaling coefficient, and the displacement value;

[0016] a pixel value determination module, configured to obtain the pixel value of the pixel to be processed by fixed-point calculation according to the pixel value of the original pixel, the fixed-point interpolation coefficient, and the displacement value;

[0017] An image generation module is used to obtain the target image after scaling the original image based on the pixel value of each pixel to be processed in the target image.

[0018] According to one aspect of an embodiment of the present application, a computer device is provided, comprising a processor and a memory, wherein a computer program is stored in the memory, and the computer program is loaded and executed by the processor to implement the above-mentioned image scaling method.

[0019] According to one aspect of an embodiment of the present application, a computer-readable storage medium is provided, in which a computer program is stored. The computer program is loaded and executed by a processor to implement the above-mentioned image scaling method.

[0020] According to one aspect of an embodiment of the present application, a computer program product is provided, which includes a computer program stored in a computer-readable storage medium. A processor reads and executes the computer program from the computer-readable storage medium to implement the above-mentioned image scaling method.

[0021] The technical solutions provided by the embodiments of the present application include at least the following beneficial effects:

[0022] When scaling an original image to obtain a target image that meets size requirements, fixed-point operations can be used to obtain integer horizontal and vertical scaling coefficients based on the size of the original image, the size of the target image, and a pre-set integer displacement value. Then, for each pixel to be processed in the target image, fixed-point operations are used to obtain the coordinates of the original pixel corresponding to the pixel to be processed in the original image, as well as integer fixed-point interpolation coefficients based on the coordinates of the pixel to be processed, the horizontal and vertical scaling coefficients, and the displacement value. Next, fixed-point operations are used to obtain the pixel value of the pixel to be processed based on the pixel value of the original pixel, the fixed-point interpolation coefficient, and the displacement value. In the above process, integer scaling coefficients are obtained through operations, and integer fixed-point interpolation coefficients are calculated based on the integer scaling coefficients. The pixel value of the pixel to be processed is then calculated based on the integer fixed-point interpolation coefficients. Finally, the target image after scaling the original image is obtained based on the pixel values ​​of each pixel to be processed in the target image. This ensures that fixed-point operations are performed using integer data throughout the entire image scaling process, avoiding floating-point operations, thereby reducing the amount of operations and improving operational efficiency. BRIEF DESCRIPTION OF THE DRAWINGS

[0023] FIG1 is a schematic diagram of performing image scaling on an original image to obtain a target image;

[0024] FIG2 is a schematic diagram of an implementation environment of a solution provided by an embodiment of the present application;

[0025] FIG3 is a schematic diagram of a gesture detection scenario provided by an embodiment of the present application;

[0026] FIG4 is a flow chart of an image scaling method provided by one embodiment of the present application;

[0027] FIG5 is a block diagram of an image scaling apparatus provided by one embodiment of the present application;

[0028] FIG6 is a structural block diagram of a computer device provided in one embodiment of the present application. DETAILED DESCRIPTION

[0029] In order to make the objectives, technical solutions and advantages of this application clearer, the implementation methods of this application will be further described in detail below with reference to the accompanying drawings.

[0030] In computer image processing and graphics, image scaling refers to the process of resizing a digital image by adding or removing pixels to change its dimensions. Image scaling is not a simple process due to the trade-offs between processing efficiency and image quality (such as smoothness and clarity). When an image is increased in size, the pixels that make up the image also become larger, resulting in a "softer" appearance. However, when an image is reduced in size, it becomes smoother and sharper.

[0031] Bilinear interpolation is a commonly used algorithm in image scaling, balancing processing efficiency and image quality. Mathematically, bilinear interpolation extends linear interpolation to a two-dimensional rectangular grid, used to interpolate functions of two variables (such as x and y). Its core concept is to perform linear interpolation once in each direction.

[0032] The following describes an image scaling method based on bilinear interpolation using floating-point operations. Taking the width and height dimensions as an example, the process is as follows:

[0033] 1. Calculate the horizontal and vertical scaling factors based on the width and height of the original image and the width and height of the target image;

[0034] The original image is reduced or enlarged to obtain a target image. For example, as shown in FIG1 , the original image 11 is reduced to obtain a target image 12 .

[0035] The width and height of the original image include the width and height of the original image. Here, the width of the original image is recorded as Width src , the height value of the original image is recorded as Height src The width and height of the target image include the width and height of the target image. Here, the width of the target image is recorded as Width dst , the height value of the target image is recorded as Height dst The width and height of the original image can be measured from the original image to be scaled. The width and height of the target image can be set in advance based on the actual scaling requirements.

[0036] The horizontal scaling factor may refer to the scaling factor in the width direction, which is denoted as Wratio. The horizontal scaling factor is equal to the width of the original image divided by the width of the target image, that is, Wratio = Width src / Width dst .

[0037] The vertical scaling factor may refer to the scaling factor in the height direction, which is denoted as Hratio. The vertical scaling factor is equal to the height of the original image divided by the height of the target image, that is, Hratio = Height src / Height dst .

[0038] 2. For a pixel to be processed in the target image, calculate the coordinates of at least one original pixel in the original image corresponding to the pixel to be processed, and the interpolation coefficient based on the coordinates of the pixel to be processed, the horizontal scaling factor, and the vertical scaling factor;

[0039] The pixel to be processed can be any pixel in the target image. The coordinates of the pixel to be processed refer to the coordinates of the pixel to be processed in the target image. For example, a two-dimensional rectangular coordinate system can be established, with the upper left corner vertex of the target image as the origin, the width direction as the x-axis, and the height direction as the y-axis, so that the coordinates of each pixel in the target image can be determined. Similarly, a two-dimensional rectangular coordinate system can be established, with the upper left corner vertex of the original image as the origin, the width direction as the x-axis, and the height direction as the y-axis, so that the coordinates of each pixel in the original image can be determined.

[0040] As shown in FIG1 , the at least one original pixel point in the original image 11 corresponding to the pixel point to be processed 13 includes: a first original pixel point 14, a second original pixel point 15, a third original pixel point 16, and a fourth original pixel point 17. Assume that the coordinates of the pixel point to be processed are (X dst , Y dst ),but:

[0041] The coordinates of the first original pixel are (X src , Y src );

[0042] The coordinates of the second original pixel are (MIN(Width src , Xsrc+1), Ysrc);

[0043] The coordinates of the third original pixel are (X src MIN(Height src , Y src +1);

[0044] The coordinates of the fourth original pixel are (MIN(Width src ,Xsrc+1),MIN(Height src , Y src +1);

[0045] Among them, (X src , Y src)=(floor(X dst *Wratio), floor(Y dst *Hratio));

[0046] Among them, MIN means taking the minimum value to prevent the coordinates from exceeding the original image size, and floor means rounding operation.

[0047] The interpolation coefficient includes the horizontal interpolation coefficient and the vertical interpolation coefficient. The horizontal interpolation coefficient refers to the interpolation coefficient in the width direction. Here, the horizontal interpolation coefficient is recorded as u. The horizontal interpolation coefficient u = fraction (X dst *Wratio). The longitudinal interpolation coefficient refers to the interpolation coefficient in the height direction. Here, the longitudinal interpolation coefficient is recorded as v. The longitudinal interpolation coefficient v = fraction (Y dst *Hratio). Fraction represents the decimal part.

[0048] 3. Calculate the pixel value of the pixel to be processed based on the pixel value and interpolation coefficient of the at least one original pixel;

[0049] The pixel value F of the pixel to be processed dst =(1-u)*(1-v)*F 00 +(1-u)*v*F 01 +u*(1-v)*F 10 +u*v*F 11 , F 00 、F 10 、F 01 、F 11 are the pixel values ​​of the first original pixel point, the second original pixel point, the third original pixel point, and the fourth original pixel point respectively.

[0050] 4. Based on the pixel values ​​of each pixel to be processed in the target image, a target image is obtained by scaling the original image.

[0051] For each pixel to be processed in the target image, the pixel value of the pixel to be processed can be calculated using the method provided in steps 2 to 3 above. After the pixel value of each pixel to be processed in the target image is calculated, the target image after scaling the original image is obtained.

[0052] From the above process, it can be seen that since floating-point division is used when calculating the scaling factor, the subsequent calculation process also includes a large number of complex floating-point operations, resulting in a large amount of calculation and low calculation efficiency.

[0053] Please refer to FIG. 2 , which shows a schematic diagram of an implementation environment of a solution provided by an embodiment of the present application. The implementation environment of the solution may include: a terminal device 10 and a server 20 .

[0054] The terminal device 10 may be an electronic device such as a mobile phone, tablet computer, PC (Personal Computer), vehicle-mounted terminal, smart home appliance, multimedia player, etc. The terminal device 10 may be installed with a client that runs an application, such as a social application, image processing application, game application, etc., which is not limited in this application.

[0055] The server 20 may be a single server, a server cluster consisting of multiple servers, or a cloud computing service center. The server 20 may be a background server of the above application, configured to provide background services for the client of the application.

[0056] The terminal device 10 and the server 20 can communicate via a network, such as a wireless or wired network.

[0057] In the image scaling method provided in the embodiments of the present application, each step may be performed by a computer device, which may be any electronic device with computing and storage capabilities. For example, the computer device may be the terminal device 10 in the implementation environment of the solution shown in FIG2 , or the server 20 in the implementation environment of the solution shown in FIG2 .

[0058] By way of example, the aforementioned computer device may also be an embedded device. An embedded device, also known as an embedded system, can consist of hardware and software and is a device capable of independent operation. Its software includes the software runtime environment and its operating system. Its hardware encompasses various aspects, including signal processors, memory, and communication modules. Compared to conventional computer processing systems, embedded systems differ significantly. They cannot implement large-capacity storage functions because there are no compatible large-capacity storage media. Most embedded systems use storage media such as E-PROM (Erasable Programmable Read Only Memory) and EEPROM (Electrically Erasable Programmable Read Only Memory). The software component utilizes an Application Programming Interface (API) as the core of the development platform. By way of example, embedded devices include, but are not limited to, embedded microprocessors, embedded microcontrollers, embedded digital signal processors, and embedded systems-on-chip.

[0059] It should be noted that the method provided in the embodiments of the present application may involve artificial intelligence (AI) technology, and in particular, computer vision (CV) technology in AI technology.

[0060] With the research and advancement of artificial intelligence technology, artificial intelligence technology has been studied and applied in many fields, such as common smart homes, smart wearable devices, virtual assistants, smart speakers, smart marketing, unmanned driving, autonomous driving, drones, robots, smart medical care, smart customer service, etc. It is believed that with the development of technology, artificial intelligence technology will be applied in more fields and play an increasingly important role.

[0061] For example, with the increasing popularity of AI applications, some traditional image processing algorithms are gradually being replaced by deep learning. Through AI models built on neural networks, different functions such as target detection, face recognition, and gesture recognition can be implemented on input images. The size of the input image of an AI model built based on a neural network is usually fixed (for example, fixed to a size of 224*224), while the size of the original image is arbitrary. Therefore, it is necessary to scale the original image of any size and adjust it to a target image of a fixed size, and then input the target image into the AI ​​model built based on the neural network for processing.

[0062] Moreover, with the application of AI on embedded devices, after acquiring the original image, the embedded device needs to execute the image scaling method to scale the original image into a target image of a fixed size, and then input the target image into the AI ​​model built based on the neural network for processing, and the AI ​​model outputs the detection or recognition result of the target image.

[0063] Taking gesture recognition in the XR field as an example, an AI model built based on a neural network recognizes an input hand image and obtains gesture recognition results from that image. As shown in Figure 3, after detecting the hand from the captured image, an image containing only the hand needs to be cropped for processing. The size of the cropped hand image 30 is random and may be large or small. However, the AI ​​model built based on a neural network has requirements for the input image size. In this case, an image scaling method can be used to scale the cropped hand image to meet the AI ​​model's input requirements. The scaled hand image is then input into the AI ​​model, which outputs the gesture recognition results.

[0064] The method provided in the embodiments of the present application can be applied to business scenarios of games. For example, in VR (Virtual Reality) games, hand images can be efficiently scaled for subsequent gesture recognition through AI models, thereby improving processing efficiency and improving the gaming experience.

[0065] Please refer to Figure 4, which shows a flow chart of an image scaling method provided by an embodiment of the present application. The execution subject of each step of the method can be a computer device. The method can include at least one of the following steps 410 to 440.

[0066] Step 410 : Obtain integer-form horizontal scaling coefficients and integer-form vertical scaling coefficients through fixed-point operations according to the size of the original image, the size of the target image, and the integer-form displacement value.

[0067] The original image may refer to an image to be scaled. The original image may be a picture or a frame in a video, which is not limited in this application. The original image is reduced or enlarged to obtain the target image.

[0068] In the embodiment of the present application, the size may refer to the width and height. The width and height of the original image may include the width value and height value of the original image. Here, the width value of the original image is recorded as Width src , the height value of the original image is recorded as Height src The width and height of the target image include the width and height of the target image. Here, the width of the target image is recorded as Width dst , the height value of the target image is recorded as Height dst The width and height of the original image can be measured from the original image to be scaled. The width and height of the target image can be set in advance based on the actual scaling requirements.

[0069] In the embodiment of the present application, the width value Width of the original image src and the width of the target image dst The size relationship is not limited. For example, Width src <Width dst , or Width src >Width dst , or Width src =Width dst . Height value of the original image src And the height value of the target image Height dst The size relationship is not limited. For example, Height src <Heightdst , or Height src >Height dst , or Height src =Height dst .

[0070] In addition, image scaling in the embodiments of the present application may refer to adjusting the size of the original image to obtain a target image of a fixed size. The size of the original image is different from the fixed size (i.e., the size of the target image). For the original image and the target image, at least one of their width values ​​and height values ​​is not equal. For example, the width value of the original image and the width value of the target image are not equal, and the height value of the original image and the height value of the target image are also not equal. Alternatively, the width value of the original image and the width value of the target image are equal, and the height value of the original image and the height value of the target image are not equal. Alternatively, the width value of the original image and the width value of the target image are not equal, and the height value of the original image and the height value of the target image are equal. It is worth noting that the image scaling described in the embodiments of the present application may refer to reduction (such as reducing both the width and height values ​​of the original image to obtain the target image), or may refer to enlargement (such as enlarging both the width and height values ​​of the original image to obtain the target image), but may not be limited to this. For example, the width value of the original image may be reduced and the height value of the original image may be enlarged to obtain the target image, or the width value of the original image may be enlarged and the height value of the original image may be reduced to obtain the target image, and so on.

[0071] In an example, suppose the original image has a width and height of 500*600 and needs to be reduced to a target size of 200*200; the width value of the original image is Width src is 500, which means the number of pixels in the width direction of the original image is 500; the height value of the original image is Height src is 600, which means the number of pixels in the height direction of the original image is 600. The width value of the target image is Width dst is 200, which means the number of pixels in the width direction of the target image is 200; the height value of the target image is Height dst It is also 200, which means that the number of pixels in the height direction of the target image is also 200.

[0072] In addition, in the embodiment of the present application, an integer displacement value is set in advance, for example, the displacement value may be 7 or 8. For a detailed description of the displacement value, please refer to the embodiment below.

[0073] The horizontal scaling factor may refer to the scaling factor in the horizontal direction (e.g., width direction), and the horizontal scaling factor is recorded as Wratio here. The vertical scaling factor may refer to the scaling factor in the vertical direction (e.g., height direction), and the vertical scaling factor is recorded as Hratio here. In the embodiment of the present application, the horizontal scaling factor and the vertical scaling factor are integer values ​​obtained by fixed-point operations. Fixed-point operations refer to operations in which the decimal point position of all numbers remains fixed during the operation.

[0074] In some embodiments, the fixed-point operation includes an integer division method, and the dimensions are width and height dimensions, which include width and height values. In this case, the horizontal scaling factor and the vertical scaling factor can be determined by using integer division to shift the width value of the original image to the left by the first digit, and then dividing it by the width value of the target image, and the resulting quotient is used as the horizontal scaling factor; using integer division to shift the height value of the original image to the left by the first digit, and then dividing it by the height value of the target image, and the resulting quotient is used as the vertical scaling factor; wherein the first digit can be determined based on the displacement value. The embodiment of the present application does not limit the numerical relationship between the first digit and the displacement value. For example, the first digit can be twice the displacement value.

[0075] Horizontal scaling factor Wratio=(Width src <<(2×SHIFT_BIT))%Width dst ;

[0076] Vertical scaling factor Hratio=(Height src <<(2×SHIFT_BIT))%Height dst ;

[0077] Here, SHIFT_BIT represents the shift value, << represents a left shift operation, and % represents integer division, that is, the quotient is calculated using integer division. For example, 5%2=2.

[0078] In step 420, for each pixel to be processed in the target image, the coordinates of the original pixel corresponding to the pixel to be processed in the original image and the fixed-point interpolation coefficient in integer form are obtained through fixed-point calculation based on the coordinates of the pixel to be processed, the horizontal scaling coefficient, the vertical scaling coefficient and the displacement value.

[0079] The pixel to be processed may be any pixel in the target image. The coordinates of the pixel to be processed may refer to the coordinates of the pixel to be processed in the target image. For example, a two-dimensional rectangular coordinate system may be established, with the upper left corner vertex of the target image as the origin, the horizontal direction as the x-axis, and the vertical direction as the y-axis, so that the coordinates of each pixel in the target image can be determined. Similarly, a two-dimensional rectangular coordinate system may be established, with the upper left corner vertex of the original image as the origin, the horizontal direction as the x-axis, and the vertical direction as the y-axis, so that the coordinates of each pixel in the original image can be determined.

[0080] Among them, the original pixel points in the original image corresponding to the pixel points to be processed may include one or more. In a possible implementation method, the number of original pixel points in the original image corresponding to the pixel points to be processed may be 4. For example, the original pixel points in the original image corresponding to the pixel points to be processed include: a first original pixel point, a second original pixel point, a third original pixel point and a fourth original pixel point.

[0081] In this case, the coordinates of the multiple original pixel points have the following relationship: the horizontal coordinate of the second original pixel point is the smaller value of the width of the original image and the first value, the vertical coordinate of the second original pixel point is the same as the vertical coordinate of the first original pixel point, and the first value is the horizontal coordinate of the first original pixel point plus 1. The horizontal coordinate of the third original pixel point is the same as the horizontal coordinate of the first original pixel point, the vertical coordinate of the third original pixel point is the smaller value of the height of the original image and the second value, and the second value is the vertical coordinate of the first original pixel point plus 1. The horizontal coordinate of the fourth original pixel point is the same as the horizontal coordinate of the second original pixel point, and the vertical coordinate of the fourth original pixel point is the same as the vertical coordinate of the third original pixel point.

[0082] Assume that the coordinates of the pixel to be processed are (X dst , Y dst ), X dst Represents the horizontal coordinate of the pixel to be processed, Y dst Represents the vertical coordinate of the pixel to be processed, then:

[0083] The coordinates of the first original pixel are (X src , Y src );

[0084] The coordinates of the second original pixel are (MIN(Width src , Xsrc+1), Ysrc);

[0085] The coordinates of the third original pixel are (X src MIN(Height src , Y src +1);

[0086] The coordinates of the fourth original pixel are (MIN(Width src ,Xsrc+1),MIN(Height src , Y src +1);

[0087] Among them, X src Represents the horizontal coordinate of the first original pixel, Y dst Represents the vertical coordinate of the first original pixel point. MIN indicates taking the minimum value to prevent the coordinate from exceeding the original image size.

[0088] In some embodiments, based on the coordinates of the pixel to be processed, the horizontal scaling factor, the vertical scaling factor, and the displacement value, the coordinates of the original pixel corresponding to the pixel to be processed in the original image can be obtained by fixed-point operation. The method can be to shift the product of the horizontal coordinate of the pixel to be processed and the horizontal scaling factor right by the first digit to obtain the horizontal coordinate of the first original pixel corresponding to the pixel to be processed in the original image; and to shift the product of the vertical coordinate of the pixel to be processed and the vertical scaling factor right by the first digit to obtain the vertical coordinate of the first original pixel; wherein the first digit is determined based on the displacement value. For example, the first digit is twice the displacement value. After obtaining the horizontal and vertical coordinates of the first original pixel, the coordinates of the original pixel corresponding to the pixel to be processed in the original image can be obtained according to the horizontal and vertical coordinates of the first original pixel and the size of the original image according to the method described above.

[0089] When the original pixel points in the original image corresponding to the pixel point to be processed include the first original pixel point, the second original pixel point, the third original pixel point and the fourth original pixel point, based on the relationship between the coordinates of the four original pixel points introduced above, according to the horizontal coordinate and the vertical coordinate of the first original pixel point, and the size of the original image, the coordinates of the original pixel point corresponding to the pixel point to be processed in the original image can be obtained by determining the smaller value of the width value of the original image and the first value as the horizontal coordinate of the second original pixel point, and determining the vertical coordinate of the first original pixel point as the vertical coordinate of the second original pixel point, where the first value is the horizontal coordinate of the first original pixel point plus 1; and determining the vertical coordinate of the first original pixel point as the vertical coordinate of the second original pixel point. The horizontal coordinate of the starting pixel point is determined as the horizontal coordinate of the third original pixel point, and the smaller value of the height value of the original image and the second value is determined as the vertical coordinate of the third original pixel point, and the second value is the vertical coordinate of the first original pixel point plus 1; the horizontal coordinate of the second original pixel point is determined as the horizontal coordinate of the fourth original pixel point, and the vertical coordinate of the third original pixel point is determined as the vertical coordinate of the fourth original pixel point; based on the horizontal coordinate and vertical coordinate of the first original pixel point, the horizontal coordinate and vertical coordinate of the second original pixel point, the horizontal coordinate and vertical coordinate of the third original pixel point, and the horizontal coordinate and vertical coordinate of the fourth original pixel point, the coordinates of the original pixel point corresponding to the pixel point to be processed in the original image are constructed.

[0090] Right now,

[0091] The horizontal coordinate X of the first original pixel src =(X dst ×Wratio)>>(2×SHIFT_BIT);

[0092] The vertical coordinate Y of the first original pixel src =(Y dst ×Hratio)>>(2×SHIFT_BIT);

[0093] Among them, >> represents the right shift operation.

[0094] In the embodiments of the present application, the interpolation coefficients are expressed in the form of fixed-point numbers and are therefore referred to as fixed-point interpolation coefficients. The fixed-point interpolation coefficients include: horizontal fixed-point interpolation coefficients and vertical fixed-point interpolation coefficients. The horizontal fixed-point interpolation coefficients refer to the interpolation coefficients in the width direction, and are denoted as u here. The vertical fixed-point interpolation coefficients refer to the interpolation coefficients in the height direction, and are denoted as v here.

[0095] In some embodiments, after obtaining the horizontal and vertical coordinates of the first original pixel point, the method for determining the fixed-point interpolation coefficient in integer form can be to obtain the fixed-point interpolation coefficient based on the horizontal and vertical coordinates of the first original pixel point, the horizontal and vertical coordinates of the pixel point to be processed, the horizontal scaling coefficient, the vertical scaling coefficient and the displacement value.

[0096] In some embodiments, the fixed-point interpolation coefficients may include horizontal fixed-point interpolation coefficients and vertical fixed-point interpolation coefficients. In this case, the fixed-point interpolation coefficients in integer form may be determined by multiplying the horizontal coordinate of the pixel to be processed by the horizontal scaling coefficient, minus the value obtained by shifting the horizontal coordinate of the first original pixel to the left by the first digit, to obtain a first difference, and right-shifting the first difference by the second digit to obtain the horizontal fixed-point interpolation coefficient; multiplying the vertical coordinate of the pixel to be processed by the vertical scaling coefficient, minus the value obtained by shifting the vertical coordinate of the first original pixel to the left by the first digit, to obtain a second difference, and right-shifting the second difference by the second digit to obtain the vertical fixed-point interpolation coefficient; wherein the first digit and the second digit are determined according to the displacement value. For example, the first digit is twice the displacement value, and the second digit is equal to the displacement value.

[0097] Right now,

[0098] The horizontal fixed-point interpolation coefficient u=(X dst ×Wratio-(X src <<2×SHIFT_BIT))>>SHIFT_BIT;

[0099] The vertical fixed-point interpolation coefficient v=(Y dst ×Hratio-(Y src <<2×SHIFT_BIT))>>SHIFT_BIT.

[0100] In the above embodiments, in the process of calculating the coordinates of at least one original pixel point and the fixed-point interpolation coefficient, a scaling factor is used. The scaling factor is determined by the width and height dimensions of the original image and the target image and is not fixed. The technical solution provided by the above embodiments adopts a unified calculation method for different scaling factors, and the project maintainability is high.

[0101] Step 430 : Obtain the pixel value of the pixel to be processed by fixed-point calculation according to the pixel value of the original pixel, the fixed-point interpolation coefficient and the displacement value.

[0102] In some embodiments, this step includes the following sub-steps:

[0103] 1. Multiply the difference between the horizontal fixed-point interpolation coefficient and the result of 1 shifted left by the second digit by the first saturation operation result to obtain a first intermediate value; wherein the first saturation operation result is obtained by performing a saturation operation on the first calculated value, and the first calculated value is obtained by multiplying the difference between the vertical fixed-point interpolation coefficient and the result of 1 shifted left by the second digit by the pixel value of the first original pixel and shifted right by the second digit by the first saturation operation result;

[0104] The second digit is determined according to the displacement value. Exemplarily, the second digit is equal to the displacement value.

[0105] First intermediate value = (1 < <SHIFT_BIT-u)×SAT{(1<<SHIFT_BIT-v)×F 00 >>SHIFT_BIT)}. SAT stands for saturation operation, that is, when the operation result is greater than an upper limit or less than a lower limit, the result is equal to the upper limit or lower limit. 00 Represents the pixel value of the first original pixel.

[0106] 2. Multiply the horizontal fixed-point interpolation coefficient by the second saturation operation result to obtain a second intermediate value; wherein the second saturation operation result is obtained by saturating the second calculated value, and the second calculated value is the difference between 1 shifted left by the second digit and the vertical fixed-point interpolation coefficient, multiplied by the pixel value of the second original pixel and shifted right by the second digit;

[0107] Second intermediate value = u × SAT {((1 < <SHIFT_BIT-v)×F 10 )>>SHIFT_BIT}. Among them, F 10 Represents the pixel value of the second original pixel.

[0108] 3. Multiply the difference between the horizontal fixed-point interpolation coefficient and the result of the third saturation operation by the result of the third saturation operation to obtain a third intermediate value; wherein the result of the third saturation operation is obtained by saturating the third calculated value, and the third calculated value is obtained by right-shifting the product of the vertical fixed-point interpolation coefficient and the pixel value of the third original pixel by the second number of digits;

[0109] The third intermediate value = (1 < <SHIFT_BIT-u)×SAT{(v×F 01 )>>SHIFT_BIT}. Among them, F 01 Represents the pixel value of the third original pixel.

[0110] 4. Multiplying the horizontal fixed-point interpolation coefficient by the result of the fourth saturation operation to obtain a fourth intermediate value; wherein the result of the fourth saturation operation is obtained by performing a saturation operation on the fourth calculated value, and the fourth calculated value is obtained by right-shifting the product of the vertical fixed-point interpolation coefficient and the pixel value of the fourth original pixel by two digits;

[0111] Fourth intermediate value = u × SAT {(v × F 11 )>>SHIFT_BIT}. Among them, F 11 Represents the pixel value of the fourth original pixel.

[0112] 5. Obtain the pixel value of the pixel to be processed based on the first intermediate value, the second intermediate value, the third intermediate value and the fourth intermediate value.

[0113] Exemplarily, the first intermediate value, the second intermediate value, the third intermediate value and the fourth intermediate value are added to obtain a sum result, and a saturation operation is performed on the value obtained by right-shifting the sum result by the second digit to obtain the pixel value of the pixel to be processed.

[0114] That is, the summation result F tmp =(1< <SHIFT_BIT-u)×SAT(1<<SHIFT_BIT-v)×F 00 >>SHIFT_BIT)}+(1< <SHIFT_BIT-u)×SAT{(v×F 01 )>>SHIFT_BIT}+u×SAT{((1< <SHIFT_BIT-v)×F 10 )>>SHIFT_BI T}+u×SAT{(v×F 11 )>>SHIFT_BIT}.

[0115] The pixel value F of the pixel to be processed dst =SAT{F tmp >>SHIFT_BIT}.

[0116] The image scaling method provided in the above embodiment mainly uses operations such as multiplication and addition, shift, and saturation operations throughout the entire process. These operations can be very conveniently accelerated in parallel using SIMD (Single Instruction Multiple Data), thereby increasing computing efficiency while reducing device power consumption.

[0117] It should be noted that the number of bits in the above saturation operation is related to the value of the displacement value. In some embodiments, the displacement value is an integer in the interval [7, 11]. For example, when the displacement value is 7, 8-bit saturation operation is used, that is, the upper limit of the saturation operation result is 255 and the lower limit is 0; when the displacement value is greater than 7, 16-bit saturation operation is used, that is, the upper limit of the saturation operation result is 65535 and the lower limit is 0.

[0118] Furthermore, the selection of the displacement value can be considered in a comprehensive manner, taking into account both computational efficiency and accuracy requirements. Larger displacement values ​​improve accuracy, but also reduce computational efficiency; smaller displacement values ​​increase efficiency, but also reduce accuracy. When the displacement value is 7, the computational process in the above image scaling method can be implemented using 8×8 MACs (multiplier-accumulators); when the displacement value is between 8 and 11, the computational process in the above image scaling method requires 16×16 MACs.

[0119] Step 440 : obtaining a target image after scaling the original image based on the pixel value of each pixel to be processed in the target image.

[0120] For each pixel to be processed in the target image, the pixel value of the pixel to be processed can be calculated using the method provided in steps 420 to 430. After the pixel value of each pixel to be processed in the target image is calculated, the target image after scaling the original image is obtained.

[0121] The technical solution provided by the embodiment of the present application is that when it is necessary to scale the original image to obtain a target image that meets the size requirements, the horizontal scaling coefficient and the vertical scaling coefficient in integer form can be obtained through fixed-point operations based on the size of the original image, the size of the target image, and the displacement value in integer form set in advance. Then, for each pixel to be processed in the target image, the coordinates of the original pixel corresponding to the pixel to be processed in the original image, as well as the fixed-point interpolation coefficient in integer form are obtained through fixed-point operations based on the coordinates of the pixel to be processed, the horizontal scaling coefficient, the vertical scaling coefficient, and the displacement value. Then, based on the pixel value of the original pixel, the fixed-point interpolation coefficient, and the displacement value, the pixel value of the pixel to be processed is obtained through fixed-point operations. In the above process, a scaling coefficient in integer form is obtained through calculation, and then a fixed-point interpolation coefficient in integer form is calculated based on the scaling coefficient in integer form, and the pixel value of the pixel point to be processed is calculated based on the fixed-point interpolation coefficient in integer form. Then, based on the pixel value of each pixel point to be processed in the target image, the target image after scaling the original image is obtained. Therefore, during the entire image scaling process, fixed-point operations are performed using data in integer form, floating-point operations are avoided, thereby reducing the amount of operations and improving operation efficiency.

[0122] Because of this, this solution can be used in embedded devices that have high power consumption requirements and do not support floating-point operations, and the software portability is high.

[0123] In the above embodiment, horizontal and vertical interpolation is performed on the four original pixels simultaneously (i.e., a single interpolation operation is performed on the four original pixels) to obtain the pixel value of the pixel to be processed. In some other embodiments, the interpolation operation can also be performed in two steps, i.e., the original pixels are first interpolated in a certain direction to obtain the pixel value of the intermediate pixel, and then the intermediate pixel is interpolated in another direction to obtain the pixel value of the pixel to be processed.

[0124] In some embodiments, taking the horizontal interpolation followed by the vertical interpolation as an example, the pixel value of the pixel to be processed is obtained by the following method:

[0125] 1. Determine the sum of the fifth saturation operation result and the sixth saturation operation result as the pixel value of the first intermediate pixel; wherein the fifth saturation operation result is obtained by performing a saturation operation on the fifth calculated value, the fifth calculated value being the difference between 1 shifted left by the second digit and the horizontal fixed-point interpolation coefficient, multiplied by the pixel value of the first original pixel, and then right-shifted by the second digit; and the sixth saturation operation result is obtained by performing a saturation operation on the sixth calculated value, the sixth calculated value being the difference between the horizontal fixed-point interpolation coefficient and the pixel value of the second original pixel, and then right-shifted by the second digit;

[0126] That is, the pixel value of the first intermediate pixel R0=SAT{(1< <SHIFT_BIT-u)×F 00 >>SHIFT_BIT)}+SAT{(u×F 10 )>>SHIFT_BIT. The first intermediate pixel point is a pixel point obtained by performing horizontal interpolation on the first original pixel point and the second original pixel point.

[0127] 2. Determine the sum of the seventh saturation operation result and the eighth saturation operation result as the pixel value of the second intermediate pixel; wherein the seventh saturation operation result is obtained by performing a saturation operation on the seventh calculated value, where the seventh calculated value is the difference between 1 shifted left by two digits and the horizontal fixed-point interpolation coefficient, multiplied by the pixel value of the third original pixel, and then right-shifted by two digits; and the eighth saturation operation result is obtained by performing a saturation operation on the eighth calculated value, where the eighth calculated value is the difference between the horizontal fixed-point interpolation coefficient and the pixel value of the fourth original pixel, multiplied by two digits;

[0128] That is, the pixel value of the second middle pixel point R1=SAT{(1< <SHIFT_BIT-u)×F 01 >>SHIFT_BIT)}+SAT{(u×F 11 )>>SHIFT_BIT}. The second intermediate pixel point is a pixel point obtained by performing horizontal interpolation on the third original pixel point and the fourth original pixel point.

[0129] 3. Perform a saturation operation on the value obtained by right-shifting the sum of the first product result and the second product result by the second digit to obtain the pixel value of the pixel to be processed; wherein the first product result is the difference between 1 shifted left by the second digit and the vertical fixed-point interpolation coefficient, multiplied by the pixel value of the first intermediate pixel; the second product result is the vertical fixed-point interpolation coefficient multiplied by the pixel value of the second intermediate pixel.

[0130] That is, the sum of the first product result and the second product result F tmp =(1< <SHIFT_BIT-v)×R0+v×R1。

[0131] The pixel value F of the pixel to be processed dst =SAT{F tmp >>SHIFT_BIT}.

[0132] In this embodiment, the pixel value of the pixel to be processed is obtained by first interpolating horizontally and then vertically.

[0133] In some embodiments, taking the vertical interpolation followed by the horizontal interpolation as an example, the pixel value of the pixel to be processed is obtained by the following method:

[0134] 1. Determine the sum of the ninth saturation operation result and the tenth saturation operation result as the pixel value of the third intermediate pixel; wherein the ninth saturation operation result is obtained by performing a saturation operation on the ninth calculated value, the ninth calculated value being the difference between 1 shifted left by two digits and the vertical fixed-point interpolation coefficient, multiplied by the pixel value of the first original pixel, and then right-shifted by two digits; and the tenth saturation operation result is obtained by performing a saturation operation on the tenth calculated value, the tenth calculated value being the difference between the vertical fixed-point interpolation coefficient and the pixel value of the third original pixel, and then right-shifted by two digits;

[0135] That is, the pixel value of the third middle pixel L0=SAT{(1< <SHIFT_BIT-v)×F 00 >>SHIFT_BIT)}+SAT{(v×F 01 )>>SHIFT_BIT. The third intermediate pixel point is a pixel point obtained by performing longitudinal interpolation on the first original pixel point and the third original pixel point.

[0136] 2. Determine the sum of the eleventh saturation operation result and the twelfth saturation operation result as the pixel value of the fourth intermediate pixel; wherein the eleventh saturation operation result is obtained by performing a saturation operation on the eleventh calculated value, where the eleventh calculated value is the difference between 1 shifted left by two digits and the vertical fixed-point interpolation coefficient, multiplied by the pixel value of the second original pixel, and then right-shifted by two digits; and the twelfth saturation operation result is obtained by performing a saturation operation on the twelfth calculated value, where the twelfth calculated value is the difference between the vertical fixed-point interpolation coefficient and the pixel value of the fourth original pixel, multiplied by the vertical fixed-point interpolation coefficient, and then right-shifted by two digits;

[0137] That is, the pixel value of the fourth middle pixel L1=SAT{(1< <SHIFT_BIT-v)×F 10 >>SHIFT_BIT)}+SAT{(v×F 11 )>>SHIFT_BIT}. The fourth intermediate pixel point is a pixel point obtained by performing longitudinal interpolation on the second original pixel point and the fourth original pixel point.

[0138] 3. Perform a saturation operation on the value obtained by right-shifting the sum of the third product result and the fourth product result by the second digit to obtain the pixel value of the pixel to be processed; wherein the third product result is the difference between 1 shifted left by the second digit and the horizontal fixed-point interpolation coefficient, multiplied by the pixel value of the third intermediate pixel; the fourth product result is the horizontal fixed-point interpolation coefficient multiplied by the pixel value of the fourth intermediate pixel.

[0139] That is, the sum of the third product result and the fourth product result F tmp =(1< <SHIFT_BIT-u)×L0+u×L1。

[0140] The pixel value F of the pixel to be processed dst =SAT{F tmp >>SHIFT_BIT}.

[0141] In this embodiment, the pixel value of the pixel to be processed is obtained by first interpolating vertically and then horizontally.

[0142] For the scheme of first horizontal interpolation and then vertical interpolation, after the horizontal interpolation calculation, the horizontal interpolation result (i.e., the pixel values ​​of the first middle pixel point and the second middle pixel point) can be stored first, and then the vertical interpolation calculation can be performed to obtain the pixel value of the pixel point to be processed. This can avoid repeated calculation of horizontal interpolation and reduce the amount of calculation.

[0143] Similarly, for the scheme of first vertical interpolation and then horizontal interpolation, after the vertical interpolation calculation, the vertical interpolation result (i.e., the pixel values ​​of the third middle pixel point and the fourth middle pixel point) can be stored first, and then the horizontal interpolation calculation can be performed to obtain the pixel value of the pixel point to be processed. This can avoid repeated calculation of the vertical interpolation and reduce the amount of calculation.

[0144] In practical applications, you can choose to perform simultaneous horizontal and vertical interpolation, horizontal interpolation first and vertical interpolation second, or vertical interpolation first and horizontal interpolation second, depending on the actual situation. The advantage of simultaneous horizontal and vertical interpolation is that it does not require additional memory allocation, which can avoid the latency and power consumption caused by memory read and write operations. The advantages of performing horizontal interpolation first and vertical interpolation second, or vertical interpolation first and horizontal interpolation second, are that they can avoid some repeated interpolation operations, but they require additional memory allocation to store the interpolation results. Therefore, in practical applications, you can weigh the pros and cons and choose the appropriate method for image scaling. For example, when the size of the original image is larger than the size of the target image, simultaneous horizontal and vertical interpolation is preferred. When the size of the original image is smaller than the size of the target image, it is preferred to perform horizontal interpolation first and vertical interpolation second to avoid repeated horizontal linear interpolation calculations, or to perform vertical interpolation first and horizontal interpolation second to avoid repeated vertical linear interpolation calculations.

[0145] The following are device embodiments of the present application, which can be used to implement the method embodiments of the present application. For details not disclosed in the device embodiments of the present application, please refer to the method embodiments of the present application.

[0146] Please refer to Figure 5, which shows a block diagram of an image scaling device provided by one embodiment of the present application. This device has the function of implementing the above-mentioned image scaling method. The function can be implemented by hardware or by hardware executing corresponding software. The device can be a computer device or can be installed in a computer device. The device 500 may include: a scaling coefficient determination module 510, an interpolation coefficient determination module 520, a pixel value determination module 530, and an image generation module 540.

[0147] The scaling factor determination module 510 is configured to obtain an integer-form horizontal scaling factor and an integer-form vertical scaling factor through fixed-point operations according to the size of the original image, the size of the target image, and the integer-form displacement value.

[0148] The interpolation coefficient determination module 520 is used to obtain, for each pixel to be processed in the target image, the coordinates of the original pixel point corresponding to the pixel to be processed in the original image and the fixed-point interpolation coefficient in integer form through fixed-point calculation based on the coordinates of the pixel point to be processed, the horizontal scaling coefficient, the vertical scaling coefficient and the displacement value.

[0149] The pixel value determination module 530 is configured to obtain the pixel value of the pixel to be processed by fixed-point calculation according to the pixel value of the original pixel, the fixed-point interpolation coefficient and the displacement value.

[0150] The image generation module 540 is configured to obtain the target image after scaling the original image based on the pixel value of each pixel to be processed in the target image.

[0151] In some embodiments, the fixed-point operation includes integer division, the dimensions are width and height dimensions, and the width and height dimensions include width value and height value. The scaling coefficient determination module 510 includes: a horizontal coefficient determination submodule and a vertical coefficient determination submodule.

[0152] The horizontal coefficient determination submodule is used to shift the width value of the original image to the left by the first digit using integer division, and then divide it by the width value of the target image to obtain the quotient as the horizontal scaling coefficient; wherein the first digit is determined according to the displacement value.

[0153] The vertical coefficient determination submodule is configured to use integer division to shift the height value of the original image left by the first digit, and then divide the result by the height value of the target image to obtain the quotient as the vertical scaling coefficient.

[0154] In some embodiments, the interpolation coefficient determination module 520 includes: a horizontal coordinate determination submodule, a vertical coordinate determination submodule, a coordinate determination submodule, and an interpolation coefficient determination submodule.

[0155] A horizontal coordinate determination submodule is used to right-shift the product of the horizontal coordinate of the pixel point to be processed and the horizontal scaling coefficient by a first digit to obtain the horizontal coordinate of the first original pixel point in the original image corresponding to the pixel point to be processed; wherein the first digit is determined based on the displacement value.

[0156] The vertical coordinate determining submodule is configured to right-shift the product of the vertical coordinate of the pixel point to be processed and the vertical scaling coefficient by the first digit to obtain the vertical coordinate of the first original pixel point.

[0157] The coordinate determination submodule is used to obtain the coordinates of the original pixel point corresponding to the pixel point to be processed in the original image according to the horizontal coordinate and the vertical coordinate of the first original pixel point and the size of the original image.

[0158] The interpolation coefficient determination submodule is used to obtain the fixed-point interpolation coefficient according to the horizontal coordinate and vertical coordinate of the first original pixel point, the horizontal coordinate and vertical coordinate of the pixel point to be processed, the horizontal scaling coefficient, the vertical scaling coefficient and the displacement value.

[0159] In some embodiments, the size is width and height dimensions, which include width and height values, and the original pixel points in the original image corresponding to the pixel points to be processed include the first original pixel point, the second original pixel point, the third original pixel point and the fourth original pixel point.

[0160] The coordinate determination submodule is specifically used for:

[0161] Determine the smaller value between the width of the original image and the first value as the horizontal coordinate of the second original pixel point, determine the vertical coordinate of the first original pixel point as the vertical coordinate of the second original pixel point, and the first value is the horizontal coordinate of the first original pixel point plus 1;

[0162] Determine the abscissa of the first original pixel as the abscissa of the third original pixel, and determine the smaller of the height value of the original image and a second value as the ordinate of the third original pixel, where the second value is the ordinate of the first original pixel plus 1;

[0163] Determine the horizontal coordinate of the second original pixel point as the horizontal coordinate of the fourth original pixel point, and determine the vertical coordinate of the third original pixel point as the vertical coordinate of the fourth original pixel point;

[0164] Based on the horizontal coordinate and vertical coordinate of the first original pixel point, the horizontal coordinate and vertical coordinate of the second original pixel point, the horizontal coordinate and vertical coordinate of the third original pixel point, and the horizontal coordinate and vertical coordinate of the fourth original pixel point, the coordinates of the original pixel point corresponding to the pixel point to be processed in the original image are constructed.

[0165] In some embodiments, the fixed-point interpolation coefficients include: horizontal fixed-point interpolation coefficients and vertical fixed-point interpolation coefficients. The interpolation coefficient determination submodule is configured to: multiply the horizontal coordinate of the pixel to be processed by the horizontal scaling coefficient, minus the value obtained by shifting the horizontal coordinate of the first original pixel left by the first digit, to obtain a first difference, and right-shift the first difference by the second digit to obtain the horizontal fixed-point interpolation coefficient; wherein the first digit and the second digit are determined based on the displacement value;

[0166] The value obtained by multiplying the vertical coordinate of the pixel point to be processed by the vertical scaling coefficient is subtracted from the value obtained by shifting the vertical coordinate of the first original pixel point left by the first digit to obtain a second difference, and the second difference is shifted right by the second digit to obtain the vertical fixed-point interpolation coefficient.

[0167] In some embodiments, the pixel value determination module 530 includes: a first intermediate value determination submodule, a second intermediate value determination submodule, a third intermediate value determination submodule, a fourth intermediate value determination submodule and a pixel value determination submodule.

[0168] A first intermediate value determination submodule is configured to multiply the difference between 1 shifted left by the second digit and the horizontal fixed-point interpolation coefficient by a first saturation operation result to obtain a first intermediate value; wherein the first saturation operation result is obtained by performing a saturation operation on a first calculated value, and the first calculated value is obtained by multiplying the difference between 1 shifted left by the second digit and the vertical fixed-point interpolation coefficient by the pixel value of the first original pixel point and shifting right by the second digit; the second digit is determined based on the displacement value.

[0169] A second intermediate value determination submodule is configured to multiply the horizontal fixed-point interpolation coefficient by a second saturation operation result to obtain a second intermediate value; wherein the second saturation operation result is obtained by performing a saturation operation on a second calculated value, and the second calculated value is the difference between 1 shifted left by the second bit number and the vertical fixed-point interpolation coefficient, multiplied by the pixel value of the second original pixel point and then shifted right by the second bit number.

[0170] A third intermediate value determination submodule is configured to multiply the difference between 1 shifted left by the second bit and the horizontal fixed-point interpolation coefficient by a third saturation operation result to obtain a third intermediate value; wherein the third saturation operation result is obtained by performing a saturation operation on a third calculated value, and the third calculated value is obtained by right-shifting the product of the vertical fixed-point interpolation coefficient and the pixel value of the third original pixel point by the second bit.

[0171] A fourth intermediate value determination submodule is used to multiply the horizontal fixed-point interpolation coefficient by a fourth saturation operation result to obtain a fourth intermediate value; wherein the fourth saturation operation result is obtained by performing a saturation operation on a fourth calculated value, and the fourth calculated value is obtained by right-shifting the product of the vertical fixed-point interpolation coefficient and the pixel value of the fourth original pixel point by the second digit.

[0172] The pixel value determination submodule is used to obtain the pixel value of the pixel to be processed according to the first intermediate value, the second intermediate value, the third intermediate value and the fourth intermediate value.

[0173] In some embodiments, the pixel value determination submodule is used to add the first intermediate value, the second intermediate value, the third intermediate value and the fourth intermediate value to obtain a sum result, perform a saturation operation on the value obtained by right shifting the sum result by the second bit number, and obtain the pixel value of the pixel point to be processed.

[0174] In some embodiments, the pixel value determination module 530 includes: a first determination submodule, a second determination submodule, and a saturation operation submodule.

[0175] The first determination submodule is used to determine the sum of the fifth saturation operation result and the sixth saturation operation result as the pixel value of the first intermediate pixel point; wherein, the fifth saturation operation result is obtained by performing a saturation operation on the fifth calculated value, and the fifth calculated value is obtained by multiplying the difference between 1 shifted left by the second digit and the horizontal fixed-point interpolation coefficient and shifting the pixel value of the first original pixel point right by the second digit; the sixth saturation operation result is obtained by performing a saturation operation on the sixth calculated value, and the sixth calculated value is obtained by multiplying the horizontal fixed-point interpolation coefficient by the pixel value of the second original pixel point and shifting the pixel value right by the second digit.

[0176] The second determination submodule is used to determine the sum of the seventh saturation operation result and the eighth saturation operation result as the pixel value of the second intermediate pixel point; wherein, the seventh saturation operation result is obtained by performing a saturation operation on the seventh calculated value, and the seventh calculated value is obtained by multiplying the difference between 1 shifted left by the second digit and the horizontal fixed-point interpolation coefficient and shifting the second digit right after multiplying it by the pixel value of the third original pixel point; the eighth saturation operation result is obtained by performing a saturation operation on the eighth calculated value, and the eighth calculated value is obtained by multiplying the horizontal fixed-point interpolation coefficient by the pixel value of the fourth original pixel point and shifting the second digit right after.

[0177] A saturation operation submodule is used to perform a saturation operation on the value obtained by right-shifting the sum of the first product result and the second product result by the second bit number to obtain the pixel value of the pixel point to be processed; wherein, the first product result is obtained by multiplying the difference between 1 shifted left by the second bit number and the vertical fixed-point interpolation coefficient by the pixel value of the first intermediate pixel point; the second product result is obtained by multiplying the vertical fixed-point interpolation coefficient by the pixel value of the second intermediate pixel point.

[0178] In some embodiments, the pixel value determination module 530 includes: a third determination submodule, a fourth determination submodule, and a saturation operation submodule.

[0179] The third determination submodule is used to determine the sum of the ninth saturation operation result and the tenth saturation operation result as the pixel value of the third intermediate pixel point; wherein, the ninth saturation operation result is obtained by performing a saturation operation on the ninth calculated value, and the ninth calculated value is obtained by multiplying the difference between 1 shifted left by the second digit and the vertical fixed-point interpolation coefficient and shifting the pixel value of the first original pixel point right by the second digit; the tenth saturation operation result is obtained by performing a saturation operation on the tenth calculated value, and the tenth calculated value is obtained by multiplying the vertical fixed-point interpolation coefficient by the pixel value of the third original pixel point and shifting the pixel value right by the second digit.

[0180] The fourth determination submodule is used to determine the sum of the eleventh saturation operation result and the twelfth saturation operation result as the pixel value of the fourth intermediate pixel point; wherein the eleventh saturation operation result is obtained by performing a saturation operation on the eleventh calculated value, and the eleventh calculated value is obtained by multiplying the difference between 1 shifted left by the second digit and the vertical fixed-point interpolation coefficient and shifting the pixel value of the second original pixel point right by the second digit; the twelfth saturation operation result is obtained by performing a saturation operation on the twelfth calculated value, and the twelfth calculated value is obtained by multiplying the vertical fixed-point interpolation coefficient by the pixel value of the fourth original pixel point and shifting the pixel value right by the second digit.

[0181] The saturation operation submodule is used to perform a saturation operation on the value obtained by right-shifting the sum of the third product result and the fourth product result by the second bit, so as to obtain the pixel value of the pixel point to be processed; wherein, the third product result is obtained by multiplying the difference between 1 shifted left by the second bit and the horizontal fixed-point interpolation coefficient by the pixel value of the third intermediate pixel point; and the fourth product result is obtained by multiplying the horizontal fixed-point interpolation coefficient by the pixel value of the fourth intermediate pixel point.

[0182] In some embodiments, the displacement value is an integer in the interval [7, 11].

[0183] It should be noted that the apparatus provided in the above embodiments, when implementing its functions, is only illustrated by the division of the above functional modules. In actual applications, the above functions can be assigned to different functional modules as needed, that is, the internal structure of the device can be divided into different functional modules to complete all or part of the functions described above. In addition, the apparatus and method embodiments provided in the above embodiments are based on the same concept. The specific implementation process is detailed in the method embodiment and will not be repeated here.

[0184] Please refer to FIG6 , which shows a structural block diagram of a computer device 600 provided in one embodiment of the present application.

[0185] Typically, the computer device 600 includes a processor 601 and a memory 602 .

[0186] The processor 601 may include one or more processing cores, such as a 4-core processor, an 8-core processor, and the like. The processor 601 may be implemented in at least one hardware form of DSP (Digital Signal Processing), FPGA (Field Programmable Gate Array), or PLA (Programmable Logic Array). The processor 601 may also include a main processor and a coprocessor. The main processor is a processor for processing data in an awake state, also known as a CPU (Central Processing Unit); the coprocessor is a low-power processor for processing data in a standby state. In some embodiments, the processor 601 may be integrated with a GPU (Graphics Processing Unit), which is responsible for rendering and drawing the content to be displayed on the display screen. In some embodiments, the processor 601 may also include an AI processor for processing computing operations related to machine learning.

[0187] Memory 602 may include one or more computer-readable storage media, which may be non-transitory. Memory 602 may also include high-speed random access memory and non-volatile memory, such as one or more magnetic disk storage devices or flash memory storage devices. In some embodiments, the non-transitory computer-readable storage media in memory 602 is used to store a computer program configured to be executed by one or more processors to implement the above-described image scaling method.

[0188] Those skilled in the art will appreciate that the structure shown in FIG. 6 does not limit the computer device 600 , and may include more or fewer components than shown, or combine certain components, or adopt a different component arrangement.

[0189] In some embodiments, a computer-readable storage medium is further provided, wherein a computer program is stored in the storage medium. The computer program is loaded and executed by a processor to implement the above-mentioned image scaling method.

[0190] Optionally, the computer-readable storage medium may include: ROM (Read-Only Memory), RAM (Random-Access Memory), SSD (Solid State Drives), or an optical disk, etc. Among them, the random access memory may include ReRAM (Resistance Random Access Memory) and DRAM (Dynamic Random Access Memory).

[0191] In some embodiments, a computer program product is further provided, comprising a computer program stored in a computer-readable storage medium, and a processor reads and executes the computer program from the computer-readable storage medium to implement the above-mentioned image scaling method.

[0192] In this application, the facial (or other biometric) recognition technology involved, when the above embodiments of this application are applied to specific products or technologies, the relevant data collection, use and processing processes should comply with national laws and regulations. Before collecting facial (or other biometric) information, the information processing rules should be informed and the target object’s separate consent (or legal basis) should be obtained. The facial (or other biometric) information should be processed strictly in accordance with the requirements of laws and regulations and the personal information processing rules, and technical measures should be taken to ensure the security of relevant data.

[0193] It should be understood that the "multiple" mentioned in this article refers to two or more. "And / or" describes the association relationship of associated objects, indicating that three relationships may exist. For example, A and / or B can represent three situations: A exists alone, A and B exist at the same time, and B exists alone. The character " / " generally indicates that the previous and subsequent associated objects are in an "or" relationship. In addition, the step numbers described in this article only illustrate a possible execution sequence between the steps. In some other embodiments, the above steps may not be executed in the order of the numbers, such as two steps with different numbers are executed at the same time, or two steps with different numbers are executed in the opposite order to the diagram. The embodiments of the present application do not limit this.

[0194] The above description is merely an exemplary embodiment of the present application and is not intended to limit the present application. Any modifications, equivalent substitutions, improvements, etc. made within the spirit and principles of the present application shall be included in the scope of protection of the present application.

Claims

1. An image scaling method, the method being executed by a computer device, the method comprising: According to the size of the original image, the size of the target image and the displacement value in integer form, a horizontal scaling factor and a vertical scaling factor in integer form are obtained through fixed-point operation; For each pixel to be processed in the target image, according to the coordinates of the pixel to be processed, the horizontal scaling factor, the vertical scaling factor and the displacement value, obtain the coordinates of the original pixel corresponding to the pixel to be processed in the original image and the fixed-point interpolation coefficient in integer form through fixed-point operation; Obtaining the pixel value of the pixel to be processed by fixed-point operation according to the pixel value of the original pixel, the fixed-point interpolation coefficient and the displacement value; Based on the pixel values ​​of each of the to-be-processed pixels in the target image, the target image is obtained after scaling the original image.

2. The method according to claim 1, wherein the fixed-point operation includes an integer division mode, the size is a width and a height size, and the width and the height size include a width value and a height value, and the fixed-point operation is used to obtain an integer horizontal scaling factor and a vertical scaling factor according to the size of the original image, the size of the target image and the displacement value in integer form, including: After shifting the width value of the original image to the left by the first digit using integer division, the resultant is divided by the width value of the target image, and the quotient obtained is used as the horizontal scaling factor; wherein the first digit is determined according to the displacement value; The height value of the original image is shifted left by the first digit using integer division, and then divided by the height value of the target image, and the obtained quotient is used as the vertical scaling factor.

3. The method according to claim 1, wherein the coordinates of the original pixel points corresponding to the pixel points to be processed in the original image and the fixed-point interpolation coefficients in integer form are obtained by fixed-point operation according to the coordinates of the pixel points to be processed, the horizontal scaling coefficient, the vertical scaling coefficient and the displacement value, comprising: Shifting the product of the horizontal coordinate of the pixel to be processed and the horizontal scaling coefficient rightward by a first digit to obtain the horizontal coordinate of the first original pixel in the original image corresponding to the pixel to be processed; wherein the first digit is determined according to the displacement value; Shifting right the product of the vertical coordinate of the pixel to be processed and the vertical scaling factor by the first digit to obtain the vertical coordinate of the first original pixel; Obtaining coordinates of an original pixel point in the original image corresponding to the pixel point to be processed according to the horizontal coordinate and the vertical coordinate of the first original pixel point and the size of the original image; The fixed-point interpolation coefficient is obtained according to the horizontal coordinate and the vertical coordinate of the first original pixel point, the horizontal coordinate and the vertical coordinate of the pixel point to be processed, the horizontal scaling coefficient, the vertical scaling coefficient and the displacement value.

4. The method according to claim 3, wherein the size is a width and height size, the width and height size includes a width value and a height value, and the original pixel points in the original image corresponding to the pixel point to be processed include the first original pixel point, the second original pixel point, the third original pixel point, and the fourth original pixel point; and obtaining the coordinates of the original pixel point in the original image corresponding to the pixel point to be processed according to the horizontal coordinate and the vertical coordinate of the first original pixel point and the size of the original image, comprises: Determine the smaller value between the width value of the original image and the first value as the horizontal coordinate of the second original pixel point, determine the vertical coordinate of the first original pixel point as the vertical coordinate of the second original pixel point, and the first value is the horizontal coordinate of the first original pixel point plus 1; Determine the horizontal coordinate of the first original pixel point as the horizontal coordinate of the third original pixel point, determine the smaller value of the height value of the original image and the second value as the vertical coordinate of the third original pixel point, and the second value is the vertical coordinate of the first original pixel point plus 1; Determine the horizontal coordinate of the second original pixel point as the horizontal coordinate of the fourth original pixel point, and determine the vertical coordinate of the third original pixel point as the vertical coordinate of the fourth original pixel point; Based on the horizontal coordinate and vertical coordinate of the first original pixel point, the horizontal coordinate and vertical coordinate of the second original pixel point, the horizontal coordinate and vertical coordinate of the third original pixel point, and the horizontal coordinate and vertical coordinate of the fourth original pixel point, the coordinates of the original pixel point in the original image corresponding to the pixel point to be processed are constructed.

5. The method according to claim 4, wherein the fixed-point interpolation coefficients include: Horizontal fixed-point interpolation coefficients and vertical fixed-point interpolation coefficients; The step of obtaining the pixel value of the pixel to be processed by fixed-point operation according to the pixel value of the original pixel, the fixed-point interpolation coefficient and the displacement value comprises: The first intermediate value is obtained by multiplying the difference between 1 shifted left by the second digit and the horizontal fixed-point interpolation coefficient by the first saturation operation result; wherein the first saturation operation result is obtained by performing a saturation operation on the first calculated value, and the first calculated value is obtained by multiplying the difference between 1 shifted left by the second digit and the vertical fixed-point interpolation coefficient by the pixel value of the first original pixel point and shifting right by the second digit; the second digit is determined according to the displacement value; The horizontal fixed-point interpolation coefficient is multiplied by a second saturation operation result to obtain a second intermediate value; wherein the second saturation operation result is obtained by performing a saturation operation on a second calculated value, and the second calculated value is obtained by multiplying the difference between 1 shifted left by the second digit and the vertical fixed-point interpolation coefficient by the pixel value of the second original pixel point and shifting right by the second digit; The difference between 1 shifted left by the second digit and the horizontal fixed-point interpolation coefficient is multiplied by the third saturation operation result to obtain a third intermediate value; wherein the third saturation operation result is obtained by performing a saturation operation on a third calculated value, and the third calculated value is obtained by right shifting the product of the vertical fixed-point interpolation coefficient and the pixel value of the third original pixel point by the second digit; Multiplying the horizontal fixed-point interpolation coefficient by a fourth saturation operation result to obtain a fourth intermediate value; wherein the fourth saturation operation result is obtained by performing a saturation operation on a fourth calculated value, and the fourth calculated value is obtained by right-shifting the product of the vertical fixed-point interpolation coefficient and the pixel value of the fourth original pixel point by the second digit; The pixel value of the pixel point to be processed is obtained according to the first intermediate value, the second intermediate value, the third intermediate value and the fourth intermediate value.

6. The method according to claim 5, wherein obtaining the pixel value of the pixel to be processed according to the first intermediate value, the second intermediate value, the third intermediate value and the fourth intermediate value comprises: Adding the first intermediate value, the second intermediate value, the third intermediate value, and the fourth intermediate value to obtain a sum result; A saturation operation is performed on a value obtained by right-shifting the sum result by the second bit to obtain a pixel value of the pixel to be processed.

7. The method according to claim 4, wherein the fixed-point interpolation coefficients include: Horizontal fixed-point interpolation coefficients and vertical fixed-point interpolation coefficients; The step of obtaining the pixel value of the pixel to be processed by fixed-point operation according to the pixel value of the original pixel, the fixed-point interpolation coefficient and the displacement value comprises: The sum of the fifth saturation operation result and the sixth saturation operation result is determined as the pixel value of the first intermediate pixel point; wherein the fifth saturation operation result is obtained by performing a saturation operation on the fifth calculated value, the fifth calculated value is obtained by multiplying the difference between 1 shifted left by the second digit and the horizontal fixed-point interpolation coefficient by the pixel value of the first original pixel point and then shifting right by the second digit; the sixth saturation operation result is obtained by performing a saturation operation on the sixth calculated value, the sixth calculated value is obtained by multiplying the horizontal fixed-point interpolation coefficient by the pixel value of the second original pixel point and then shifting right by the second digit; The sum of the seventh saturation operation result and the eighth saturation operation result is determined as the pixel value of the second intermediate pixel point; wherein the seventh saturation operation result is obtained by performing a saturation operation on the seventh calculated value, the seventh calculated value is obtained by multiplying the difference between 1 shifted left by the second digit and the horizontal fixed-point interpolation coefficient by the pixel value of the third original pixel point and then shifting right by the second digit; the eighth saturation operation result is obtained by performing a saturation operation on the eighth calculated value, the eighth calculated value is obtained by multiplying the horizontal fixed-point interpolation coefficient by the pixel value of the fourth original pixel point and then shifting right by the second digit; A saturation operation is performed on the value obtained by right-shifting the sum of the first product result and the second product result by the second bit number to obtain the pixel value of the pixel to be processed; wherein the first product result is obtained by multiplying the difference between 1 shifted left by the second bit number and the vertical fixed-point interpolation coefficient by the pixel value of the first intermediate pixel point; and the second product result is obtained by multiplying the vertical fixed-point interpolation coefficient by the pixel value of the second intermediate pixel point.

8. The method according to claim 4, wherein the fixed-point interpolation coefficients include: Horizontal fixed-point interpolation coefficients and vertical fixed-point interpolation coefficients; The step of obtaining the pixel value of the pixel to be processed by fixed-point operation according to the pixel value of the original pixel, the fixed-point interpolation coefficient and the displacement value comprises: The sum of the ninth saturation operation result and the tenth saturation operation result is determined as the pixel value of the third intermediate pixel point; wherein the ninth saturation operation result is obtained by performing a saturation operation on the ninth calculated value, the ninth calculated value is obtained by multiplying the difference between 1 shifted left by the second digit and the vertical fixed-point interpolation coefficient by the pixel value of the first original pixel point and then shifting right by the second digit; the tenth saturation operation result is obtained by performing a saturation operation on the tenth calculated value, the tenth calculated value is obtained by multiplying the vertical fixed-point interpolation coefficient by the pixel value of the third original pixel point and then shifting right by the second digit; The sum of the eleventh saturation operation result and the twelfth saturation operation result is determined as the pixel value of the fourth intermediate pixel point; wherein the eleventh saturation operation result is obtained by performing a saturation operation on the eleventh calculated value, and the eleventh calculated value is the difference between 1 shifted left by the second digit and the vertical fixed-point interpolation coefficient, multiplied by the pixel value of the second original pixel point and then shifted right by the second digit; the twelfth saturation operation result is the twelfth calculated value saturated The twelfth calculated value is obtained by multiplying the vertical fixed-point interpolation coefficient by the pixel value of the fourth original pixel point and then right-shifting by the second digit; A saturation operation is performed on the value obtained by right-shifting the sum of the third product result and the fourth product result by the second bit to obtain the pixel value of the pixel to be processed; wherein the third product result is obtained by multiplying the difference between 1 shifted left by the second bit and the horizontal fixed-point interpolation coefficient by the pixel value of the third intermediate pixel; and the fourth product result is obtained by multiplying the horizontal fixed-point interpolation coefficient by the pixel value of the fourth intermediate pixel.

9. The method according to claim 3, wherein the fixed-point interpolation coefficients include: Horizontal fixed-point interpolation coefficients and vertical fixed-point interpolation coefficients; The step of obtaining the fixed-point interpolation coefficient according to the horizontal coordinate and the vertical coordinate of the first original pixel point, the horizontal coordinate and the vertical coordinate of the pixel point to be processed, the horizontal scaling coefficient, the vertical scaling coefficient and the displacement value comprises: The value obtained by multiplying the horizontal coordinate of the pixel to be processed by the horizontal scaling coefficient is subtracted from the value obtained by shifting the horizontal coordinate of the first original pixel to the left by the first digit to obtain a first difference, and the first difference is shifted right by the second digit to obtain the horizontal fixed-point interpolation coefficient; wherein the first digit and the second digit are determined according to the displacement value; The value obtained by multiplying the vertical coordinate of the pixel to be processed by the vertical scaling coefficient is subtracted from the value obtained by shifting the vertical coordinate of the first original pixel point left by the first bit number to obtain a second difference, and the second difference is right shifted by the second bit number to obtain the vertical fixed-point interpolation coefficient.

10. The method according to any one of claims 1 to 9, wherein the displacement value is an integer in the interval [7, 11].

11. An image scaling device, the device being deployed on a computer device, the device comprising: A scaling factor determination module, used to obtain a horizontal scaling factor and a vertical scaling factor in integer form through fixed-point calculation according to the width and height of the original image, the width and height of the target image and the displacement value in integer form; an interpolation coefficient determination module, configured to obtain, for each pixel to be processed in the target image, the coordinates of the original pixel corresponding to the pixel to be processed in the original image and the fixed-point interpolation coefficient in integer form through fixed-point calculation according to the coordinates of the pixel to be processed, the horizontal scaling coefficient, the vertical scaling coefficient and the displacement value; A pixel value determination module, used for obtaining the pixel value of the pixel point to be processed by fixed-point operation according to the pixel value of the original pixel point, the fixed-point interpolation coefficient and the displacement value; The image generation module is used to obtain the target image after scaling the original image based on the pixel value of each pixel to be processed in the target image.

12. A computer device, comprising a processor and a memory, wherein a computer program is stored in the memory, and the computer program is loaded and executed by the processor to implement the method according to any one of claims 1 to 10.

13. A computer-readable storage medium, wherein a computer program is stored in the computer-readable storage medium, wherein the computer program is loaded and executed by a processor to implement the method according to any one of claims 1 to 10.

14. A computer program product, comprising a computer program, wherein the computer program is stored in a computer-readable storage medium, and a processor reads and executes the computer program from the computer-readable storage medium to implement the method according to any one of claims 1 to 10.

Citation Information

Patent Citations

  • Video scaling device based on bicubic interpolation

    CN101616249A

  • Image scaling method based on bilinear interpolation algorithm processing

    CN108986033A

  • Image zooming method and device, electronic equipment and storage medium

    CN112508793A

  • Image scaling method and device based on bilinear interpolation algorithm, equipment and medium

    CN114092336A

  • Image zooming method and device, electronic equipment and storage medium

    CN114170091A