CN114170091A - Image scaling method and device, electronic equipment and storage medium - Google Patents

Image scaling method and device, electronic equipment and storage medium Download PDF

Info

Publication number
CN114170091A
CN114170091A CN202111632868.XA CN202111632868A CN114170091A CN 114170091 A CN114170091 A CN 114170091A CN 202111632868 A CN202111632868 A CN 202111632868A CN 114170091 A CN114170091 A CN 114170091A
Authority
CN
China
Prior art keywords
coordinate point
distortion
scaling
point
coordinate
Prior art date
Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
Pending
Application number
CN202111632868.XA
Other languages
Chinese (zh)
Inventor
黄崇基
Current Assignee (The listed assignees may be inaccurate. Google has not performed a legal analysis and makes no representation or warranty as to the accuracy of the list.)
Hangzhou Hikrobot Technology Co Ltd
Original Assignee
Hangzhou Hikrobot Technology Co Ltd
Priority date (The priority date is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the date listed.)
Filing date
Publication date
Application filed by Hangzhou Hikrobot Technology Co Ltd filed Critical Hangzhou Hikrobot Technology Co Ltd
Priority to CN202111632868.XA priority Critical patent/CN114170091A/en
Publication of CN114170091A publication Critical patent/CN114170091A/en
Pending legal-status Critical Current

Links

Images

Classifications

    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T3/00Geometric image transformations in the plane of the image
    • G06T3/40Scaling of whole images or parts thereof, e.g. expanding or contracting
    • GPHYSICS
    • G06COMPUTING; CALCULATING OR COUNTING
    • G06TIMAGE DATA PROCESSING OR GENERATION, IN GENERAL
    • G06T5/00Image enhancement or restoration
    • G06T5/80Geometric correction

Landscapes

  • Physics & Mathematics (AREA)
  • General Physics & Mathematics (AREA)
  • Engineering & Computer Science (AREA)
  • Theoretical Computer Science (AREA)
  • Image Processing (AREA)

Abstract

The embodiment of the invention provides an image scaling method, an image scaling device, electronic equipment and a storage medium, which are applied to the technical field of data processing. The method comprises the following steps: acquiring an original image to be processed; calculating pixel values of target pixel points in the target image after the original image is zoomed so as to generate a target image; the pixel value of each target pixel point is obtained through the following modes: 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; determining a third coordinate point corresponding to the second coordinate point in the original image; and calculating the pixel value of the target pixel point by using the pixel value of the pixel point corresponding to the third coordinate point. By the scheme, the zoomed image subjected to distortion correction can be quickly generated.

Description

