Image scaling method, device, electronic device and storage medium
By using the pixel values of the third coordinate point to perform distortion correction during image scaling, the problem of post-scaling image distortion caused by the distortion of the original image is solved, and efficient image distortion correction and scaling processing are achieved.
Patent Information
- Application Number
- CN202111632868.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-12-29
- Publication Date
- 2025-06-06
- Estimated Expiration
- 2041-12-29
AI Technical Summary
The original image collected by the image acquisition device has distortion due to lens characteristics and installation distance, which causes the object to appear distorted or deformed in the image after scaling. How to quickly generate a scaled image that has been distorted and corrected is an urgent problem to be solved.
By calculating the pixel value of the target pixel point in the target image after the original image is scaled, distortion correction and scaling processing are performed using the pixel value of the pixel point corresponding to the pixel point of the third coordinate point to generate a scalable image with distortion correction.
It realizes direct distortion correction during image scaling, reduces the number of processing, avoids multiple reading and writing images, and improves the efficiency of generating the zoomed image.
Smart Images

Figure CN114170091B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of data processing, and in particular to an image scaling method, device, electronic equipment and storage medium. Background Art
[0002] With the development of technology, intelligent image processing algorithms are widely used in various industries, such as intelligent monitoring and intelligent access control.
[0003] Generally speaking, in order to improve the processing efficiency of the intelligent processing algorithm, the image processed by the intelligent processing algorithm is not the original image captured by the image acquisition device, but the scaled image obtained by scaling the original image.
[0004] However, due to lens characteristics, installation distance and other reasons, the original image captured by the image acquisition device is distorted, resulting in distortion or deformation of the object in the original image relative to the real object. Therefore, how to quickly generate a scaled image that has been corrected for distortion is an urgent problem to be solved. Summary of the invention
[0005] The purpose of the embodiments of the present invention is to provide an image scaling method, device, electronic device and storage medium to quickly generate a scaled image that has been distortion corrected. The specific technical solution is as follows:
[0006] In a first aspect, an embodiment of the present invention provides an image scaling method, the method comprising:
[0007] Obtain the original image to be processed;
[0008] Calculate the pixel value of the target pixel in the target image after scaling the original image to generate the target image; wherein the pixel value of each target pixel is obtained by:
[0009] Determine, according to the first coordinate point of the target pixel point in the target image, a second coordinate point corresponding to the target pixel point in the original image; wherein the second coordinate point corresponding to the target pixel point is: a coordinate point of a pixel point used to generate the target pixel point when scaling the original image;
[0010] Determine a third coordinate point corresponding to the second coordinate point in the original image; wherein the third coordinate point corresponding to the second coordinate point is: a coordinate point of a pixel point used for performing distortion correction on the second coordinate point;
[0011] The pixel value of the target pixel point is calculated using the pixel value of the pixel point corresponding to the third coordinate point.
[0012] Optionally, determining a second coordinate point corresponding to the target pixel point in the original image according to the first coordinate point of the target pixel point in the target image includes:
[0013] Determine a first coordinate point of the target pixel point in the target image;
[0014] Based on a preset scaling mapping relationship, a coordinate point mapped by the first coordinate point in the original image is determined as a second coordinate point corresponding to the target pixel point.
[0015] Optionally, the determining, based on a preset scaling mapping relationship, a coordinate point mapped by the first coordinate point in the original image as a second coordinate point corresponding to the target pixel point includes:
[0016] Calculating a ratio of a horizontal coordinate of the first coordinate point to a preset horizontal zoom ratio to obtain a first zoomed horizontal coordinate, and calculating a ratio of a vertical coordinate of the first coordinate point to a preset vertical zoom ratio to obtain a first zoomed vertical coordinate;
[0017] Based on the first scaled horizontal coordinate and the first scaled vertical coordinate, a coordinate point in the original image to which the first coordinate point is mapped is determined as a second coordinate point corresponding to the target pixel point.
[0018] Optionally, the determining, based on the first scaled horizontal coordinate and the first scaled vertical coordinate, a coordinate point mapped by the first coordinate point in the original image as a second coordinate point corresponding to the target pixel point includes:
[0019] Determine at least one coordinate point mapped by the first coordinate point in the original image as a second coordinate point corresponding to the target pixel point;
[0020] Among them, each determined coordinate point is: the horizontal coordinate is the second scaled horizontal coordinate or the third scaled horizontal coordinate, and the vertical coordinate is the coordinate point of the second scaled vertical coordinate or the third scaled vertical coordinate; the second scaled horizontal coordinate is: a maximum integer less than or equal to the first scaled horizontal coordinate; the third scaled horizontal coordinate is a minimum integer greater than the second scaled horizontal coordinate, and the second scaled vertical coordinate is: a maximum integer less than or equal to the first scaled vertical coordinate; the third scaled vertical coordinate is a minimum integer greater than the second scaled vertical coordinate.
[0021] Optionally, the determining a third coordinate point corresponding to the second coordinate point in the original image includes:
[0022] Determine a distance between the second coordinate point and the coordinate origin of the original image, and determine a distortion adjustment parameter of the second coordinate point based on the distance;
[0023] Calculating the product of the abscissa of the second coordinate point and the distortion adjustment parameter to obtain a first distortion abscissa, and calculating the product of the ordinate of the second coordinate point and the distortion adjustment parameter to obtain a first distortion ordinate;
[0024] Based on the first distorted horizontal coordinate and the first distorted vertical coordinate, a third coordinate point corresponding to the second coordinate point is determined.
[0025] Optionally, the determining, based on the first distorted horizontal coordinate and the first distorted vertical coordinate, a third coordinate point corresponding to the second coordinate point includes:
[0026] Determine at least one coordinate point corresponding to the second coordinate point as a third coordinate point corresponding to the second coordinate point;
[0027] Among them, at least one determined coordinate point is: the horizontal coordinate is the second distortion horizontal coordinate or the third distortion horizontal coordinate, and the vertical coordinate is the coordinate point of the second distortion vertical coordinate or the third distortion vertical coordinate; the second distortion horizontal coordinate is: a maximum integer less than or equal to the first distortion horizontal coordinate; the third distortion horizontal coordinate is a minimum integer greater than the second distortion horizontal coordinate, the second distortion vertical coordinate is: a maximum integer less than or equal to the first distortion vertical coordinate; the third distortion vertical coordinate is a minimum integer greater than the second distortion vertical coordinate.
[0028] Optionally, calculating the pixel value of the target pixel point by using the pixel value of the pixel point corresponding to the third coordinate point includes:
[0029] Obtaining a distortion-scaling weight corresponding to the third coordinate point;
[0030] If the third coordinate point is single, then calculating the product of the pixel value of the pixel point corresponding to the third coordinate point in the original image and the distortion-scaling weight corresponding to the third coordinate point as the pixel value of the target pixel point;
[0031] If there are multiple third coordinate points, based on the distortion-scaling weights corresponding to the third coordinate points, the pixel values of the pixel points corresponding to the third coordinate points in the original image are weighted summed to obtain the pixel value of the target pixel point.
[0032] Optionally, obtaining the distortion-scaling weight corresponding to the third coordinate point includes:
[0033] Calculating the distortion-scaling weight corresponding to the third coordinate point according to the second coordinate point and the third coordinate point; and / or,
[0034] Searching a preset distortion-scaling table for a distortion-scaling weight corresponding to the coordinates of the target pixel point as the distortion-scaling weight corresponding to the third coordinate point; wherein the weight corresponding to each coordinate point in the distortion-scaling table is determined in advance based on the second coordinate point and the third coordinate point corresponding to the coordinate point.
[0035] Optionally, calculating the distortion-scaling weight corresponding to the third coordinate point according to the second coordinate point and the third coordinate point includes:
[0036] Substituting the coordinates of the second coordinate point into a preset scaling weight calculation formula to calculate the scaling weight corresponding to the second coordinate point;
[0037] Substituting the coordinates of the third coordinate point into a preset distortion weight calculation formula to calculate the distortion weight corresponding to the third coordinate point;
[0038] The product of the distortion weight and the scaling weight is calculated as the distortion-scaling weight corresponding to the third coordinate point.
[0039] In a second aspect, an embodiment of the present invention provides an image scaling device, the device comprising:
[0040] An image acquisition module, used to acquire the original image to be processed;
[0041] An image generation module, used for calculating the pixel value of a target pixel point in a target image after scaling the original image, so as to generate the target image;
[0042] Wherein, the image generation module is specifically used to determine, for each target pixel point, the second coordinate point corresponding to the target pixel point in the original image according to the first coordinate point of the target pixel point in the target image; wherein the second coordinate point corresponding to the target pixel point is: the coordinate point of the pixel point used to generate the target pixel point when the original image is scaled; the coordinate point of the pixel point used to generate the target pixel point when the original image is scaled; determine the third coordinate point corresponding to the second coordinate point in the original image; wherein the third coordinate point corresponding to the second coordinate point is: the coordinate point of the pixel point used for distortion correction of the second coordinate point; and calculate the pixel value of the target pixel point using the pixel value of the pixel point corresponding to the third coordinate point;
[0043] Optionally, the image generation module includes:
[0044] A first determination submodule, used to determine a first coordinate point of the target pixel point in the target image;
[0045] A second determination submodule is used to determine, based on a preset scaling mapping relationship, a coordinate point mapped by the first coordinate point in the original image as a second coordinate point corresponding to the target pixel point;
[0046] Optionally, the second determining submodule includes:
[0047] a coordinate calculation unit, configured to calculate a ratio of a horizontal coordinate of the first coordinate point to a preset horizontal zoom ratio to obtain a first zoomed horizontal coordinate, and to calculate a ratio of a vertical coordinate of the first coordinate point to a preset vertical zoom ratio to obtain a first zoomed vertical coordinate;
[0048] a coordinate determining unit, configured to determine, based on the first scaled horizontal coordinate and the first scaled vertical coordinate, a coordinate point mapped by the first coordinate point in the original image as a second coordinate point corresponding to the target pixel point;
[0049] Optionally, the coordinate determination unit is specifically used to determine at least one coordinate point mapped by the first coordinate point in the original image as the second coordinate point corresponding to the target pixel point; wherein each determined coordinate point is a coordinate point whose horizontal coordinate is the second scaled horizontal coordinate or the third scaled horizontal coordinate, and whose vertical coordinate is the second scaled vertical coordinate or the third scaled vertical coordinate; the second scaled horizontal coordinate is a maximum integer less than or equal to the first scaled horizontal coordinate; the third scaled horizontal coordinate is a minimum integer greater than the second scaled horizontal coordinate, and the second scaled vertical coordinate is a maximum integer less than or equal to the first scaled vertical coordinate; the third scaled vertical coordinate is a minimum integer greater than the second scaled vertical coordinate;
[0050] Optionally, the image generation module includes:
[0051] a parameter determination submodule, used to determine the distance between the second coordinate point and the coordinate origin of the original image, and based on the distance, determine the distortion adjustment parameter of the second coordinate point;
[0052] A coordinate calculation submodule, configured to calculate the product of the abscissa of the second coordinate point and the distortion adjustment parameter to obtain a first distorted abscissa, and calculate the product of the ordinate of the second coordinate point and the distortion adjustment parameter to obtain a first distorted ordinate;
[0053] a coordinate determination submodule, configured to determine a third coordinate point corresponding to the second coordinate point based on the first distorted horizontal coordinate and the first distorted vertical coordinate;
[0054] Optionally, the coordinate determination submodule is specifically used to determine at least one coordinate point corresponding to the second coordinate point as a third coordinate point corresponding to the second coordinate point; wherein the determined at least one coordinate point is: a coordinate point whose horizontal coordinate is the second distorted horizontal coordinate or the third distorted horizontal coordinate, and whose vertical coordinate is the second distorted vertical coordinate or the third distorted vertical coordinate; the second distorted horizontal coordinate is: a maximum integer less than or equal to the first distorted horizontal coordinate; the third distorted horizontal coordinate is a minimum integer greater than the second distorted horizontal coordinate, and the second distorted vertical coordinate is: a maximum integer less than or equal to the first distorted vertical coordinate; the third distorted vertical coordinate is a minimum integer greater than the second distorted vertical coordinate.
[0055] Optionally, the image generation module includes:
[0056] A weight acquisition submodule, used to acquire the distortion-scaling weight corresponding to the third coordinate point;
[0057] The pixel calculation submodule calculates the pixel value of the pixel point corresponding to the third coordinate point in the original image and the product of the distortion-scaling weight corresponding to the third coordinate point as the pixel value of the target pixel point if the third coordinate point is single; if the third coordinate point is multiple, the pixel values of the pixel points corresponding to each third coordinate point in the original image are weighted summed based on the distortion-scaling weight corresponding to each third coordinate point to obtain the pixel of the target pixel point.
[0058] Optionally, the weight acquisition submodule includes:
[0059] a weight calculation unit, configured to calculate a distortion-scaling weight corresponding to the third coordinate point according to the second coordinate point and the third coordinate point; and / or,
[0060] A weight search unit is used to search for the distortion-scaling weight corresponding to the coordinates of the target pixel point in a preset distortion-scaling table as the distortion-scaling weight corresponding to the third coordinate point; wherein the weight corresponding to each coordinate point in the distortion-scaling table is determined in advance based on the second coordinate point and the third coordinate point corresponding to the coordinate point.
[0061] Optionally, the weight calculation unit is specifically used to substitute the coordinates of the second coordinate point into a preset scaling weight calculation formula to calculate the scaling weight corresponding to the second coordinate point; substitute the coordinates of the third coordinate point into a preset distortion weight calculation formula to calculate the distortion weight corresponding to the third coordinate point; and calculate the product of the distortion weight and the scaling weight as the distortion-scaling weight corresponding to the third coordinate point.
[0062] In a third aspect, an embodiment of the present invention provides an electronic device, including a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other via the communication bus;
[0063] Memory, used to store computer programs;
[0064] The processor is used to implement the method steps provided in the first aspect when executing the program stored in the memory.
[0065] In a fourth aspect, an embodiment of the present invention provides a computer-readable storage medium, wherein the computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method steps provided in the first aspect are implemented.
[0066] Beneficial effects of the embodiments of the present invention:
[0067] In the image scaling method provided by the embodiment of the present invention, for the target pixel point in the target image after the original image is scaled, the second coordinate point corresponding to the target pixel point is first determined, and then the third coordinate point corresponding to the second coordinate point is determined, and finally the pixel value of the target pixel point is calculated using the pixel value of the pixel point corresponding to the third coordinate point. Since the second coordinate point is the coordinate of the pixel point used to generate the target pixel point when the original image is scaled, and the third coordinate point is the coordinate point of the pixel point used for performing distortion correction on the second coordinate point, therefore, the pixel value of the target pixel point is calculated using the pixel value of the pixel point corresponding to the third coordinate point, which is equivalent to first performing distortion correction on the original image, and then performing scaling to obtain the pixel value of the target pixel point, so that the pixel value of the target pixel point obtained is the pixel value after distortion correction and scaling. It can be seen that through this solution, a scaled image that has been distortion corrected can be obtained.
[0068] In addition, since the pixel point of the target pixel point can be calculated directly based on the pixel value of the pixel point corresponding to the third coordinate point, it is equivalent to performing distortion correction while scaling the image, which can reduce the number of processing required to obtain the scaled image that has been distortion corrected. At the same time, there is no need to first perform distortion correction on the original image to generate a distortion-corrected image, and then scale the distortion-corrected image. This can avoid reading and writing the image multiple times, reduce the consumption of read and write bandwidth, and make the generation of the scaled image more efficient.
[0069] Of course, it is not necessary to achieve all of the advantages described above at the same time to implement any product or method of the present invention. BRIEF DESCRIPTION OF THE DRAWINGS
[0070] In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings required for use in the embodiments or the description of the prior art will be briefly introduced below. Obviously, the drawings in the following description are only some embodiments of the present invention. For ordinary technicians in this field, other embodiments can be obtained based on these drawings without paying creative work.
[0071] Figure 1 A schematic diagram of distortion provided by an embodiment of the present invention;
[0072] Figure 2 A schematic diagram of a flow chart of an image scaling method provided by an embodiment of the present invention;
[0073] Figure 3 A schematic diagram of a pixel calculation method provided by an embodiment of the present invention;
[0074] Figure 4 Another flow chart of the image scaling method provided by an embodiment of the present invention;
[0075] Figure 5 A schematic diagram of scaling mapping provided by an embodiment of the present invention;
[0076] Figure 6 Another flow chart of the image scaling method provided by an embodiment of the present invention;
[0077] Figure 7 A schematic diagram of distortion mapping provided by an embodiment of the present invention;
[0078] Figure 8 Another flow chart of the image scaling method provided by an embodiment of the present invention;
[0079] Fig. 9 A schematic diagram of distortion-scaling mapping provided by an embodiment of the present invention;
[0080] Fig.10 A schematic diagram of the structure of an image scaling device provided by an embodiment of the present invention;
[0081] Fig.11 A schematic diagram of the structure of an electronic device provided by an embodiment of the present invention. DETAILED DESCRIPTION
[0082] The following will be combined with the drawings in the embodiments of the present invention to clearly and completely describe the technical solutions in the embodiments of the present invention. Obviously, the described embodiments are only part of the embodiments of the present invention, not all of the embodiments. Based on the embodiments of the present invention, all other embodiments obtained by ordinary technicians in this field without creative work are within the scope of protection of the present invention.
[0083] In order to more clearly illustrate the technical solution of the embodiment of the present invention, image distortion is briefly introduced.
[0084] The distortion caused by the lens of the image acquisition device is usually divided into radial distortion and tangential distortion. For the convenience of description, the distortion involved in the technical solution of the embodiment of the present invention is only introduced as radial distortion. Tangential distortion and radial distortion are only different in the direction of distortion and will not be introduced separately. Among them, radial distortion is the distortion distributed along the radius of the lens. Further, it can be divided into barrel distortion and pincushion distortion, such as Figure 1 The left half of the image in the distortion diagram is pincushion distortion, and the right half is barrel distortion. Radial distortion is the distortion distributed along the radius of the lens. The reason for radial distortion is that the light is bent more away from the center of the lens than near the center. Radial distortion is more obvious in cheap lenses.
[0085] In order to quickly obtain a scaled image that has undergone distortion correction, embodiments of the present invention provide an image scaling method, an apparatus, an electronic device, and a storage medium.
[0086] like Figure 2 As shown, an image scaling method provided by an embodiment of the present invention may include the following steps:
[0087] S201, obtaining an original image to be processed;
[0088] The original image is the image that needs to be scaled. The acquisition method of the original image can be combined with the actual usage scenario. For example, in a scenario with high feasibility requirements, the image captured by the image acquisition device can be acquired in real time as the original image to be processed. For a scenario with low real-time requirements, the original image to be processed can be read from a data set / database.
[0089] The above-mentioned embodiments with high requirements may include various application scenarios of face recognition and body recognition, such as smart access control, area protection, etc. In this case, the original image may be a body image or face image captured in real time by an image acquisition device. The above-mentioned embodiments with low requirements may include machine learning model training and other scenarios. In this case, the original image may be an image read from a training sample set.
[0090] S202, calculating the pixel value of the target pixel point in the target image after the original image is scaled, so as to generate the target image.
[0091] The target image is the image after scaling the original image. In order to obtain the target image, the pixel value of the target pixel in the target image needs to be calculated. It should be noted that the target pixel in the target image is any pixel contained in the target image. For example, if the target image contains N pixels, then these N pixels are all target pixels.
[0092] Different from the related art, in which a target image is obtained by scaling the original image, in an embodiment of the present invention, calculations can be performed for each target pixel in the target image, and the pixel value of each pixel in the original image can be used to calculate the pixel value of each pixel in the target image.
[0093] Optionally, in a method of calculating the pixel value of a target pixel, for each pixel in the target image, the following method can be used: Figure 3 The pixel value of the target pixel is calculated by the pixel calculation method shown in FIG. Figure 3 The pixel calculation method shown includes the following steps:
[0094] S202-1, determine the second coordinate point corresponding to the target pixel point in the original image based on the first coordinate point of the target pixel point in the target image; wherein the second coordinate point corresponding to the target pixel point is: the coordinate point of the pixel point used to generate the target pixel point when the original image is scaled.
[0095] In this step, the second coordinate point corresponding to the target pixel point is: the coordinate point of the pixel point used to generate the target pixel point when the original image is scaled.
[0096] When the scaling ratio is known, the pixel point in the image before scaling that corresponds to the pixel point in the scaled image is related to the coordinates of the pixel point in the scaled image, that is, related to the coordinate points of the pixel point in the scaled image. Therefore, the second coordinate point corresponding to the target pixel point in the original image can be determined based on the first coordinate point of the target pixel point in the target image.
[0097] S202-2, determining a third coordinate point corresponding to the second coordinate point in the original image; wherein the third coordinate point corresponding to the second coordinate point is: a coordinate point of a pixel point used for performing distortion correction on the second coordinate point;
[0098] In this step, the third coordinate point corresponding to the second coordinate point is: the coordinate point of the pixel point used for performing distortion correction on the second coordinate point. When the distortion parameters are known, the pixel point used when calibrating each pixel point before distortion correction is related to the coordinate point of the pixel point before distortion correction, that is, related to the coordinates of the pixel point in the distorted image. Therefore, the third coordinate point corresponding to the second coordinate point can be determined according to the coordinates of the second coordinate point.
[0099] S202-3, using the pixel value of the pixel point corresponding to the third coordinate point, calculate the pixel value of the target pixel point.
[0100] After the third coordinate point is determined, the pixel value of the target pixel point can be calculated using the pixel value of the pixel point corresponding to the third coordinate point. When the pixel value is an RGB value, the R value of the target pixel point can be determined based on the R value of the pixel point corresponding to the third coordinate point, the G value of the target pixel point can be determined based on the G value of the pixel point corresponding to the third coordinate point, and the B value of the first coordinate point can be determined based on the B value of the pixel point corresponding to the third coordinate point, thereby obtaining the RGB value of the target pixel point.
[0101] In order to obtain a scaled image that has been distortion corrected, in the related art, it is necessary to first use the pixel value of the pixel point corresponding to the third coordinate point to perform distortion calibration, and then scale the image after the distortion calibration, that is, use the pixel value of the second coordinate point in the image after the distortion calibration to calculate the pixel value of the target pixel point, and finally obtain the scaled image that has been distortion corrected.
[0102] In this step, the pixel value of the target pixel is calculated directly using the pixel value of the pixel corresponding to the third coordinate point, rather than first performing distortion calibration and then performing scaling. The specific implementation process will be described in detail in subsequent embodiments and will not be repeated here.
[0103] In the image scaling method provided by the embodiment of the present invention, since the second coordinate point is the coordinate of the pixel point used to generate the target pixel point when the original image is scaled, and the third coordinate point is the coordinate point of the pixel point used for distortion correction of the second coordinate point, the pixel value of the target pixel point is calculated using the pixel value of the pixel point corresponding to the third coordinate point, which is equivalent to first performing distortion correction on the original image and then scaling to obtain the pixel value of the target pixel point, so that the pixel value of the target pixel point obtained is the pixel value after distortion correction and scaling. It can be seen that through this solution, a scaled image that has been distortion corrected can be obtained.
[0104] In addition, since the pixel point of the target pixel point can be calculated directly based on the pixel value of the pixel point corresponding to the third coordinate point, it is equivalent to performing distortion correction while scaling the image, which can reduce the number of processing required to obtain the scaled image that has been distortion corrected. At the same time, there is no need to first perform distortion correction on the original image to generate a distortion-corrected image, and then scale the distortion-corrected image. This can avoid reading and writing the image multiple times, reduce the consumption of read and write bandwidth, and make the generation of the scaled image more efficient.
[0105] based on Figure 3 Examples of Figure 4As shown, in another embodiment of the present invention, the image scaling method provided by the above S202-1 may include steps S401-S402:
[0106] S401, determining a first coordinate point of the target pixel in the target image;
[0107] The first coordinate point is the pixel coordinate point of the target pixel point in the target image.
[0108] S402: Based on a preset scaling mapping relationship, determine a coordinate point mapped to the first coordinate point in the original image as a second coordinate point corresponding to the target pixel point.
[0109] The preset scaling mapping relationship may be a preset coordinate mapping relationship corresponding to the scaling ratio required for the original image. As can be seen from the foregoing, the image size of the acquired original image and the image size after scaling are both known in advance, which means that the scaling ratio required for the original image is also known in advance. The scaling ratio required for the original image may include a preset horizontal scaling ratio and a preset vertical scaling ratio.
[0110] The vertical scaling ratio is the ratio of the length of the scaled image to the length of the original image, and the horizontal scaling ratio is the ratio of the width of the scaled image to the width of the original image. For example, if the image size of the original image is 1024×768 and the image size of the scaled image is 512×512, then the vertical scaling ratio = 512 / 1024 = 0.5, and the horizontal scaling ratio = 512 / 768≈0.7.
[0111] It should be noted that if the vertical scaling ratio and the horizontal scaling ratio are the same, the scaling ratio required for the original image may only include a single ratio, which means that both the length and the width of the original image are scaled according to the ratio.
[0112] In one implementation, the above step S402 may include the following steps A1-A2:
[0113] Step A1: Calculate the ratio of the horizontal coordinate of the first coordinate point to the preset horizontal zoom ratio to obtain a first zoomed horizontal coordinate, and calculate the ratio of the vertical coordinate of the first coordinate point to the preset vertical zoom ratio to obtain a first zoomed vertical coordinate.
[0114] The first scaling horizontal coordinate and the first scaling vertical coordinate can be calculated respectively using the following formulas:
[0115]
[0116]
[0117] Among them, x is the horizontal coordinate of the first coordinate point, y is the vertical coordinate of the first coordinate point, x′ is the first scaled horizontal coordinate, y′ is the first scaled vertical coordinate, W is the width scaling ratio, and H is the length scaling ratio.
[0118] After determining the first coordinate point, the first scaling horizontal coordinate and the first scaling vertical coordinate can be calculated based on the coordinates of the first coordinate point according to the above calculation formula. For the convenience of description, the point whose horizontal coordinate is the first scaling horizontal coordinate and whose vertical coordinate is the first scaling vertical coordinate can be used as the scaling mapping point corresponding to the first coordinate point.
[0119] For example, Figure 5 A schematic diagram of scaling mapping provided for an embodiment of the present invention, wherein S1 is the first coordinate point with coordinates (x, y). The coordinates of S1 are substituted into the above calculation formula to obtain coordinates (x0, y0), where x0 is the first scaling horizontal coordinate and y0 is the first scaling vertical coordinate.
[0120] Step A2: Based on the first scaled horizontal coordinate and the first scaled vertical coordinate, determine the coordinate point mapped by the first coordinate point in the original image as the second coordinate point corresponding to the target pixel point.
[0121] After the first scaled horizontal coordinate and the first scaled vertical coordinate are calculated, the coordinate point mapped by the first coordinate point in the original image may be determined based on the first scaled horizontal coordinate and the first scaled vertical coordinate as the second coordinate point corresponding to the target pixel point.
[0122] In one implementation, at least one coordinate point mapped by the first coordinate point in the original image may be determined as the second coordinate point corresponding to the target pixel point.
[0123] Among them, each determined coordinate point is: the horizontal coordinate is the second scaled horizontal coordinate or the third scaled horizontal coordinate, and the vertical coordinate is the coordinate point of the second scaled vertical coordinate or the third scaled vertical coordinate; the second scaled horizontal coordinate is: the maximum integer less than or equal to the first scaled horizontal coordinate; the third scaled horizontal coordinate is the minimum integer greater than the second scaled horizontal coordinate, the second scaled vertical coordinate is: the maximum integer less than or equal to the first scaled vertical coordinate; the third scaled vertical coordinate is the minimum integer greater than the second scaled vertical coordinate.
[0124] Optionally, the maximum integer less than or equal to the first scaled horizontal coordinate can be determined as the second scaled horizontal coordinate, and the maximum integer less than or equal to the first scaled vertical coordinate can be determined as the second scaled vertical coordinate, and then the minimum integer greater than the second scaled horizontal coordinate can be calculated as the third scaled horizontal coordinate, and the minimum integer greater than the second scaled vertical coordinate can be calculated as the third scaled vertical coordinate, and finally at least one coordinate point mapped to the first coordinate point in the original image can be determined as the second coordinate point corresponding to the target pixel point.
[0125] In order to determine the maximum integer less than or equal to the first scaled horizontal coordinate, the first scaled horizontal coordinate may be rounded to obtain the second scaled horizontal coordinate. Similarly, the first scaled vertical coordinate may be rounded to obtain the second scaled vertical coordinate. The implementation method of the first scaled vertical coordinate and the first scaled horizontal coordinate for rounding operations is the same, and the following description is based only on the first scaled horizontal coordinate. The method of rounding the first scaled vertical coordinate refers to the method of rounding the first scaled horizontal coordinate.
[0126] The value operation includes two types: rounding down and rounding up. Among them, rounding down can obtain the maximum integer coordinate less than the first scaled horizontal coordinate, and rounding up can obtain the minimum integer coordinate greater than the first scaled horizontal coordinate. For example, if the first scaled horizontal coordinate is 1.2, it is rounded down to 1 and rounded up to 2.
[0127] In the embodiment of the present invention, after obtaining the first scaled horizontal coordinate, it is necessary to determine the maximum integer less than or equal to the first scaled horizontal coordinate. Therefore, it is necessary to round down the first scaled horizontal coordinate to obtain a second scaled horizontal coordinate less than or equal to the first scaled horizontal coordinate. After obtaining the second scaled horizontal coordinate, the minimum integer greater than the second scaled vertical coordinate can be calculated by adding 1. For example, if the first scaled horizontal coordinate is 1.2, it is rounded down to 1, that is, the second scaled horizontal coordinate is 1, and then 1+1=2 is calculated to obtain the third scaled horizontal coordinate of 2.
[0128] Combination Figure 5 In the embodiment, S2 is the scaled mapping point mapped by the first coordinate point S1, and the coordinates of S2 are (x0, y0). x0 and y0 are rounded down to obtain the second scaled horizontal coordinate x1 and the second scaled vertical coordinate y1, and then the third scaled horizontal coordinate x2 = x1 + 1 and the third scaled vertical coordinate y2 = y1 + 1 are calculated. Finally, based on x1, x2, y1, and y2, four coordinate points can be determined, such as Figure 5 As shown, they are R1(x1, y2), R2(x2, y2), R3(x1, y1) and R4(x2, y1). Then at least one coordinate point mapped by the first coordinate point in the original image is at least one of R1, R2, R3 and R4.
[0129] In the image scaling method provided in the embodiment of the present invention, a scaled image that has been subjected to distortion correction can be obtained, and multiple reading and writing of the image can be avoided, so that the efficiency of generating the scaled image is higher. At the same time, the second coordinate point corresponding to the target pixel point can be determined based on the preset scaling mapping relationship, which provides an implementation basis for the present invention.
[0130] based on Figure 3 Examples of Figure 6As shown, in another embodiment of the present invention, the image scaling method provided by the above S202-2 may include steps S601-S603:
[0131] S601, determining a distance between a second coordinate point and the coordinate origin of the original image, and determining a distortion adjustment parameter of the second coordinate point based on the distance;
[0132] The following calculation formula can be used to calculate the distance between the second coordinate point and the origin of the original image coordinates:
[0133] r = sqrt(x′ 2 +y′ 2 )
[0134] Wherein, r is the distance between the second coordinate point and the coordinate origin of the original image, x′ is the horizontal coordinate of the second coordinate point, and y′ is the vertical coordinate of the second coordinate point.
[0135] After calculating the distance between the second coordinate point and the coordinate origin of the original image, the distortion adjustment parameter of the second coordinate point can be determined as:
[0136] k=1+k 1 r 2 +k 2 r 4 +k 3 r 6
[0137] Among them, k is the distortion adjustment parameter of the second coordinate point, k 1 , k 2 and k 3 Distortion parameters of the distortion-corrected image calibrated offline.
[0138] S602, calculating the product of the abscissa of the second coordinate point and the distortion adjustment parameter to obtain a first distorted abscissa, and calculating the product of the ordinate of the second coordinate point and the distortion adjustment parameter to obtain a first distorted ordinate;
[0139] After the distortion adjustment parameter is determined, the first distortion abscissa and the first distortion ordinate can be calculated based on the distortion adjustment parameter:
[0140] x″=x′k
[0141] y″=y′k
[0142] Wherein, x′ is the abscissa of the second coordinate point, x″ is the first distorted abscissa, y′ is the ordinate of the second coordinate point, and y″ is the first distorted ordinate.
[0143] In the embodiment of the present invention, for the convenience of description, a point whose abscissa is the first distortion abscissa and whose ordinate is the first distortion ordinate is taken as a distortion mapping point corresponding to the second coordinate point.
[0144] S603: Determine a third coordinate point corresponding to the second coordinate point based on the first distorted horizontal coordinate and the first distorted vertical coordinate.
[0145] After the first distorted horizontal coordinate and the first distorted vertical coordinate are calculated, a third coordinate point corresponding to the second coordinate point may be determined based on the first distorted horizontal coordinate and the first distorted vertical coordinate.
[0146] In one implementation, at least one coordinate point corresponding to the second coordinate point may be determined as a third coordinate point corresponding to the second coordinate point.
[0147] Among them, at least one coordinate point determined is: the horizontal coordinate is the second distortion horizontal coordinate or the third distortion horizontal coordinate, and the vertical coordinate is the coordinate point of the second distortion vertical coordinate or the third distortion vertical coordinate; the second distortion horizontal coordinate is: a maximum integer less than or equal to the first distortion horizontal coordinate; the third distortion horizontal coordinate is a minimum integer greater than the second distortion horizontal coordinate, and the second distortion vertical coordinate is: a maximum integer less than or equal to the first distortion vertical coordinate; the third distortion vertical coordinate is a minimum integer greater than the second distortion vertical coordinate.
[0148] Optionally, the maximum integer less than or equal to the first distorted horizontal coordinate can be determined as the second distorted horizontal coordinate, and the maximum integer less than or equal to the first distorted vertical coordinate can be determined as the second distorted vertical coordinate, and then the minimum integer greater than the second distorted horizontal coordinate can be calculated as the third distorted horizontal coordinate, and the minimum integer greater than the second distorted vertical coordinate can be calculated as the third distorted vertical coordinate, and finally at least one coordinate point mapped by the second coordinate point in the original image can be determined as the third coordinate point corresponding to the target pixel point.
[0149] In order to determine the maximum integer less than or equal to the first distorted horizontal coordinate, the first distorted horizontal coordinate may be rounded to obtain the second distorted horizontal coordinate. Similarly, the first distorted vertical coordinate may be rounded to obtain the second distorted vertical coordinate. The implementation method of the first distorted vertical coordinate and the first distorted horizontal coordinate is the same. The following description is based on the first distorted horizontal coordinate. The method of rounding the first distorted vertical coordinate refers to the method of rounding the first distorted horizontal coordinate.
[0150] In the embodiment of the present invention, after obtaining the first distorted horizontal coordinate, it is necessary to determine the maximum integer less than or equal to the first distorted horizontal coordinate. Therefore, it is necessary to round down the first distorted horizontal coordinate to obtain a second distorted horizontal coordinate less than or equal to the first distorted horizontal coordinate. After obtaining the second distorted horizontal coordinate, the minimum integer greater than the second distorted vertical coordinate can be calculated by adding 1. For example, if the first distorted horizontal coordinate is 2.2, it is rounded down to 2, that is, the second distorted horizontal coordinate is 2, and finally 2+1=3 is calculated, that is, the third distorted horizontal coordinate is 3.
[0151] For example, Figure 7 A schematic diagram of distortion mapping provided by an embodiment of the present invention, wherein point N1 is a distortion mapping point corresponding to the second coordinate point, and the coordinates are (x3, y3), x3 is the first distortion horizontal coordinate, y3 is the first distortion vertical coordinate, and x3 and y3 are rounded down to obtain the second distortion horizontal coordinate x4 and the second distortion vertical coordinate y4, and then the third distortion horizontal coordinate x5=x4+1 and the third distortion vertical coordinate y5=y4+1 are calculated. Finally, based on x4, x5, y4, and y5, four coordinate points can be determined, such as Figure 7 As shown, they are N11 (x4, y5), N12 (x5, y5), N13 (x4, y4) and N14 (x5, y4). Then at least one coordinate point mapped by the second coordinate point in the original image is at least one of N11, N12, N13 and N14.
[0152] In the image scaling method provided in the embodiment of the present invention, a scaled image that has been subjected to distortion correction can be obtained, and multiple reading and writing of the image can be avoided, so that the efficiency of generating the scaled image is higher. At the same time, the distortion adjustment parameter can be determined, and then the third coordinate point corresponding to the second pixel point can be determined, which provides a basis for the implementation of the present invention.
[0153] based on Figure 3 Examples of Figure 8 As shown, in another embodiment of the present invention, the image scaling method provided by the above S202-3 may include steps S801-S803:
[0154] S801, obtaining a distortion-scaling weight corresponding to a third coordinate point;
[0155] There are multiple ways to obtain the distortion-scaling weight corresponding to the third coordinate point, and exemplary methods include at least one of the following two ways:
[0156] Method 1: Calculate the distortion-scaling weight corresponding to the third coordinate point according to the second coordinate point and the third coordinate point;
[0157] Optionally, the method of calculating the distortion-scaling weight may include step A1-step A2:
[0158] Step A1, substituting the coordinates of the second coordinate point into a preset scaling weight calculation formula to calculate the scaling weight corresponding to the second coordinate point;
[0159] The scaling weight calculation formula is:
[0160] w=|x′-x|*|y′-y|
[0161] Among them, x′ is the horizontal coordinate of the second coordinate point, y′ is the vertical coordinate of the second coordinate point, x is the first scaled horizontal coordinate, and y is the first scaled vertical coordinate.
[0162] For each second coordinate point, after the second coordinate point is determined, the scaling weight of the second coordinate point may be calculated according to the scaling weight calculation formula.
[0163] by Figure 5 The scaling mapping diagram shown is used as an example. The scaling weight w1 of the second coordinate point R1 is (x2-x0)*(y1-y0), the scaling weight w2 of the second coordinate point R2 is (x0-x1)*(y1-y0), the scaling weight w3 of the second coordinate point R3 is (x2-x0)*(y0-y2), and the scaling weight w4 of the second coordinate point R4 is (x0-x1)*(y0-y2).
[0164] Step A2, substituting the coordinates of the third coordinate point into a preset distortion weight calculation formula to calculate the distortion weight corresponding to the third coordinate point;
[0165] Among them, the preset distortion weight calculation formula is:
[0166] m=|x″-x′|*|y″-x′|
[0167] Among them, x″ is the abscissa of the third coordinate point, y″ is the ordinate of the third coordinate point, x′ is the abscissa of the distortion mapping point of the second coordinate point, and y′ is the ordinate of the distortion mapping point of the second coordinate point.
[0168] For each third coordinate point, after the third coordinate point is determined, the distortion weight of the third coordinate point may be calculated according to the above distortion weight calculation formula.
[0169] by Figure 7 The distortion mapping diagram shown is used as an example. The distortion weight m11 of the third coordinate point N11 is (x5-x3)*(y4-y3), the distortion weight m12 of the third coordinate point N12 is (x3-x4)*(y4-y3), the distortion weight m13 of the third coordinate point N13 is (x5-x3)*(y3-y5), and the distortion weight m14 of the third coordinate point N14 is (x3-x4)*(y3-y5).
[0170] Step A3: Calculate the product of the distortion weight and the scaling weight as the distortion-scaling weight corresponding to the third coordinate point.
[0171] For each third coordinate point, the product of the distortion weight of the third coordinate point and the scaling weight of the second coordinate point corresponding to the third coordinate point may be calculated as the distortion-scaling weight corresponding to the third coordinate point.
[0172] Exemplarily, the distortion weight of the third coordinate point N11 is m11, the third coordinate point N11 corresponds to the second coordinate point R1, the scaling weight of the second coordinate point R1 is w1, and the distortion-scaling weight of the third coordinate point N11 is: w1*m11.
[0173] Method 2: Searching for the distortion-scaling weight corresponding to the coordinates of the target pixel point in a preset distortion-scaling table as the distortion-scaling weight corresponding to the third coordinate point; wherein the weight corresponding to each coordinate point in the distortion-scaling table is determined in advance based on the second coordinate point and the third coordinate point corresponding to the coordinate point.
[0174] In this method, in order to reduce the amount of calculation and save the computing resources of the device, a distortion-scaling table can be established in advance. The distortion-scaling table records the distortion-scaling weight of each third coordinate point, and the distortion-scaling weight of each third coordinate point is determined in advance based on the second coordinate point and the third coordinate point corresponding to the coordinate point. Therefore, when it is needed, the distortion-scaling table can be directly read to obtain the weight of each third coordinate point, avoiding the decimal operations involved in the calculation of the distortion-scaling weight, saving computing resources, and further improving the efficiency of image scaling.
[0175] Among them, in establishing the distortion-scaling table, the distortion-scaling weight corresponding to the coordinates of each target pixel point can be calculated according to the calculation method of the distortion-scaling weight described in the above-mentioned method 1, which will not be repeated here.
[0176] S802, if the third coordinate point is a single point, then calculate the product of the pixel value of the pixel point corresponding to the third coordinate point in the original image and the distortion-scaling weight corresponding to the third coordinate point as the pixel value of the target pixel point;
[0177] If the third coordinate point is single, the pixel value of the pixel point corresponding to the third coordinate point in the original image and the product of the distortion-scaling weight corresponding to the third coordinate point can be directly used as the pixel value of the target pixel point.
[0178] S803: If there are multiple third coordinate points, based on the distortion-scaling weights corresponding to the third coordinate points, weighted sum is performed on the pixel values of the pixel points corresponding to the third coordinate points in the original image to obtain the pixel value of the target pixel point.
[0179] In order to obtain a more accurate pixel value of the target pixel, there may be multiple third coordinate points, for example, there are 16 third coordinate points.
[0180] In such Fig. 9 In the distortion-scaling mapping schematic diagram shown, the second coordinate points corresponding to the first coordinate point S1 include R1, R2, R3 and R4. The third coordinate points corresponding to the second coordinate point R1 include: N11, N12, N13 and N14; the third coordinate points corresponding to the second coordinate point R2 include: N21, N22, N23 and N24; the third coordinate points corresponding to the second coordinate point R3 include: N31, N32, N33 and N34; the third coordinate points corresponding to the second coordinate point R4 include: N41, N42, N43 and N44. That is, the third coordinate points corresponding to the first coordinate point S1 include N11, N12, N13, N14, N21, N22, N23, N24, N31, N32, N33, N34, N41, N42, N43 and N44.
[0181] At this time there are:
[0182] S1=N11*m11*w1+N12*m12*w1+N13*m13*w1+N14*m14*w1+N21*m21*w2+N22*m22*w2+N23*m23*w2+N24*m24*w 2+N31*m31*w3+N32*m32*w3+N33*m33*w3+N34*m34*w3+N41*m41*w4+N42*m42*w4+N43*m43*w4+N44*m44*w4
[0183] Among them, S1 represents the pixel value of the target pixel corresponding to the first coordinate point S1, and m11*w1 to m44*w4 are the distortion-scaling weights of the third stage N11-N44 respectively.
[0184] In the image scaling method provided in the embodiment of the present invention, a scaled image that has been subjected to distortion correction can be obtained, and multiple reading and writing of the image can be avoided, so that the efficiency of generating the scaled image is higher. At the same time, by calculating the distortion-scaling weight, the pixel value of the target pixel point can be accurately calculated based on the distortion-scaling weight.
[0185] According to the image scaling method provided by the embodiment of the present invention, Fig.10 As shown, an embodiment of the present invention further provides an image scaling device, the device comprising:
[0186] An image acquisition module 1001 is used to acquire an original image to be processed;
[0187] An image generation module 1002 is used to calculate the pixel value of a target pixel point in a target image after scaling the original image to generate the target image;
[0188] The image generation module 1002 is specifically used to determine, for each target pixel point, a second coordinate point corresponding to the target pixel point in the original image according to the first coordinate point of the target pixel point in the target image; wherein the second coordinate point corresponding to the target pixel point is: a coordinate point of a pixel point used to generate the target pixel point when the original image is scaled; a coordinate point of a pixel point used to generate the target pixel point when the original image is scaled; determine a third coordinate point corresponding to the second coordinate point in the original image; wherein the third coordinate point corresponding to the second coordinate point is: a coordinate point of a pixel point used for performing distortion correction on the second coordinate point; and calculate the pixel value of the target pixel point using the pixel value of the pixel point corresponding to the third coordinate point;
[0189] Optionally, the image generation module includes:
[0190] A first determination submodule, used to determine a first coordinate point of the target pixel point in the target image;
[0191] A second determination submodule is used to determine, based on a preset scaling mapping relationship, a coordinate point mapped by the first coordinate point in the original image as a second coordinate point corresponding to the target pixel point;
[0192] Optionally, the second determining submodule includes:
[0193] a coordinate calculation unit, configured to calculate a ratio of a horizontal coordinate of the first coordinate point to a preset horizontal zoom ratio to obtain a first zoomed horizontal coordinate, and to calculate a ratio of a vertical coordinate of the first coordinate point to a preset vertical zoom ratio to obtain a first zoomed vertical coordinate;
[0194] a coordinate determining unit, configured to determine, based on the first scaled horizontal coordinate and the first scaled vertical coordinate, a coordinate point mapped by the first coordinate point in the original image as a second coordinate point corresponding to the target pixel point;
[0195] Optionally, the coordinate determination unit is specifically used to determine at least one coordinate point mapped by the first coordinate point in the original image as the second coordinate point corresponding to the target pixel point; wherein each determined coordinate point is a coordinate point whose horizontal coordinate is the second scaled horizontal coordinate or the third scaled horizontal coordinate, and whose vertical coordinate is the second scaled vertical coordinate or the third scaled vertical coordinate; the second scaled horizontal coordinate is a maximum integer less than or equal to the first scaled horizontal coordinate; the third scaled horizontal coordinate is a minimum integer greater than the second scaled horizontal coordinate, and the second scaled vertical coordinate is a maximum integer less than or equal to the first scaled vertical coordinate; the third scaled vertical coordinate is a minimum integer greater than the second scaled vertical coordinate;
[0196] Optionally, the image generation module includes:
[0197] a parameter determination submodule, used to determine the distance between the second coordinate point and the coordinate origin of the original image, and based on the distance, determine the distortion adjustment parameter of the second coordinate point;
[0198] A coordinate calculation submodule, configured to calculate the product of the abscissa of the second coordinate point and the distortion adjustment parameter to obtain a first distorted abscissa, and calculate the product of the ordinate of the second coordinate point and the distortion adjustment parameter to obtain a first distorted ordinate;
[0199] a coordinate determination submodule, configured to determine a third coordinate point corresponding to the second coordinate point based on the first distorted horizontal coordinate and the first distorted vertical coordinate;
[0200] Optionally, the coordinate determination submodule is specifically used to determine at least one coordinate point corresponding to the second coordinate point as a third coordinate point corresponding to the second coordinate point; wherein the determined at least one coordinate point is: a coordinate point whose horizontal coordinate is the second distorted horizontal coordinate or the third distorted horizontal coordinate, and whose vertical coordinate is the second distorted vertical coordinate or the third distorted vertical coordinate; the second distorted horizontal coordinate is: a maximum integer less than or equal to the first distorted horizontal coordinate; the third distorted horizontal coordinate is a minimum integer greater than the second distorted horizontal coordinate, and the second distorted vertical coordinate is: a maximum integer less than or equal to the first distorted vertical coordinate; the third distorted vertical coordinate is a minimum integer greater than the second distorted vertical coordinate.
[0201] Optionally, the image generation module includes:
[0202] A weight acquisition submodule, used to acquire the distortion-scaling weight corresponding to the third coordinate point;
[0203] The pixel calculation submodule calculates the pixel value of the pixel point corresponding to the third coordinate point in the original image and the product of the distortion-scaling weight corresponding to the third coordinate point as the pixel value of the target pixel point if the third coordinate point is single; if the third coordinate point is multiple, the pixel values of the pixel points corresponding to each third coordinate point in the original image are weighted summed based on the distortion-scaling weight corresponding to each third coordinate point to obtain the pixel of the target pixel point.
[0204] Optionally, the weight acquisition submodule includes:
[0205] a weight calculation unit, configured to calculate a distortion-scaling weight corresponding to the third coordinate point according to the second coordinate point and the third coordinate point; and / or,
[0206] A weight search unit is used to search for the distortion-scaling weight corresponding to the coordinates of the target pixel point in a preset distortion-scaling table as the distortion-scaling weight corresponding to the third coordinate point; wherein the weight corresponding to each coordinate point in the distortion-scaling table is determined in advance based on the second coordinate point and the third coordinate point corresponding to the coordinate point.
[0207] Optionally, the weight calculation unit is specifically used to substitute the coordinates of the second coordinate point into a preset scaling weight calculation formula to calculate the scaling weight corresponding to the second coordinate point; substitute the coordinates of the third coordinate point into a preset distortion weight calculation formula to calculate the distortion weight corresponding to the third coordinate point; and calculate the product of the distortion weight and the scaling weight as the distortion-scaling weight corresponding to the third coordinate point.
[0208] In the image scaling method provided by the embodiment of the present invention, since the second coordinate point is the coordinate of the pixel point used to generate the target pixel point when the original image is scaled, and the third coordinate point is the coordinate point of the pixel point used for distortion correction of the second coordinate point, the pixel value of the target pixel point is calculated using the pixel value of the pixel point corresponding to the third coordinate point, which is equivalent to first performing distortion correction on the original image and then scaling to obtain the pixel value of the target pixel point, so that the pixel value of the target pixel point obtained is the pixel value after distortion correction and scaling. It can be seen that through this solution, a scaled image that has been distortion corrected can be obtained.
[0209] In addition, since the pixel point of the target pixel point can be calculated directly based on the pixel value of the pixel point corresponding to the third coordinate point, it is equivalent to performing distortion correction while scaling the image, which can reduce the number of processing required to obtain the scaled image that has been distortion corrected. At the same time, there is no need to first perform distortion correction on the original image to generate a distortion-corrected image, and then scale the distortion-corrected image. This can avoid reading and writing the image multiple times, reduce the consumption of read and write bandwidth, and make the generation of the scaled image more efficient.
[0210] The embodiment of the present invention further provides an electronic device, such as Fig.11 As shown, it includes a processor 1101, a communication interface 1102, a memory 1103 and a communication bus 1104, wherein the processor 1101, the communication interface 1102, and the memory 1103 communicate with each other through the communication bus 1104.
[0211] Memory 1103, used for storing computer programs;
[0212] The processor 1101 is used to implement the steps of the above-mentioned image scaling method provided by the embodiment of the present invention when executing the program stored in the memory 1103.
[0213] The communication bus mentioned in the above electronic device can be a Peripheral Component Interconnect (PCI) bus or an Extended Industry Standard Architecture (EISA) bus, etc. The communication bus can be divided into an address bus, a data bus, a control bus, etc. For ease of representation, only one thick line is used in the figure, but it does not mean that there is only one bus or one type of bus.
[0214] The communication interface is used for communication between the above electronic device and other devices.
[0215] The memory may include a random access memory (RAM) or a non-volatile memory (NVM), such as at least one disk memory. Optionally, the memory may also be at least one storage device located away from the aforementioned processor.
[0216] The above-mentioned processor can be a general-purpose processor, including a central processing unit (CPU), a network processor (NP), etc.; it can also be a digital signal processor (DSP), an application specific integrated circuit (ASIC), a field programmable gate array (FPGA) or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components.
[0217] In another embodiment of the present invention, a computer-readable storage medium is provided, in which a computer program is stored. When the computer program is executed by a processor, the steps of any of the above-mentioned image scaling methods are implemented.
[0218] In another embodiment of the present invention, a computer program product including instructions is provided. When the computer program product is run on a computer, the computer executes any one of the image scaling methods in the above embodiments.
[0219] In the above embodiments, it can be implemented in whole or in part by software, hardware, firmware or any combination thereof. When implemented by software, it can be implemented in whole or in part in the form of a computer program product. The computer program product includes one or more computer instructions. When the computer program instructions are loaded and executed on a computer, the process or function described in the embodiment of the present invention is generated in whole or in part. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium, or transmitted from one computer-readable storage medium to another computer-readable storage medium. For example, the computer instructions can be transmitted from a website site, computer, server or data center to another website site, computer, server or data center by wired (e.g., coaxial cable, optical fiber, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.). The computer-readable storage medium can be any available medium that a computer can access or a data storage device such as a server or data center that includes one or more available media integrated. The available medium can be a magnetic medium (e.g., a floppy disk, a hard disk, a tape), an optical medium (e.g., a DVD), or a semiconductor medium (e.g., a solid-state hard disk Solid State Disk (SSD)), etc.
[0220] It should be noted that, in this article, relational terms such as first and second, etc. are only used to distinguish one entity or operation from another entity or operation, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Moreover, the terms "include", "comprise" or any other variants thereof are intended to cover non-exclusive inclusion, so that a process, method, article or device including a series of elements includes not only those elements, but also other elements not explicitly listed, or also includes elements inherent to such process, method, article or device. In the absence of further restrictions, the elements defined by the sentence "comprise a ..." do not exclude the presence of other identical elements in the process, method, article or device including the elements.
[0221] Each embodiment in this specification is described in a related manner, and the same or similar parts between the embodiments can be referred to each other, and each embodiment focuses on the differences from other embodiments. In particular, for the device, equipment, and system embodiments, since they are basically similar to the method embodiments, the description is relatively simple, and the relevant parts can be referred to the partial description of the method embodiments.
[0222] The above description is only a preferred embodiment of the present invention and is not intended to limit the protection scope of the present invention. Any modification, equivalent replacement, improvement, etc. made within the spirit and principle of the present invention are included in the protection scope of the present invention.
Claims
1. An image scaling method, It is characterized in that The method comprises: Obtain the original image to be processed; Calculate the pixel value of the target pixel in the target image after scaling the original image to generate the target image; wherein the pixel value of each target pixel is obtained by: Determine, according to the first coordinate point of the target pixel point in the target image, a second coordinate point corresponding to the target pixel point in the original image; wherein the second coordinate point corresponding to the target pixel point is: a coordinate point of a pixel point used to generate the target pixel point when scaling the original image; Determine a third coordinate point corresponding to the second coordinate point in the original image; wherein the third coordinate point corresponding to the second coordinate point is: a coordinate point of a pixel point used for performing distortion correction on the second coordinate point; According to the second coordinate point and the third coordinate point, the distortion-scaling weight corresponding to the third coordinate point is calculated; or, the distortion-scaling weight corresponding to the coordinate of the target pixel point is searched in a preset distortion-scaling table as the distortion-scaling weight corresponding to the third coordinate point; wherein the weight corresponding to each coordinate point in the distortion-scaling table is determined in advance based on the second coordinate point and the third coordinate point corresponding to the coordinate point; If the third coordinate point is single, then calculating the product of the pixel value of the pixel point corresponding to the third coordinate point in the original image and the distortion-scaling weight corresponding to the third coordinate point as the pixel value of the target pixel point; If there are multiple third coordinate points, based on the distortion-scaling weights corresponding to the third coordinate points, the pixel values of the pixel points corresponding to the third coordinate points in the original image are weighted summed to obtain the pixel value of the target pixel point.
2. The method according to claim 1, It is characterized in that The determining, according to the first coordinate point of the target pixel point in the target image, a second coordinate point corresponding to the target pixel point in the original image comprises: Determine a first coordinate point of the target pixel point in the target image; Based on a preset scaling mapping relationship, a coordinate point mapped by the first coordinate point in the original image is determined as a second coordinate point corresponding to the target pixel point.
3. The method according to claim 2, It is characterized in that The step of determining, based on a preset scaling mapping relationship, a coordinate point mapped by the first coordinate point in the original image as a second coordinate point corresponding to the target pixel point comprises: Calculating a ratio of a horizontal coordinate of the first coordinate point to a preset horizontal zoom ratio to obtain a first zoomed horizontal coordinate, and calculating a ratio of a vertical coordinate of the first coordinate point to a preset vertical zoom ratio to obtain a first zoomed vertical coordinate; Based on the first scaled horizontal coordinate and the first scaled vertical coordinate, a coordinate point in the original image to which the first coordinate point is mapped is determined as a second coordinate point corresponding to the target pixel point.
4. The method according to claim 3, It is characterized in that The step of determining, based on the first scaled horizontal coordinate and the first scaled vertical coordinate, a coordinate point mapped by the first coordinate point in the original image as a second coordinate point corresponding to the target pixel point includes: Determine at least one coordinate point mapped by the first coordinate point in the original image as a second coordinate point corresponding to the target pixel point; Among them, each determined coordinate point is: the horizontal coordinate is the second scaled horizontal coordinate or the third scaled horizontal coordinate, and the vertical coordinate is the coordinate point of the second scaled vertical coordinate or the third scaled vertical coordinate; the second scaled horizontal coordinate is: a maximum integer less than or equal to the first scaled horizontal coordinate; the third scaled horizontal coordinate is a minimum integer greater than the second scaled horizontal coordinate, and the second scaled vertical coordinate is: a maximum integer less than or equal to the first scaled vertical coordinate; the third scaled vertical coordinate is a minimum integer greater than the second scaled vertical coordinate.
5. The method according to claim 1, It is characterized in that The determining of a third coordinate point corresponding to the second coordinate point in the original image includes: Determine a distance between the second coordinate point and the coordinate origin of the original image, and determine a distortion adjustment parameter of the second coordinate point based on the distance; Calculating the product of the abscissa of the second coordinate point and the distortion adjustment parameter to obtain a first distortion abscissa, and calculating the product of the ordinate of the second coordinate point and the distortion adjustment parameter to obtain a first distortion ordinate; Based on the first distorted horizontal coordinate and the first distorted vertical coordinate, a third coordinate point corresponding to the second coordinate point is determined.
6. The method according to claim 5, It is characterized in that The determining, based on the first distorted horizontal coordinate and the first distorted vertical coordinate, a third coordinate point corresponding to the second coordinate point includes: Determine at least one coordinate point corresponding to the second coordinate point as a third coordinate point corresponding to the second coordinate point; Among them, at least one determined coordinate point is: the horizontal coordinate is the second distortion horizontal coordinate or the third distortion horizontal coordinate, and the vertical coordinate is the coordinate point of the second distortion vertical coordinate or the third distortion vertical coordinate; the second distortion horizontal coordinate is: a maximum integer less than or equal to the first distortion horizontal coordinate; the third distortion horizontal coordinate is a minimum integer greater than the second distortion horizontal coordinate, the second distortion vertical coordinate is: a maximum integer less than or equal to the first distortion vertical coordinate; the third distortion vertical coordinate is a minimum integer greater than the second distortion vertical coordinate.
7. The method according to claim 1, It is characterized in that The calculating, according to the second coordinate point and the third coordinate point, the distortion-scaling weight corresponding to the third coordinate point includes: Substituting the coordinates of the second coordinate point into a preset scaling weight calculation formula to calculate the scaling weight corresponding to the second coordinate point; Substituting the coordinates of the third coordinate point into a preset distortion weight calculation formula to calculate the distortion weight corresponding to the third coordinate point; The product of the distortion weight and the scaling weight is calculated as the distortion-scaling weight corresponding to the third coordinate point.
8. An image scaling device, It is characterized in that The device comprises: An image acquisition module, used to acquire the original image to be processed; An image generation module, used for calculating the pixel value of a target pixel point in a target image after scaling the original image, so as to generate the target image; Wherein, the image generation module is specifically used to determine, for each target pixel point, the second coordinate point corresponding to the target pixel point in the original image according to the first coordinate point of the target pixel point in the target image; wherein the second coordinate point corresponding to the target pixel point is: the coordinate point of the pixel point used to generate the target pixel point when the original image is scaled; the coordinate point of the pixel point used to generate the target pixel point when the original image is scaled; determine the third coordinate point corresponding to the second coordinate point in the original image; wherein the third coordinate point corresponding to the second coordinate point is: the coordinate point of the pixel point used for distortion correction of the second coordinate point; and calculate the pixel value of the target pixel point using the pixel value of the pixel point corresponding to the third coordinate point; The image generation module comprises: A weight acquisition submodule, wherein the weight acquisition submodule includes: a weight calculation unit and a weight search unit; the weight calculation unit is used to calculate the distortion-scaling weight corresponding to the third coordinate point according to the second coordinate point and the third coordinate point; or the weight search unit is used to search for the distortion-scaling weight corresponding to the coordinate of the target pixel point in a preset distortion-scaling table as the distortion-scaling weight corresponding to the third coordinate point; wherein the weight corresponding to each coordinate point in the distortion-scaling table is: determined in advance based on the second coordinate point and the third coordinate point corresponding to the coordinate point; The pixel calculation submodule calculates the pixel value of the pixel point corresponding to the third coordinate point in the original image and the product of the distortion-scaling weight corresponding to the third coordinate point as the pixel value of the target pixel point if the third coordinate point is single; if the third coordinate point is multiple, the pixel values of the pixel points corresponding to each third coordinate point in the original image are weighted summed based on the distortion-scaling weight corresponding to each third coordinate point to obtain the pixel of the target pixel point.
9. The device according to claim 8, It is characterized in that The image generation module comprises: A first determination submodule, used to determine a first coordinate point of the target pixel point in the target image; A second determination submodule is used to determine, based on a preset scaling mapping relationship, a coordinate point mapped by the first coordinate point in the original image as a second coordinate point corresponding to the target pixel point; Wherein, the second determining submodule includes: a coordinate calculation unit, configured to calculate a ratio of a horizontal coordinate of the first coordinate point to a preset horizontal zoom ratio to obtain a first zoomed horizontal coordinate, and to calculate a ratio of a vertical coordinate of the first coordinate point to a preset vertical zoom ratio to obtain a first zoomed vertical coordinate; a coordinate determining unit, configured to determine, based on the first scaled horizontal coordinate and the first scaled vertical coordinate, a coordinate point mapped by the first coordinate point in the original image as a second coordinate point corresponding to the target pixel point; Wherein, the coordinate determination unit is specifically used to determine at least one coordinate point mapped by the first coordinate point in the original image as the second coordinate point corresponding to the target pixel point; wherein each determined coordinate point is a coordinate point whose horizontal coordinate is the second scaled horizontal coordinate or the third scaled horizontal coordinate, and whose vertical coordinate is the second scaled vertical coordinate or the third scaled vertical coordinate; the second scaled horizontal coordinate is a maximum integer less than or equal to the first scaled horizontal coordinate; the third scaled horizontal coordinate is a minimum integer greater than the second scaled horizontal coordinate, and the second scaled vertical coordinate is a maximum integer less than or equal to the first scaled vertical coordinate; the third scaled vertical coordinate is a minimum integer greater than the second scaled vertical coordinate; Wherein, the image generation module includes: a parameter determination submodule, used to determine the distance between the second coordinate point and the coordinate origin of the original image, and based on the distance, determine the distortion adjustment parameter of the second coordinate point; A coordinate calculation submodule, configured to calculate the product of the abscissa of the second coordinate point and the distortion adjustment parameter to obtain a first distorted abscissa, and calculate the product of the ordinate of the second coordinate point and the distortion adjustment parameter to obtain a first distorted ordinate; a coordinate determination submodule, configured to determine a third coordinate point corresponding to the second coordinate point based on the first distorted horizontal coordinate and the first distorted vertical coordinate; The coordinate determination submodule is specifically used to determine at least one coordinate point corresponding to the second coordinate point as the third coordinate point corresponding to the second coordinate point; wherein the at least one coordinate point determined is a coordinate point whose abscissa is the second distorted abscissa or the third distorted abscissa and whose ordinate is the second distorted ordinate or the third distorted ordinate; the second distorted abscissa is a maximum integer less than or equal to the first distorted abscissa; the third distorted abscissa is a minimum integer greater than the second distorted abscissa, and the second distorted ordinate is a maximum integer less than or equal to the first distorted ordinate; the third distorted ordinate is a minimum integer greater than the second distorted ordinate; Among them, the weight calculation unit is specifically used to substitute the coordinates of the second coordinate point into a preset scaling weight calculation formula to calculate the scaling weight corresponding to the second coordinate point; substitute the coordinates of the third coordinate point into a preset distortion weight calculation formula to calculate the distortion weight corresponding to the third coordinate point; calculate the product of the distortion weight and the scaling weight as the distortion-scaling weight corresponding to the third coordinate point.
10. An electronic device, It is characterized in that It includes a processor, a communication interface, a memory and a communication bus, wherein the processor, the communication interface and the memory communicate with each other through the communication bus; Memory, used to store computer programs; A processor, for implementing the method steps described in any one of claims 1 to 7 when executing a program stored in a memory.
11. A computer-readable storage medium, It is characterized in that The computer-readable storage medium stores a computer program, and when the computer program is executed by a processor, the method steps described in any one of claims 1 to 7 are implemented.
Citation Information
Patent Citations
Image zooming method and device, computer equipment and storage medium
CN109903224A
Fisheye image correction method, electronic equipment and storage medium
CN110570367A