Image scaling method and device, electronic equipment and storage medium
Technical Field
The present invention relates to the field of data processing technologies, and in particular, to an image scaling method and apparatus, an electronic device, and a storage medium.
Background
With the development of the technology, the intelligent processing algorithm aiming at the image is widely applied to various industries. Such as smart surveillance, smart gate entry, etc.
Generally, 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 acquired by the image acquisition device, but the original image is scaled to obtain a scaled image
However, due to the characteristics of the lens, the installation distance, and the like, the original image acquired by the image acquisition device has a distortion phenomenon, so that an object in the original image has distortion or deformation relative to a real object. Therefore, how to quickly generate a scaled image with distortion correction is an urgent problem to be solved.
Disclosure of Invention
An object of the embodiments of the present invention is to provide an image scaling method, apparatus, electronic device and storage medium, so as to quickly generate a scaled image with distortion correction performed thereon. The specific technical scheme is as follows:
in a first aspect, an embodiment of the present invention provides an image scaling method, where the method includes:
acquiring an original image to be processed;
calculating pixel values of target pixel points in the target image after the original image is zoomed so as to generate the target image; the pixel value of each target pixel point is obtained through the following modes:
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; wherein, the second coordinate point corresponding to the target pixel point is: when the original image is subjected to zooming processing, generating a coordinate point of a pixel point of the target pixel point;
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 distortion correction of the second coordinate point;
and calculating the pixel value of the target pixel point by using the pixel value of the pixel point corresponding to the third coordinate point.
Optionally, the determining, according to the first coordinate point of the target pixel point in the target image, a second coordinate point of the target pixel point in the original image includes:
determining a first coordinate point of the target pixel point in the target image;
and determining a coordinate point mapped by the first coordinate point in the original image based on a preset scaling mapping relation, and taking the coordinate point as a second coordinate point corresponding to the target pixel point.
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 determining, based on a preset scaling mapping relationship, a coordinate point mapped by the first coordinate point in the original image, where the second coordinate point includes a coordinate point corresponding to the target pixel point
Calculating the ratio of the abscissa of the first coordinate point to a preset horizontal scaling ratio to obtain a first scaling abscissa, and calculating the ratio of the ordinate of the first coordinate point to a preset vertical scaling ratio to obtain a first scaling ordinate;
and determining a coordinate point mapped by the first coordinate point in the original image as a second coordinate point corresponding to the target pixel point based on the first scaling abscissa and the first scaling ordinate.
Optionally, the determining, based on the first scaling abscissa and the first scaling ordinate, 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:
determining 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;
wherein each determined coordinate point is: the abscissa is a second scaling abscissa or a third scaling abscissa, and the ordinate is a coordinate point of a second scaling ordinate or a third scaling ordinate; the second scaling abscissa is: a maximum integer less than or equal to the first scaling abscissa; the third scaling abscissa is the smallest integer larger than the second scaling abscissa, and the second scaling ordinate is: a maximum integer less than or equal to the first scaling ordinate; the third scaling ordinate is a smallest integer larger than the second scaling ordinate.
Optionally, the determining a third coordinate point corresponding to the second coordinate point in the original image includes:
determining the distance between the second coordinate point and the original image coordinate origin, and determining the distortion adjusting parameter of the second coordinate point based on the distance;
calculating the product of the abscissa of the second coordinate point and the distortion adjusting parameter to obtain a first distortion abscissa, and calculating the product of the ordinate of the second coordinate point and the distortion adjusting parameter to obtain a first distortion ordinate;
and determining a third coordinate point corresponding to the second coordinate point based on the first distortion abscissa and the first distortion ordinate.
Optionally, the determining, based on the first distortion abscissa and the first distortion ordinate, a third coordinate point corresponding to the second coordinate point includes:
determining 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: the abscissa is a second distortion abscissa or a third distortion abscissa, and the ordinate is a coordinate point of a second distortion ordinate or a third distortion ordinate; the second distortion abscissa is: a maximum integer less than or equal to the first distortion abscissa; the third distortion abscissa is a minimum integer greater than the second distortion abscissa, and the second distortion ordinate is: a maximum integer less than or equal to the first distortion ordinate; the third distortion ordinate is the smallest integer greater than the second distortion ordinate.
Optionally, the 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:
obtaining distortion-scaling weights corresponding to the third coordinate points;
if the third coordinate point is single, 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, and taking the product as the pixel value of the target pixel point;
and if the number of the third coordinate points is multiple, carrying out weighted summation on the pixel values of the pixel points corresponding to the third coordinate points in the original image based on the distortion-scaling weights corresponding to the third coordinate points to obtain the pixel value of the target pixel point.
Optionally, the obtaining distortion-scaling weights corresponding to the third coordinate points includes:
calculating distortion-scaling weights corresponding to the third coordinate points according to the second coordinate points and the third coordinate points; and/or the presence of a gas in the gas,
searching distortion-scaling weights corresponding to the coordinates of the target pixel points in a preset distortion-scaling table, and using the distortion-scaling weights as distortion-scaling weights corresponding to the third coordinate points; wherein, the weight corresponding to each coordinate point in the distortion-scaling table is as follows: the coordinate point is determined in advance based on the second coordinate point and the third coordinate point corresponding to the coordinate point.
Optionally, the calculating, according to the second coordinate point and the third coordinate point, a 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, and calculating the scaling weight corresponding to the second coordinate point;
substituting the coordinates of the third coordinate point into a preset distortion weight calculation formula, and calculating the distortion weight corresponding to the third coordinate point;
and calculating the product of the distortion weight and the scaling weight as the distortion-scaling weight corresponding to the third coordinate point.
In a second aspect, an embodiment of the present invention provides an image scaling apparatus, including:
the image acquisition module is used for acquiring an original image to be processed;
the image generation module is used for calculating the pixel value of a target pixel point in a target image after the original image is zoomed so as to generate the target image;
the image generation module is specifically configured to determine, for each target pixel point, a second coordinate point corresponding to the target pixel point in the original image according to a first coordinate point of the target pixel point in the target image; wherein, the second coordinate point corresponding to the target pixel point is: when the original image is subjected to zooming processing, generating a coordinate point of a pixel point of the target pixel point; when the original image is subjected to zooming processing, generating a coordinate point of a pixel point of the target pixel point; 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 distortion correction of the second coordinate point; calculating the pixel value of the target pixel point by using the pixel value of the pixel point corresponding to the third coordinate point;
optionally, the image generating module includes:
the first determining submodule is used for determining a first coordinate point of the target pixel point in the target image;
the second determining submodule is used for determining a coordinate point mapped by the first coordinate point in the original image based on a preset scaling mapping relation, and the coordinate point is used as a second coordinate point corresponding to the target pixel point;
optionally, the second determining sub-module includes:
the coordinate calculation unit is used for calculating the ratio of the abscissa of the first coordinate point to a preset horizontal scaling ratio to obtain a first scaling abscissa, and calculating the ratio of the ordinate of the first coordinate point to a preset vertical scaling ratio to obtain a first scaling ordinate;
a coordinate determination unit, configured to determine, based on the first scaling abscissa and the first scaling ordinate, a coordinate point mapped by the first coordinate point in the original image as a second coordinate point corresponding to the target pixel point;
optionally, the coordinate determining unit is specifically configured to 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; wherein each determined coordinate point is: the abscissa is a second scaling abscissa or a third scaling abscissa, and the ordinate is a coordinate point of a second scaling ordinate or a third scaling ordinate; the second scaling abscissa is: a maximum integer less than or equal to the first scaling abscissa; the third scaling abscissa is the smallest integer larger than the second scaling abscissa, and the second scaling ordinate is: a maximum integer less than or equal to the first scaling ordinate; the third scaling ordinate is the smallest integer larger than the second scaling ordinate;
optionally, the image generating module includes:
the parameter determining submodule is used for determining the distance between the second coordinate point and the original image coordinate origin and determining the distortion adjusting parameter of the second coordinate point based on the distance;
the coordinate calculation submodule is used for calculating the product of the abscissa of the second coordinate point and the distortion adjusting parameter to obtain a first distortion abscissa, and calculating the product of the ordinate of the second coordinate point and the distortion adjusting parameter to obtain a first distortion ordinate;
the coordinate determination submodule is used for determining a third coordinate point corresponding to the second coordinate point based on the first distortion abscissa and the first distortion ordinate;
optionally, the coordinate determination sub-module is specifically configured 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: the abscissa is a second distortion abscissa or a third distortion abscissa, and the ordinate is a coordinate point of a second distortion ordinate or a third distortion ordinate; the second distortion abscissa is: a maximum integer less than or equal to the first distortion abscissa; the third distortion abscissa is a minimum integer greater than the second distortion abscissa, and the second distortion ordinate is: a maximum integer less than or equal to the first distortion ordinate; the third distortion ordinate is the smallest integer greater than the second distortion ordinate.
Optionally, the image generating module includes:
the weight obtaining submodule is used for obtaining distortion-scaling weights corresponding to the third coordinate points;
if the third coordinate point is single, calculating the product of the pixel value of the pixel point corresponding to the third coordinate point and the distortion-scaling weight corresponding to the third coordinate point in the original image as the pixel value of the target pixel point; and if the number of the third coordinate points is multiple, carrying out weighted summation on pixel values of pixel points corresponding to the third coordinate points in the original image based on distortion-scaling weights corresponding to the third coordinate points to obtain pixels of the target pixel points.
Optionally, the weight obtaining sub-module includes:
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 the presence of a gas in the gas,
the weight searching unit is used for searching distortion-scaling weights corresponding to the coordinates of the target pixel points in a preset distortion-scaling table and taking the distortion-scaling weights as distortion-scaling weights corresponding to the third coordinate points; wherein, the weight corresponding to each coordinate point in the distortion-scaling table is as follows: the coordinate point is determined in advance based on the second coordinate point and the third coordinate point corresponding to the coordinate point.
Optionally, the weight calculating unit is specifically configured to substitute the coordinates of the second coordinate point into a preset scaling weight calculation formula, and calculate a scaling weight corresponding to the second coordinate point; substituting the coordinates of the third coordinate point into a preset distortion weight calculation formula, and calculating the distortion weight corresponding to the third coordinate point; and calculating the product of the distortion weight and the scaling weight as the distortion-scaling weight corresponding to the third coordinate point.
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, where the processor and the communication interface complete communication between the memory and the processor through the communication bus;
a memory for storing a computer program;
a processor for implementing the method steps provided by the first aspect when executing the program stored in the memory.
In a fourth aspect, the present invention provides a computer-readable storage medium, in which a computer program is stored, and the computer program, when executed by a processor, implements the method steps provided in the first aspect.
The embodiment of the invention has the following beneficial effects:
in the image scaling method provided in the embodiment of the present invention, for a target pixel point in a target image after an original image is scaled, a second coordinate point corresponding to a target pixel point is determined, a third coordinate point corresponding to the second coordinate point is further determined, and finally a pixel value of the target pixel point is calculated by using a pixel value corresponding to the third coordinate point, since the second coordinate point is a coordinate of a pixel point used for generating the target pixel point when the original image is scaled, and the third coordinate point is a coordinate of a pixel point used for performing distortion correction on the second coordinate point, the pixel value of the target pixel point is calculated by using the pixel value corresponding to the pixel point of the third coordinate point, which is equivalent to performing distortion correction on the original image first and then performing scaling to obtain the pixel value of the target pixel point, so that the obtained pixel value of the target pixel point is the pixel value after distortion correction and scaling, therefore, the zoomed image subjected to distortion correction can be obtained through the scheme.
In addition, because the pixel values of the pixel points corresponding to the third coordinate points can be directly based on, the pixel points of the target pixel points are calculated, which is equivalent to performing distortion correction while zooming the image, the processing quantity required for obtaining the zoomed image subjected to distortion correction can be reduced, and meanwhile, the original image does not need to be subjected to distortion correction to generate the image subjected to distortion correction and then the image subjected to distortion correction is zoomed, so that the image can be prevented from being read and written for many times, the read-write bandwidth consumption is reduced, and the efficiency of generating the zoomed image is higher.
Of course, not all of the advantages described above need to be achieved at the same time in the practice of any one product or method of the invention.
Drawings
In order to more clearly illustrate the embodiments of the present invention or the technical solutions in the prior art, the drawings used in the description of the embodiments or the prior art will be briefly described below, and it is obvious that the drawings in the following description are only some embodiments of the present invention, and it is obvious for those skilled in the art that other embodiments can be obtained by using the drawings without creative efforts.
FIG. 1 is a schematic diagram of distortion provided by an embodiment of the present invention;
FIG. 2 is a schematic flow chart diagram illustrating an image scaling method according to an embodiment of the present invention;
fig. 3 is a schematic diagram of a pixel point calculation method according to an embodiment of the present invention;
FIG. 4 is another flowchart of an image scaling method according to an embodiment of the present invention;
FIG. 5 is a schematic diagram of a scaling map according to an embodiment of the present invention;
FIG. 6 is another flowchart of an image scaling method according to an embodiment of the present invention;
FIG. 7 is a diagram illustrating distortion mapping provided by an embodiment of the present invention;
FIG. 8 is another flowchart of an image scaling method according to an embodiment of the present invention;
FIG. 9 is a diagram illustrating a distortion-scaling map according to an embodiment of the present invention;
FIG. 10 is a schematic structural diagram of an image scaling apparatus according to an embodiment of the present invention;
fig. 11 is a schematic structural diagram of an electronic device according to an embodiment of the present invention.
Detailed Description
The technical solutions in the embodiments of the present invention will be clearly and completely described below with reference to the drawings in the embodiments of the present invention, and it is obvious that the described embodiments are only a part of the embodiments of the present invention, and not all of the embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present invention.
To more clearly illustrate the technical solution of the embodiment of the present invention, the picture distortion is briefly introduced.
Distortion caused by a lens of an image acquisition device is generally divided into radial distortion and tangential distortion, for convenience of description, distortion related to the technical scheme of the embodiment of the invention is introduced only by radial distortion, and tangential distortion and radial distortion are only different in distortion direction and are not introduced independently. The radial distortion is a distortion distributed along the radial direction of the lens, and further, can be divided into barrel distortion and pincushion distortion, as shown in the distortion diagram of fig. 1, the left half image is pincushion distortion, and the right half image is barrel distortion. Radial distortion is distortion distributed along the radius of the lens, and occurs because rays are bent more far from the center of the lens than near the center. Radial distortion is more pronounced in inexpensive lenses.
In order to obtain a scaled image with distortion correction quickly, embodiments of the present invention provide an image scaling method and apparatus, an electronic device, and a storage medium.
As shown in fig. 2, an image scaling method provided in an embodiment of the present invention may include the following steps:
s201, acquiring an original image to be processed;
the original image is an image that needs to be scaled, and the original image may be acquired in a manner that is combined with an actual usage scene, for example, in a scene with a high implementation requirement, an image acquired by the image acquisition device may be acquired in real time as the original image to be processed. For scenes with low real-time requirements, the original image to be processed can be read from the data set/database.
The scenes with higher requirements of the above embodiment may include various application scenes of face recognition and human body recognition, such as intelligent access control, regional protection, and the like, and at this time, the original image may be a human body image, a face image, and the like acquired by the image acquisition device in real time. The scenarios with low requirements of the above embodiments may include scenarios such as machine learning model training, and the like. The raw image may be an image read from a set of training samples.
S202, calculating the pixel value of a target pixel point in the target image after the original image is zoomed so as to generate the target image.
The target image is an image obtained by scaling the original image, and in order to obtain the target image, the pixel value of a target pixel point in the target image needs to be calculated. It should be noted that the target pixel in the target image is any pixel included in the target image, for example, the target image includes N pixels, and the N pixels are all the target pixels.
Different from the related art, the method for obtaining the target image by scaling the original image is based on the mode that the target image is obtained, in the embodiment of the invention, calculation can be carried out aiming at each target pixel point in the target image, and the pixel value of each pixel point in the target image is calculated by utilizing the pixel value of each pixel point in the original image.
Optionally, in a manner of calculating a pixel value of a target pixel, a pixel calculation manner shown in fig. 3 may be adopted for each pixel in a target image, and the pixel value of the target pixel is calculated, where the pixel calculation manner shown in fig. 3 includes the following steps:
s202-1, 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; wherein, the second coordinate point corresponding to the target pixel point is: and when the original image is subjected to zooming processing, generating a coordinate point of a pixel point of the target pixel point.
In this step, the second coordinate point corresponding to the target pixel point is: and when the original image is subjected to zooming processing, generating a coordinate point of a pixel point of the target pixel point.
Under the condition that the scaling ratio is known, the pixel points in the image before scaling, which correspond to the pixel points in the image after scaling, are related to the coordinates of the pixel points in the image after scaling, namely, the coordinate points of the pixel points in the image after scaling, so that the second coordinate points, which correspond to the target pixel points in the original image, can be determined according to the first coordinate points of the target pixel points in the target image.
S202-2, determining a third coordinate point corresponding to the second coordinate point in the original image; wherein, the third coordinate point that the second coordinate point corresponds to is: a coordinate point of a pixel point used for distortion correction of the second coordinate point;
in this step, the third coordinate points corresponding to the second coordinate points are: and the coordinate point of the pixel point is used for carrying out distortion correction on the second coordinate point. Under the condition that the distortion parameters are known, the pixel point utilized when each pixel point before distortion correction is calibrated is related to the coordinate point of the pixel point before distortion correction, namely the coordinate of the pixel point in the image after distortion, so that the third coordinate point corresponding to the second coordinate point can be determined according to the coordinate of the second coordinate point.
S202-3, calculating the pixel value of the target pixel point by using the pixel value of the pixel point corresponding to the third coordinate point.
After the third coordinate point is determined, the pixel value of the target pixel point can be calculated by using the pixel value of the pixel point corresponding to the third coordinate point. When the pixel value is the RGB value, the R value of the target pixel point may 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 may 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 may be determined based on the B value of the pixel point corresponding to the third coordinate point, so as to obtain the RGB value of the target pixel point.
In order to obtain a zoomed image subjected to distortion correction, in the related art, a third coordinate point is used to correspond to a pixel value of a pixel point, distortion correction is performed first, then the zoomed image subjected to distortion correction is subjected to zoom processing, that is, the pixel value of a target pixel point is calculated by using the pixel value of a second coordinate point in the zoomed image subjected to distortion correction, and finally the zoomed image subjected to distortion correction can be obtained.
In this step, the pixel value of the target pixel point is calculated by directly using the pixel value of the pixel point corresponding to the third coordinate point, instead of performing distortion calibration first and then performing scaling processing. The specific implementation process will be described in detail in the following embodiments, and will not be described herein again.
In the image scaling method provided by the embodiment of the invention, since the second coordinate point is a coordinate of a pixel point used for generating the target pixel point when the original image is scaled, and the third coordinate point is a coordinate point of a pixel point used for distortion correction of the second coordinate point, the pixel value of the target pixel point is calculated by using the pixel value of the pixel point corresponding to the third coordinate point, which is equivalent to performing distortion correction on the original image and then scaling to obtain the pixel value of the target pixel point, so that the obtained pixel value of the target pixel point is a pixel value after distortion correction and scaling.
In addition, because the pixel values of the pixel points corresponding to the third coordinate points can be directly based on, the pixel points of the target pixel points are calculated, which is equivalent to performing distortion correction while zooming the image, the processing quantity required for obtaining the zoomed image subjected to distortion correction can be reduced, and meanwhile, the original image does not need to be subjected to distortion correction to generate the image subjected to distortion correction and then the image subjected to distortion correction is zoomed, so that the image can be prevented from being read and written for many times, the read-write bandwidth consumption is reduced, and the efficiency of generating the zoomed image is higher.
Based on the embodiment of fig. 3, as shown in fig. 4, in the image scaling method provided by another embodiment of the present invention, the above-mentioned S202-1 may include steps S401-S402:
s401, determining a first coordinate point of the target pixel point in the target image;
and the first coordinate point is a pixel coordinate point of the target pixel point in the target image.
S402, determining a coordinate point of the first coordinate point mapped in the original image based on a preset scaling mapping relation, and taking the coordinate point as a second coordinate point corresponding to the target pixel point.
The preset scaling mapping relationship may be a preset coordinate mapping relationship corresponding to a scaling ratio required by the original image. As can be seen from the foregoing, the image size of the original image and the image size to be scaled are both known in advance, which means that the scaling ratio required for the original image is also known in advance. The required scaling of the original image may include a preset horizontal scaling ratio and a preset vertical scaling ratio.
Wherein, 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. As is exemplary. The image size of the original image is 1024 × 768, the image size of the scaled image is 512 × 512, and then the vertical scaling ratio 512/1024 ≈ 0.5 and the horizontal scaling ratio 512/768 ≈ 0.7.
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 indicates that the length and the width of the original image are scaled according to the ratio.
In one implementation, the step S402 may include the following steps a1-a 2:
step A1: and calculating the ratio of the abscissa of the first coordinate point to a preset horizontal scaling ratio to obtain a first scaling abscissa, and calculating the ratio of the ordinate of the first coordinate point to a preset vertical scaling ratio to obtain a first scaling ordinate.
The first scaling abscissa and the first scaling ordinate can be respectively calculated by adopting the following formulas:
Figure BDA0003441561770000121
Figure BDA0003441561770000122
wherein x is an abscissa of the first coordinate point, y is an ordinate of the first coordinate point, x 'is a first scaling abscissa, y' is a first scaling ordinate, W is a width scaling, and H is a length scaling.
After the first coordinate point is determined, the first scaling abscissa and the first scaling ordinate may be calculated based on the coordinate of the first coordinate point according to the above calculation formula. For convenience of description, a point whose abscissa is the first scaling abscissa and whose ordinate is the first scaling ordinate may be used as the scaling mapping point corresponding to the first coordinate point.
Exemplarily, fig. 5 is a schematic diagram of the scaling mapping provided by the embodiment of the present invention, where S1 is a first coordinate point, the coordinates are (x, y), the coordinates of S1 are substituted into the above calculation formula, and the coordinates (x0, y0) are obtained through calculation, where x0 is a first scaling abscissa, and y0 is a first scaling ordinate.
Step A2: and determining a coordinate point mapped by the first coordinate point in the original image as a second coordinate point corresponding to the target pixel point based on the first scaling abscissa and the first scaling ordinate.
After the first scaling abscissa and the first scaling ordinate are obtained through calculation, a coordinate point mapped by the first coordinate point in the original image may be determined as a second coordinate point corresponding to the target pixel point based on the first scaling abscissa and the first scaling ordinate.
In one implementation, at least one coordinate point to which the first coordinate point is mapped in the original image may be determined as the second coordinate point corresponding to the target pixel point.
Wherein each determined coordinate point is: the abscissa is a second scaling abscissa or a third scaling abscissa, and the ordinate is a coordinate point of a second scaling ordinate or a third scaling ordinate; the second zoom abscissa is: a maximum integer less than or equal to the first zoom abscissa; the third scaling abscissa is the smallest integer greater than the second scaling abscissa, and the second scaling ordinate is: a maximum integer less than or equal to the first scaling ordinate; the third scaling ordinate is the smallest integer larger than the second scaling ordinate.
Optionally, the maximum integer less than or equal to the first scaling abscissa may be determined as the second scaling abscissa, the maximum integer less than or equal to the first scaling ordinate is determined as the second scaling ordinate, then the minimum integer greater than the second scaling abscissa is calculated as the third scaling abscissa, the minimum integer greater than the second scaling ordinate is calculated as the third scaling ordinate, and finally at least one coordinate point mapped by the first coordinate point in the original image is determined as the second coordinate point corresponding to the target pixel point.
In order to determine the maximum integer less than or equal to the first scaling abscissa, the rounding operation may be performed on the first scaling abscissa to obtain the second scaling abscissa. Similarly, the rounding operation may be performed on the first scaling ordinate to obtain the second scaling ordinate. The first scaling ordinate is the same as the manner in which the rounding operation is performed on the first scaling abscissa, and only the first scaling abscissa will be described below, and the manner in which the rounding operation is performed on the first scaling ordinate refers to the manner in which the rounding operation is performed on the first scaling abscissa.
The value calculation includes both rounding-down and rounding-up. Wherein rounding down results in the largest integer coordinate being less than the first scaled abscissa and rounding up results in the smallest integer coordinate being greater than the first scaled abscissa. For example, the first zoom abscissa is 1.2, then 1 is rounded down and 2 is rounded up.
In the embodiment of the present invention, after the first scaling abscissa is obtained, the largest integer less than or equal to the first scaling abscissa needs to be determined, so that the first scaling abscissa needs to be rounded down to obtain the second scaling abscissa less than or equal to the first scaling abscissa. After the second scaling abscissa is obtained, the smallest integer larger than the second scaling ordinate can be calculated by adding 1. For example, if the first scaling abscissa is 1.2, then the rounding is performed downwards to 1, i.e. the second scaling abscissa is 1, and then 1+1 is calculated to 2, resulting in the third scaling abscissa being 2.
With reference to the embodiment of fig. 5, S2 is a zoom mapping point mapped by the first coordinate point S1, the coordinates of S2 are (x0, y0), x0 and y0 are rounded down to obtain a second zoom abscissa x1 and a second zoom ordinate y1, and a third zoom abscissa x2 and a third zoom ordinate y2 are calculated to be x1+1 and y1+1, respectively. Finally, 4 coordinate points can be determined based on x1, x2, y1 and y2, as shown in fig. 5, which are R1(x1, y2), R2(x2, y2), R3(x1, y1) and R4(x2, y 1). The at least one coordinate point to which the first coordinate point is mapped in the original image is at least one of R1, R2, R3, and R4.
According to the image scaling method provided by the embodiment of the invention, the scaled image subjected to distortion correction can be obtained, and the image can be prevented from being read and written for many times, so that the efficiency of generating the scaled image is higher. Meanwhile, a second coordinate point corresponding to the target pixel point can be determined based on a preset scaling mapping relation, and a basis is provided for the method and the device.
Based on the embodiment of fig. 3, as shown in fig. 6, in the image scaling method provided by another embodiment of the present invention, the above S202-2 may include steps S601-S603:
s601, determining the distance between a second coordinate point and the original image coordinate origin, and determining a distortion adjusting parameter of the second coordinate point based on the distance;
the distance between the second coordinate point and the original image coordinate origin can be calculated by adopting the following calculation formula:
r=sqrt(x′2+y′2)
wherein r is the distance between the second coordinate point and the original image coordinate origin, x 'is the abscissa of the second coordinate point, and y' is the ordinate of the second coordinate point.
After calculating the distance between the second coordinate point and the original image coordinate origin, the distortion adjustment parameter of the second coordinate point may be determined as:
k=1+k1r2+k2r4+k3r6
wherein k is a distortion adjusting parameter of the second coordinate point, k1、k2And k3And correcting the distortion parameters of the image for the distortion calibrated off-line.
S602, calculating the product of the abscissa of the second coordinate point and the distortion adjusting parameter to obtain a first distortion abscissa, and calculating the product of the ordinate of the second coordinate point and the distortion adjusting parameter to obtain a first distortion ordinate;
after determining the distortion adjustment parameter, respectively calculating a first distortion abscissa and a first distortion ordinate based on the distortion adjustment parameter:
x″=x′k
y″=y′k
wherein x 'is the abscissa of the second coordinate point, x "is the first distortion abscissa, y' is the ordinate of the second coordinate point, and y" is the first distortion ordinate.
In the embodiment of the present invention, for convenience of description, a point whose abscissa is the first distortion abscissa and whose ordinate is the first distortion ordinate is used as the distortion mapping point corresponding to the second coordinate point.
And S603, determining a third coordinate point corresponding to the second coordinate point based on the first distortion abscissa and the first distortion ordinate.
After the first distortion abscissa and the first distortion ordinate are calculated, a third coordinate point corresponding to the second coordinate point may be determined based on the first distortion abscissa and the first distortion ordinate.
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.
Wherein the determined at least one coordinate point is: the abscissa is a second distortion abscissa or a third distortion abscissa, and the ordinate is a coordinate point of a second distortion ordinate or a third distortion ordinate; the second distortion abscissa is: a maximum integer less than or equal to the first distortion abscissa; the third distortion abscissa is the smallest integer greater than the second distortion abscissa, and the second distortion ordinate is: a maximum integer less than or equal to the first distortion ordinate; the third distortion ordinate is the smallest integer greater than the second distortion ordinate.
Optionally, the maximum integer less than or equal to the first distortion abscissa may be determined as the second distortion abscissa, the maximum integer less than or equal to the first distortion ordinate may be determined as the second distortion ordinate, the minimum integer greater than the second distortion abscissa may be calculated as the third distortion abscissa, the minimum integer greater than the second distortion ordinate may be calculated as the third distortion ordinate, and at least one coordinate point mapped by the second coordinate point in the original image may be determined as the third coordinate point corresponding to the target pixel point.
In order to determine the maximum integer less than or equal to the first distortion abscissa, the rounding operation may be performed on the first distortion abscissa to obtain the second distortion abscissa. Similarly, the second distortion ordinate may be obtained by rounding the first distortion ordinate. The first distortion ordinate is the same as the first distortion abscissa in terms of the manner of rounding, and only the first distortion abscissa will be described below, and the manner in which the first distortion ordinate is rounded will be referred to the manner in which the first distortion abscissa is rounded.
In the embodiment of the present invention, after the first distortion abscissa is obtained, the maximum integer less than or equal to the first distortion abscissa needs to be determined, so that the first distortion abscissa needs to be rounded down to obtain the second distortion abscissa less than or equal to the first distortion abscissa. After the second distortion abscissa is obtained, the smallest integer greater than the second distortion ordinate can be calculated by adding 1. Illustratively, the first distortion abscissa is 2.2, then 2 is rounded down, i.e., the second distortion abscissa is 2, and finally 2+1 is calculated to be 3, i.e., the third distortion abscissa is 3.
For example, fig. 7 is a schematic diagram of distortion mapping provided by an embodiment of the present invention, where N1 is a distortion mapping point corresponding to the second coordinate point, the coordinates are (x3, y3), x3 is a first distortion abscissa, y3 is a first distortion ordinate, x3 and y3 are rounded down to obtain a second distortion abscissa x4 and a second distortion ordinate y4, and then a third distortion abscissa x5 ═ x4+1 and a third distortion ordinate y5 ═ y4+1 are calculated. Finally, 4 coordinate points can be determined based on x4, x5, y4 and y5, as shown in fig. 7, which are N11(x4, y5), N12(x5, y5), N13(x4, y4) and N14(x5, y 4). The at least one coordinate point to which the second coordinate point is mapped in the original image is at least one of N11, N12, N13, and N14.
According to the image scaling method provided by the embodiment of the invention, the scaled image subjected to distortion correction can be obtained, and the image can be prevented from being read and written for many times, so that the efficiency of generating the scaled image is higher. Meanwhile, distortion adjusting parameters can be determined, and then a third coordinate point corresponding to the second pixel point provides a basis for the method.
Based on the embodiment of fig. 3, as shown in fig. 8, in the image scaling method provided by another embodiment of the present invention, the above S202-3 may include steps S801-S803:
s801, obtaining distortion-scaling weight corresponding to the third coordinate point;
the method for obtaining the distortion-scaling weight corresponding to the third coordinate point includes multiple methods, and for example, at least one of the following two methods is included:
the first method is as follows: calculating distortion-scaling weight corresponding to the third coordinate point according to the second coordinate point and the third coordinate point;
alternatively, the way of calculating the distortion-scaling weight may include step a 1-step a 2:
step A1, substituting the coordinates of the second coordinate point into a preset scaling weight calculation formula, and calculating the scaling weight corresponding to the second coordinate point;
wherein, the scaling weight calculation formula is as follows:
w=|x′-x|*|y′-y|
wherein x 'is an abscissa of the second coordinate point, y' is an ordinate of the second coordinate point, x is a first scaling abscissa, and y is a first scaling ordinate.
For each second coordinate point, after determining the second coordinate point, the scaling weight of the second coordinate point may be calculated according to the above scaling weight calculation formula.
By way of example with the scaling map diagram shown in fig. 5, the scaling weight w1 of the second coordinate R1 is (x2-x0) ((y 1-y 0)), the scaling weight w2 of the second coordinate R2 is (x0-x1) ((y 1-y 0)), the scaling weight w3 of the second coordinate R3 is (x2-x0) ((y 0-y2), and the scaling weight w4 of the second coordinate R4 is (x0-x1) ((y 0-y 2).
Step A2, substituting the coordinates of the third coordinate point into a preset distortion weight calculation formula, and calculating the distortion weight corresponding to the third coordinate point;
wherein, the preset distortion weight calculation formula is as follows:
m=|x″-x′|*|y″-x′|
wherein x "is an abscissa of the third coordinate point, y" is an ordinate of the third coordinate point, x 'is an abscissa of the distortion mapping point of the second coordinate point, and y' is an ordinate of the distortion mapping point of the second coordinate point.
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.
By way of example of the distortion map diagram shown in fig. 7, 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-y 5).
Step a3, a product of the distortion weight and the scaling weight is calculated as the distortion-scaling weight corresponding to the third coordinate point.
For each third coordinate point, a 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.
Illustratively, 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 × m 11.
The second method comprises the following steps: searching distortion-scaling weights corresponding to the coordinates of the target pixel points in a preset distortion-scaling table, and using the distortion-scaling weights as distortion-scaling weights corresponding to the third coordinate points; wherein, the weight corresponding to each coordinate point in the distortion-scaling table is as follows: the coordinate point is determined in advance based on the second coordinate point and the third coordinate point corresponding to the coordinate point.
In this embodiment, in order to reduce the amount of calculation and save the calculation resources of the device, the distortion-scaling table may be established in advance. And recording the distortion-scaling weight of each third coordinate point in the distortion-scaling table, wherein 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 the distortion-scaling table needs to be used, the distortion-scaling table can be directly read, the weight of each third coordinate point is obtained, decimal operation involved in the process of calculating the distortion-scaling weight is avoided, calculation resources are saved, and the efficiency of image scaling is further improved.
In the distortion-scaling table, the distortion-scaling weight corresponding to the coordinate of each target pixel point may be calculated according to the distortion-scaling weight calculation method described in the foregoing method one, which is not described herein again.
S802, if the third coordinate point is single, 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, and taking the product as the pixel value of the target pixel point;
if the third coordinate point is single, 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 can be directly used as the pixel value of the target pixel point.
And S803, if the number of the third coordinate points is multiple, performing weighted summation on the pixel values of the pixel points corresponding to the third coordinate points in the original image based on the distortion-scaling weights corresponding to the third coordinate points to obtain the pixel value of the target pixel point.
In order to obtain more accurate pixel values of the target pixel points, the number of the third coordinate points may be multiple, for example, there are 16 third coordinate points.
In the distortion-scaling mapping diagram shown in fig. 9, the second coordinate points corresponding to the first coordinate point S1 include R1, R2, R3, and R4. The third coordinate point corresponding to the second coordinate point R1 includes: n11, N12, N13 and N14; the third coordinate point corresponding to the second coordinate point R2 includes: n21, N22, N23 and N24; the third coordinate point corresponding to the second coordinate point R3 includes: n31, N32, N33 and N34; the third coordinate point corresponding to the second coordinate point R4 includes: 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.
This time is:
S1=N11*m11*w1+N12*m12*w1+N13*m13*w1+N14*m14*w1+N21*m21*w2+N22*m22*w2+N23*m23*w2+N24*m24*w2+N31*m31*w3+N32*m32*w3+N33*m33*w3+N34*m34*w3+N41*m41*w4+N42*m42*w4+N43*m43*w4+N44*m44*w4
s1 represents the pixel value of the first coordinate point S1 corresponding to the target pixel point, and m11 × w1 to m44 × w4 are distortion-scaling weights of N11 to N44 in the third stage, respectively.
According to the image scaling method provided by the embodiment of the invention, the scaled image subjected to distortion correction can be obtained, and the image can be prevented from being read and written for many times, so that the efficiency of generating the scaled image is higher. Meanwhile, the distortion-scaling weight is calculated, and then the pixel value of the target pixel point can be accurately calculated based on the distortion-scaling weight.
Corresponding to the image scaling method provided by the embodiment of the present invention, as shown in fig. 10, an embodiment of the present invention further provides an image scaling apparatus, including:
an image obtaining module 1001 configured to obtain an original image to be processed;
an image generating module 1002, configured to calculate a pixel value of a target pixel in a target image after an original image is zoomed, so as to generate the target image;
the image generation module 1002 is specifically configured to determine, for each target pixel point, a second coordinate point corresponding to the target pixel point in the original image according to a first coordinate point of the target pixel point in the target image; wherein, the second coordinate point corresponding to the target pixel point is: when the original image is subjected to zooming processing, generating a coordinate point of a pixel point of the target pixel point; when the original image is subjected to zooming processing, generating a coordinate point of a pixel point of the target pixel point; 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 distortion correction of the second coordinate point; calculating the pixel value of the target pixel point by using the pixel value of the pixel point corresponding to the third coordinate point;
optionally, the image generating module includes:
the first determining submodule is used for determining a first coordinate point of the target pixel point in the target image;
the second determining submodule is used for determining a coordinate point mapped by the first coordinate point in the original image based on a preset scaling mapping relation, and the coordinate point is used as a second coordinate point corresponding to the target pixel point;
optionally, the second determining sub-module includes:
the coordinate calculation unit is used for calculating the ratio of the abscissa of the first coordinate point to a preset horizontal scaling ratio to obtain a first scaling abscissa, and calculating the ratio of the ordinate of the first coordinate point to a preset vertical scaling ratio to obtain a first scaling ordinate;
a coordinate determination unit, configured to determine, based on the first scaling abscissa and the first scaling ordinate, a coordinate point mapped by the first coordinate point in the original image as a second coordinate point corresponding to the target pixel point;
optionally, the coordinate determining unit is specifically configured to 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; wherein each determined coordinate point is: the abscissa is a second scaling abscissa or a third scaling abscissa, and the ordinate is a coordinate point of a second scaling ordinate or a third scaling ordinate; the second scaling abscissa is: a maximum integer less than or equal to the first scaling abscissa; the third scaling abscissa is the smallest integer larger than the second scaling abscissa, and the second scaling ordinate is: a maximum integer less than or equal to the first scaling ordinate; the third scaling ordinate is the smallest integer larger than the second scaling ordinate;
optionally, the image generating module includes:
the parameter determining submodule is used for determining the distance between the second coordinate point and the original image coordinate origin and determining the distortion adjusting parameter of the second coordinate point based on the distance;
the coordinate calculation submodule is used for calculating the product of the abscissa of the second coordinate point and the distortion adjusting parameter to obtain a first distortion abscissa, and calculating the product of the ordinate of the second coordinate point and the distortion adjusting parameter to obtain a first distortion ordinate;
the coordinate determination submodule is used for determining a third coordinate point corresponding to the second coordinate point based on the first distortion abscissa and the first distortion ordinate;
optionally, the coordinate determination sub-module is specifically configured 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: the abscissa is a second distortion abscissa or a third distortion abscissa, and the ordinate is a coordinate point of a second distortion ordinate or a third distortion ordinate; the second distortion abscissa is: a maximum integer less than or equal to the first distortion abscissa; the third distortion abscissa is a minimum integer greater than the second distortion abscissa, and the second distortion ordinate is: a maximum integer less than or equal to the first distortion ordinate; the third distortion ordinate is the smallest integer greater than the second distortion ordinate.
Optionally, the image generating module includes:
the weight obtaining submodule is used for obtaining distortion-scaling weights corresponding to the third coordinate points;
if the third coordinate point is single, calculating the product of the pixel value of the pixel point corresponding to the third coordinate point and the distortion-scaling weight corresponding to the third coordinate point in the original image as the pixel value of the target pixel point; and if the number of the third coordinate points is multiple, carrying out weighted summation on pixel values of pixel points corresponding to the third coordinate points in the original image based on distortion-scaling weights corresponding to the third coordinate points to obtain pixels of the target pixel points.
Optionally, the weight obtaining sub-module includes:
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 the presence of a gas in the gas,
the weight searching unit is used for searching distortion-scaling weights corresponding to the coordinates of the target pixel points in a preset distortion-scaling table and taking the distortion-scaling weights as distortion-scaling weights corresponding to the third coordinate points; wherein, the weight corresponding to each coordinate point in the distortion-scaling table is as follows: the coordinate point is determined in advance based on the second coordinate point and the third coordinate point corresponding to the coordinate point.
Optionally, the weight calculating unit is specifically configured to substitute the coordinates of the second coordinate point into a preset scaling weight calculation formula, and calculate a scaling weight corresponding to the second coordinate point; substituting the coordinates of the third coordinate point into a preset distortion weight calculation formula, and calculating the distortion weight corresponding to the third coordinate point; and calculating the product of the distortion weight and the scaling weight as the distortion-scaling weight corresponding to the third coordinate point.
In the image scaling method provided by the embodiment of the invention, since the second coordinate point is a coordinate of a pixel point used for generating the target pixel point when the original image is scaled, and the third coordinate point is a coordinate point of a pixel point used for distortion correction of the second coordinate point, the pixel value of the target pixel point is calculated by using the pixel value of the pixel point corresponding to the third coordinate point, which is equivalent to performing distortion correction on the original image and then scaling to obtain the pixel value of the target pixel point, so that the obtained pixel value of the target pixel point is a pixel value after distortion correction and scaling.
In addition, because the pixel values of the pixel points corresponding to the third coordinate points can be directly based on, the pixel points of the target pixel points are calculated, which is equivalent to performing distortion correction while zooming the image, the processing quantity required for obtaining the zoomed image subjected to distortion correction can be reduced, and meanwhile, the original image does not need to be subjected to distortion correction to generate the image subjected to distortion correction and then the image subjected to distortion correction is zoomed, so that the image can be prevented from being read and written for many times, the read-write bandwidth consumption is reduced, and the efficiency of generating the zoomed image is higher.
An embodiment of the present invention further provides an electronic device, as shown in fig. 11, including a processor 1101, a communication interface 1102, a memory 1103 and a communication bus 1104, where the processor 1101, the communication interface 1102 and the memory 1103 complete mutual communication through the communication bus 1104,
a memory 1103 for storing a computer program;
the processor 1101 is configured to implement the steps of the image scaling method according to the embodiment of the present invention when executing the program stored in the memory 1103.
The communication bus mentioned in the electronic device may be a Peripheral Component Interconnect (PCI) bus, an Extended Industry Standard Architecture (EISA) bus, or the like. The communication bus may be divided into an address bus, a data bus, a control bus, etc. For ease of illustration, only one thick line is shown, but this does not mean that there is only one bus or one type of bus.
The communication interface is used for communication between the electronic equipment and other equipment.
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 memory device located remotely from the processor.
The Processor may be a general-purpose Processor, including a Central Processing Unit (CPU), a Network Processor (NP), and the like; but also Digital Signal Processors (DSPs), Application Specific Integrated Circuits (ASICs), Field Programmable Gate Arrays (FPGAs) or other Programmable logic devices, discrete Gate or transistor logic devices, discrete hardware components.
In a further embodiment of the present invention, a computer-readable storage medium is further provided, in which a computer program is stored, which, when being executed by a processor, implements the steps of any of the image scaling methods described above.
In a further embodiment provided by the present invention, there is also provided a computer program product containing instructions which, when run on a computer, cause the computer to perform any of the image scaling methods of the above embodiments.
In the above embodiments, the implementation may be wholly or partially realized by software, hardware, firmware, or any combination thereof. When implemented in software, may 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 loaded and executed on a computer, cause the processes or functions described in accordance with the embodiments of the invention to occur, in whole or in part. The computer may be a general purpose computer, a special purpose computer, a network of computers, or other programmable device. The computer instructions may be stored in a computer readable storage medium or transmitted from one computer readable storage medium to another, for example, from one website site, computer, server, or data center to another website site, computer, server, or data center via wired (e.g., coaxial cable, fiber optic, Digital Subscriber Line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.). The computer-readable storage medium can be any available medium that can be accessed by a computer or a data storage device, such as a server, a data center, etc., that incorporates one or more of the available media. The usable medium may be a magnetic medium (e.g., floppy Disk, hard Disk, magnetic tape), an optical medium (e.g., DVD), or a semiconductor medium (e.g., Solid State Disk (SSD)), among others.
It is noted that, herein, relational terms such as first and second, and the like may be used solely to distinguish one entity or action from another entity or action without necessarily requiring or implying any actual such relationship or order between such entities or actions. Also, the terms "comprises," "comprising," or any other variation thereof, are intended to cover a non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements does not include only those elements but may include other elements not expressly listed or inherent to such process, method, article, or apparatus. Without further limitation, an element defined by the phrase "comprising an … …" does not exclude the presence of other identical elements in a process, method, article, or apparatus that comprises the element.
All the embodiments in the present specification are described in a related manner, and the same and similar parts among the embodiments may be referred to each other, and each embodiment focuses on the differences from the other embodiments. In particular, as for the apparatus, device, and system embodiments, since they are substantially similar to the method embodiments, the description is relatively simple, and reference may be made to some descriptions of the method embodiments for relevant points.
The above description is only for the preferred embodiment of the present invention, and is not intended to limit the scope of the present invention. Any modification, equivalent replacement, or improvement made within the spirit and principle of the present invention shall fall within the protection scope of the present invention.

Claims (13)

1. An image scaling method, characterized in that the method comprises:
acquiring an original image to be processed;
calculating pixel values of target pixel points in the target image after the original image is zoomed so as to generate the target image; the pixel value of each target pixel point is obtained through the following modes:
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; wherein, the second coordinate point corresponding to the target pixel point is: when the original image is subjected to zooming processing, generating a coordinate point of a pixel point of the target pixel point;
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 distortion correction of the second coordinate point;
and calculating the pixel value of the target pixel point by using the pixel value of the pixel point corresponding to the third coordinate point.
2. The method of claim 1, wherein determining, according to the first coordinate point of the target pixel point in the target image, a corresponding second coordinate point of the target pixel point in the original image comprises:
determining a first coordinate point of the target pixel point in the target image;
and determining a coordinate point mapped by the first coordinate point in the original image based on a preset scaling mapping relation, and taking the coordinate point as a second coordinate point corresponding to the target pixel point.
3. The method according to claim 2, wherein determining the coordinate point mapped by the first coordinate point in the original image as the second coordinate point corresponding to the target pixel point based on a preset scaling mapping relationship comprises
Calculating the ratio of the abscissa of the first coordinate point to a preset horizontal scaling ratio to obtain a first scaling abscissa, and calculating the ratio of the ordinate of the first coordinate point to a preset vertical scaling ratio to obtain a first scaling ordinate;
and determining a coordinate point mapped by the first coordinate point in the original image as a second coordinate point corresponding to the target pixel point based on the first scaling abscissa and the first scaling ordinate.
4. The method according to claim 3, wherein the determining, as the second coordinate point corresponding to the target pixel point, the coordinate point to which the first coordinate point is mapped in the original image based on the first scaling abscissa and the first scaling ordinate comprises:
determining 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;
wherein each determined coordinate point is: the abscissa is a second scaling abscissa or a third scaling abscissa, and the ordinate is a coordinate point of a second scaling ordinate or a third scaling ordinate; the second scaling abscissa is: a maximum integer less than or equal to the first scaling abscissa; the third scaling abscissa is the smallest integer larger than the second scaling abscissa, and the second scaling ordinate is: a maximum integer less than or equal to the first scaling ordinate; the third scaling ordinate is a smallest integer larger than the second scaling ordinate.
5. The method of claim 1, wherein determining a third coordinate point in the original image corresponding to the second coordinate point comprises:
determining the distance between the second coordinate point and the original image coordinate origin, and determining the distortion adjusting parameter of the second coordinate point based on the distance;
calculating the product of the abscissa of the second coordinate point and the distortion adjusting parameter to obtain a first distortion abscissa, and calculating the product of the ordinate of the second coordinate point and the distortion adjusting parameter to obtain a first distortion ordinate;
and determining a third coordinate point corresponding to the second coordinate point based on the first distortion abscissa and the first distortion ordinate.
6. The method of claim 5, wherein determining a third coordinate point corresponding to the second coordinate point based on the first distortion abscissa and the first distortion ordinate comprises:
determining 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: the abscissa is a second distortion abscissa or a third distortion abscissa, and the ordinate is a coordinate point of a second distortion ordinate or a third distortion ordinate; the second distortion abscissa is: a maximum integer less than or equal to the first distortion abscissa; the third distortion abscissa is a minimum integer greater than the second distortion abscissa, and the second distortion ordinate is: a maximum integer less than or equal to the first distortion ordinate; the third distortion ordinate is the smallest integer greater than the second distortion ordinate.
7. The method according to claim 1, wherein calculating the pixel value of the target pixel point by using the pixel value of the pixel point corresponding to the third coordinate point comprises:
obtaining distortion-scaling weights corresponding to the third coordinate points;
if the third coordinate point is single, 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, and taking the product as the pixel value of the target pixel point;
and if the number of the third coordinate points is multiple, carrying out weighted summation on the pixel values of the pixel points corresponding to the third coordinate points in the original image based on the distortion-scaling weights corresponding to the third coordinate points to obtain the pixel value of the target pixel point.
8. The method of claim 7, wherein obtaining distortion-scaling weights corresponding to the third coordinate points comprises:
calculating distortion-scaling weights corresponding to the third coordinate points according to the second coordinate points and the third coordinate points; and/or the presence of a gas in the gas,
searching distortion-scaling weights corresponding to the coordinates of the target pixel points in a preset distortion-scaling table, and using the distortion-scaling weights as distortion-scaling weights corresponding to the third coordinate points; wherein, the weight corresponding to each coordinate point in the distortion-scaling table is as follows: the coordinate point is determined in advance based on the second coordinate point and the third coordinate point corresponding to the coordinate point.
9. The method of claim 8, wherein said calculating distortion-scaling weights corresponding to said third coordinate points based on said second coordinate points and said third coordinate points comprises:
substituting the coordinates of the second coordinate point into a preset scaling weight calculation formula, and calculating the scaling weight corresponding to the second coordinate point;
substituting the coordinates of the third coordinate point into a preset distortion weight calculation formula, and calculating the distortion weight corresponding to the third coordinate point;
and calculating the product of the distortion weight and the scaling weight as the distortion-scaling weight corresponding to the third coordinate point.
10. An image scaling apparatus, characterized in that the apparatus comprises:
the image acquisition module is used for acquiring an original image to be processed;
the image generation module is used for calculating the pixel value of a target pixel point in a target image after the original image is zoomed so as to generate the target image;
the image generation module is specifically configured to determine, for each target pixel point, a second coordinate point corresponding to the target pixel point in the original image according to a first coordinate point of the target pixel point in the target image; wherein, the second coordinate point corresponding to the target pixel point is: when the original image is subjected to zooming processing, generating a coordinate point of a pixel point of the target pixel point; when the original image is subjected to zooming processing, generating a coordinate point of a pixel point of the target pixel point; 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 distortion correction of the second coordinate point; and calculating the pixel value of the target pixel point by using the pixel value of the pixel point corresponding to the third coordinate point.
11. The apparatus of claim 10, wherein the image generation module comprises:
the first determining submodule is used for determining a first coordinate point of the target pixel point in the target image;
the second determining submodule is used for determining a coordinate point mapped by the first coordinate point in the original image based on a preset scaling mapping relation, and the coordinate point is used as a second coordinate point corresponding to the target pixel point;
wherein the second determining submodule includes:
the coordinate calculation unit is used for calculating the ratio of the abscissa of the first coordinate point to a preset horizontal scaling ratio to obtain a first scaling abscissa, and calculating the ratio of the ordinate of the first coordinate point to a preset vertical scaling ratio to obtain a first scaling ordinate;
a coordinate determination unit, configured to determine, based on the first scaling abscissa and the first scaling ordinate, a coordinate point mapped by the first coordinate point in the original image as a second coordinate point corresponding to the target pixel point;
the coordinate determination unit is specifically configured to 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; wherein each determined coordinate point is: the abscissa is a second scaling abscissa or a third scaling abscissa, and the ordinate is a coordinate point of a second scaling ordinate or a third scaling ordinate; the second scaling abscissa is: a maximum integer less than or equal to the first scaling abscissa; the third scaling abscissa is the smallest integer larger than the second scaling abscissa, and the second scaling ordinate is: a maximum integer less than or equal to the first scaling ordinate; the third scaling ordinate is the smallest integer larger than the second scaling ordinate;
wherein the image generation module comprises:
the parameter determining submodule is used for determining the distance between the second coordinate point and the original image coordinate origin and determining the distortion adjusting parameter of the second coordinate point based on the distance;
the coordinate calculation submodule is used for calculating the product of the abscissa of the second coordinate point and the distortion adjusting parameter to obtain a first distortion abscissa, and calculating the product of the ordinate of the second coordinate point and the distortion adjusting parameter to obtain a first distortion ordinate;
the coordinate determination submodule is used for determining a third coordinate point corresponding to the second coordinate point based on the first distortion abscissa and the first distortion ordinate;
the coordinate determination submodule is specifically configured to determine at least one coordinate point corresponding to the second coordinate point, and use the coordinate point as a third coordinate point corresponding to the second coordinate point; wherein the determined at least one coordinate point is: the abscissa is a second distortion abscissa or a third distortion abscissa, and the ordinate is a coordinate point of a second distortion ordinate or a third distortion ordinate; the second distortion abscissa is: a maximum integer less than or equal to the first distortion abscissa; the third distortion abscissa is a minimum integer greater than the second distortion abscissa, and the second distortion ordinate is: a maximum integer less than or equal to the first distortion ordinate; the third distortion ordinate is the smallest integer greater than the second distortion ordinate;
wherein the image generation module comprises:
the weight obtaining submodule is used for obtaining distortion-scaling weights corresponding to the third coordinate points;
if the third coordinate point is single, calculating the product of the pixel value of the pixel point corresponding to the third coordinate point and the distortion-scaling weight corresponding to the third coordinate point in the original image as the pixel value of the target pixel point; if the number of the third coordinate points is multiple, based on distortion-scaling weights corresponding to the third coordinate points, carrying out weighted summation on pixel values of pixel points corresponding to the third coordinate points in the original image to obtain pixels of the target pixel points;
wherein, the weight obtaining submodule includes:
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 the presence of a gas in the gas,
the weight searching unit is used for searching distortion-scaling weights corresponding to the coordinates of the target pixel points in a preset distortion-scaling table and taking the distortion-scaling weights as distortion-scaling weights corresponding to the third coordinate points; wherein, the weight corresponding to each coordinate point in the distortion-scaling table is as follows: the coordinate point is determined in advance based on a second coordinate point and a third coordinate point corresponding to the coordinate point;
the weight calculation unit is specifically configured to substitute the coordinates of the second coordinate point into a preset scaling weight calculation formula, and calculate a scaling weight corresponding to the second coordinate point; substituting the coordinates of the third coordinate point into a preset distortion weight calculation formula, and calculating the distortion weight corresponding to the third coordinate point; and calculating the product of the distortion weight and the scaling weight as the distortion-scaling weight corresponding to the third coordinate point.
12. An electronic device is characterized by comprising a processor, a communication interface, a memory and a communication bus, wherein the processor and the communication interface are used for realizing mutual communication by the memory through the communication bus;
a memory for storing a computer program;
a processor for implementing the method steps of any of claims 1-9 when executing a program stored in the memory.
13. A computer-readable storage medium, characterized in that a computer program is stored in the computer-readable storage medium, which computer program, when being executed by a processor, carries out the method steps of any one of claims 1-9.
CN202111632868.XA 2021-12-29 2021-12-29 Image scaling method and device, electronic equipment and storage medium Pending CN114170091A (en)

Priority Applications (1)

Application Number Priority Date Filing Date Title
CN202111632868.XA CN114170091A (en) 2021-12-29 2021-12-29 Image scaling method and device, electronic equipment and storage medium

Applications Claiming Priority (1)

Application Number Priority Date Filing Date Title
CN202111632868.XA CN114170091A (en) 2021-12-29 2021-12-29 Image scaling method and device, electronic equipment and storage medium

Publications (1)

Publication Number Publication Date
CN114170091A true CN114170091A (en) 2022-03-11

Family

ID=80488375

Family Applications (1)

Application Number Title Priority Date Filing Date
CN202111632868.XA Pending CN114170091A (en) 2021-12-29 2021-12-29 Image scaling method and device, electronic equipment and storage medium

Country Status (1)

Country Link
CN (1) CN114170091A (en)

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114998794A (en) * 2022-05-31 2022-09-02 天翼爱音乐文化科技有限公司 High-altitude parabolic recognition method, system, device and storage medium
WO2024212665A1 (en) * 2023-04-12 2024-10-17 腾讯科技(深圳)有限公司 Image scaling method and apparatus, and device and storage medium

Cited By (2)

* Cited by examiner, † Cited by third party
Publication number Priority date Publication date Assignee Title
CN114998794A (en) * 2022-05-31 2022-09-02 天翼爱音乐文化科技有限公司 High-altitude parabolic recognition method, system, device and storage medium
WO2024212665A1 (en) * 2023-04-12 2024-10-17 腾讯科技(深圳)有限公司 Image scaling method and apparatus, and device and storage medium

Similar Documents

Publication Publication Date Title
CN114170091A (en) Image scaling method and device, electronic equipment and storage medium
CN110996081B (en) Projection picture correction method and device, electronic equipment and readable storage medium
CN108961184A (en) A kind of bearing calibration of depth image, device and equipment
CN111323751B (en) Sound source positioning method, device and storage medium
CN112686824A (en) Image correction method, image correction device, electronic equipment and computer readable medium
CN113643414A (en) Three-dimensional image generation method and device, electronic equipment and storage medium
CN111325798A (en) Camera model correction method and device, AR implementation equipment and readable storage medium
CN113963072B (en) Binocular camera calibration method and device, computer equipment and storage medium
CN113516697A (en) Image registration method and device, electronic equipment and computer-readable storage medium
US8139065B2 (en) Machine-implemented method and electronic device for presenting a dual-axis graph
CN110210572B (en) Image classification method, device, storage medium and equipment
US20230401670A1 (en) Multi-scale autoencoder generation method, electronic device and readable storage medium
CN110909277A (en) Multimedia resource loading method and device, electronic equipment and storage medium
CN114900606B (en) Calibration method and device for zoom tracking curve, electronic device and storage medium
CN116012418A (en) Multi-target tracking method and device
CN115209030B (en) Video anti-shake processing method and device, electronic equipment and storage medium
CN116797464A (en) Computing method, computing device, computer apparatus, and storage medium
CN115730208A (en) Training method, training device, training apparatus, and computer-readable storage medium
CN112967351A (en) Image generation method and device, electronic equipment and storage medium
CN110189279B (en) Model training method and device, electronic equipment and storage medium
CN106408499B (en) Method and device for acquiring reverse mapping table for image processing
CN113989121A (en) Normalization processing method and device, electronic equipment and storage medium
CN109741250B (en) Image processing method and device, storage medium and electronic equipment
CN113222997A (en) Neural network generation method, neural network image processing device, electronic device, and medium
CN116563357B (en) Image matching method, device, computer equipment and computer readable storage medium

Legal Events

Date Code Title Description
PB01 Publication
PB01 Publication
SE01 Entry into force of request for substantive examination
SE01 Entry into force of request for substantive examination
CB02 Change of applicant information

Address after: 310051 room 304, B / F, building 2, 399 Danfeng Road, Binjiang District, Hangzhou City, Zhejiang Province

Applicant after: Hangzhou Hikvision Robot Co.,Ltd.

Address before: 310051 room 304, B / F, building 2, 399 Danfeng Road, Binjiang District, Hangzhou City, Zhejiang Province

Applicant before: HANGZHOU HIKROBOT TECHNOLOGY Co.,Ltd.

CB02 Change of applicant information