Distorted image correction method and device, electronic device, and storage medium
By using inverse mapping transformation and an anti-aliasing model to correct distorted images, the problem of poor image correction performance in existing technologies is solved, and high-precision image correction and analysis are achieved.
Patent Information
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- INDUSTRIAL AND COMMERCIAL BANK OF CHINA
- Filing Date
- 2023-06-05
- Publication Date
- 2026-06-05
AI Technical Summary
Existing technologies have poor distortion correction effects, which cannot meet the requirements of high-precision image analysis and applications.
By obtaining the pixel coordinates of each pixel in the target distorted image, an inverse mapping transformation is performed using an image correction model, the deformation convolution kernel and Jacobian value are calculated, and optimization correction is performed by combining a Gaussian convolution kernel and an anti-aliasing correction model.
It achieves high-precision correction of distorted images, improves the accuracy of image analysis and applications, and enhances the user experience.
Smart Images

Figure CN116777769B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of biometrics and other related technical fields. Specifically, it relates to a method and apparatus for correcting distorted images, an electronic device, and a storage medium. Background Technology
[0002] With the rapid development of image recognition technology, more and more businesses need to complete verification through facial or other image recognition. Although technological advancements have enabled camera devices such as cameras or mobile phones to capture images of better quality, the lenses cannot achieve ideal precision during production and may also deviate during assembly. This results in image distortion, making it difficult to apply to computer image applications that require high image accuracy. Lens distortion may cause the final image analysis to lose its application value. For example, in applications such as facial recognition and OCR image recognition, it is impossible to obtain accurate user information from directly captured images, thus affecting the user experience.
[0003] In related technologies, to solve image distortion, a mathematical model is generally established to fit the distortion process before distortion correction is performed. However, due to the characteristics of the image itself and the sampling process, the correction transformation process will inevitably lead to image aliasing. Anti-aliasing can be achieved by performing convolution operation using a standard Gaussian function, that is, by suppressing high-frequency components in the image signal to prevent aliasing during the resampling process. However, this correction method cannot effectively filter out high-frequency components, so the corrected image still cannot meet the requirements of subsequent high-precision analysis or application.
[0004] There is currently no effective solution to the above problems. Summary of the Invention
[0005] This invention provides a method, apparatus, electronic device, and storage medium for correcting distorted images, in order to at least solve the technical problem in related technologies where the distortion correction effect is poor and cannot meet the requirements of high-precision image analysis and application.
[0006] According to one aspect of the present invention, a method for correcting a distorted image is provided, comprising: obtaining the pixel coordinates of each pixel in a target distorted image; inputting the pixel coordinates of each pixel into an image correction model, outputting initial correction coordinates corresponding to each pixel, and calculating a deformation convolution kernel size based on the initial correction coordinates, wherein the image correction model corrects the target distorted image through an inverse mapping transformation; inputting each pixel coordinate into a Jacobi calculation formula to obtain a Jacobi value for each pixel coordinate, and performing an inverse mapping calculation on the Jacobi value to obtain an inverse-mapped Jacobi value; calculating a Gaussian convolution kernel for each pixel based on the deformation convolution kernel size and the inverse-mapped Jacobi value; inputting the Gaussian convolution kernel into an anti-aliasing correction model, outputting optimized correction coordinates for each pixel, and obtaining a target corrected image.
[0007] Optionally, the step of obtaining the pixel coordinates of each pixel in the target distorted image includes: receiving source image information of the target distorted image, wherein the source image information includes at least one of the following: source image size, source pixel value; scanning the target distorted image to obtain scanned image information, wherein the scanned image information includes at least one of the following: scanned image size, scanned pixel value; determining that the target distorted image has missing pixels when the source image size is not equal to the scanned image size, or when the source pixel value is not equal to the scanned pixel value, and filling in the missing pixels; establishing a coordinate system for the filled target distorted image and acquiring the pixel coordinates of each pixel.
[0008] Optionally, after obtaining the pixel coordinates of each pixel in the target distorted image, the method includes: calculating the coordinate difference between each pixel and its adjacent pixels in the target distorted image to obtain a first coordinate difference.
[0009] Optionally, after inputting the pixel coordinates of each pixel into the image correction model and outputting the initial corrected coordinates corresponding to each pixel, the method includes: calculating the coordinate difference between the initial corrected coordinates of each pixel and the initial corrected coordinates of adjacent pixels to obtain a second coordinate difference; and determining that the corrected initial corrected coordinates are correct coordinates when both the first coordinate difference and the second coordinate difference are less than or equal to a preset difference threshold.
[0010] Optionally, the step of calculating the deformable convolution kernel size based on the initial correction coordinates includes: determining the convolution region based on the initial correction coordinates of each pixel; calculating the area of the convolution region to obtain the deformable convolution kernel size.
[0011] Optionally, after inputting the Gaussian convolution kernel into the anti-aliasing correction formula and outputting the optimized correction coordinates of each pixel to obtain the target correction image, the method further includes: performing interpolation on each pixel in the target correction image to obtain the optimized coordinates of each pixel; and filling the optimized coordinates into the target correction image to obtain the optimized target correction image.
[0012] Optionally, the formula for calculating the Gaussian convolution kernel is: in, G represents the Gaussian convolution kernel. c (x) represents the size of the deformable convolution kernel, x0 represents the pixel coordinate, and x represents the initial correction coordinate. The Jacobian value after the inverse mapping is represented, and h represents the homography mapping. -1 This represents the inverse mapping.
[0013] Optionally, the calculation formula used in the anti-aliasing correction model is: in, This represents the pixel coordinates of each pixel in the target distorted image. H represents the optimized correction coordinates, and H represents the homography transformation. -1 Represents the inverse mapping transformation. This indicates sampling of the image, and I represents the interpolation operation. This refers to the Gaussian convolution kernel.
[0014] According to another aspect of the present invention, a device for correcting distorted images is also provided, comprising: an acquisition unit for acquiring the pixel coordinates of each pixel in a target distorted image; a first output unit for inputting the pixel coordinates of each pixel into an image correction model, outputting initial correction coordinates corresponding to each pixel, and calculating the deformation convolution kernel size based on the initial correction coordinates, wherein the image correction model corrects the target distorted image through an inverse mapping transformation; a second output unit for inputting each pixel coordinate into a Jacobi calculation formula to obtain the Jacobi value of each pixel coordinate, and performing an inverse mapping calculation on the Jacobi value to obtain an inverse-mapped Jacobi value; a calculation unit for calculating a Gaussian convolution kernel for each pixel based on the deformation convolution kernel size and the inverse-mapped Jacobi value; and a third output unit for inputting the Gaussian convolution kernel into an anti-aliasing correction model, outputting optimized correction coordinates of each pixel, and obtaining a target corrected image.
[0015] Optionally, the distortion image correction device further includes: a first receiving module, configured to receive source image information of the target distorted image, wherein the source image information includes at least one of the following: source image size, source pixel value; a first scanning module, configured to scan the target distorted image to obtain scanned image information, wherein the scanned image information includes at least one of the following: scanned image size, scanned pixel value; a first determining module, configured to determine that the target distorted image has missing pixels when the source image size is not equal to the scanned image size, or when the source pixel value is not equal to the scanned pixel value, and to fill in the missing pixels; and a first establishing module, configured to establish a coordinate system for the filled target distorted image and collect the pixel coordinates of each pixel.
[0016] Optionally, the image correction device further includes: a first calculation module, used to calculate the coordinate difference between each pixel and its adjacent pixels in the target distorted image, to obtain a first coordinate difference.
[0017] Optionally, the distortion image correction device further includes: a second calculation module, used to calculate the coordinate difference between the initial corrected coordinates of each pixel and the initial corrected coordinates of adjacent pixels to obtain a second coordinate difference; and a second determination module, used to determine that the corrected initial corrected coordinates are correct coordinates when both the first coordinate difference and the second coordinate difference are less than or equal to a preset difference threshold.
[0018] Optionally, the first output unit includes: a third determining module, used to determine the convolution region based on the initial correction coordinates of each pixel; and a third calculating module, used to calculate the area of the convolution region to obtain the size of the deformable convolution kernel.
[0019] Optionally, the distortion correction device further includes: a first calculation module, used to perform interpolation calculation on each pixel in the target correction image to obtain the optimized coordinates of each pixel; and a first filling module, used to fill the optimized coordinates into the target correction image to obtain the optimized target correction image.
[0020] Optionally, the formula for calculating the Gaussian convolution kernel is: in, G represents the Gaussian convolution kernel. c (x) represents the size of the deformable convolution kernel, x0 represents the pixel coordinate, and x represents the initial correction coordinate. The Jacobian value after the inverse mapping is represented, and h represents the homography mapping. -1 This represents the inverse mapping.
[0021] Optionally, the calculation formula used in the anti-aliasing correction model is: in, This represents the pixel coordinates of each pixel in the target distorted image. H represents the optimized correction coordinates, and H represents the homography transformation. -1 Represents the inverse mapping transformation. This indicates sampling of the image, and I represents the interpolation operation. This refers to the Gaussian convolution kernel.
[0022] According to another aspect of the present invention, a computer-readable storage medium is also provided, the computer-readable storage medium including a stored computer program, wherein, when the computer program is executed, it controls the device where the computer-readable storage medium is located to perform any of the above-described methods for correcting distorted images.
[0023] According to another aspect of the present invention, an electronic device is also provided, including one or more processors and a memory, the memory being used to store one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors cause the one or more processors to implement any of the above-described methods for correcting distorted images.
[0024] In this disclosure, the following steps are performed: First, the pixel coordinates of each pixel in the target distorted image are obtained. Then, the pixel coordinates of each pixel are input into the image correction model, and the initial correction coordinates corresponding to each pixel are output. The deformation convolution kernel size is calculated based on the initial correction coordinates. Next, each pixel coordinate is input into the Jacobian calculation formula to obtain the Jacobian value of each pixel coordinate. The Jacobian value is then inversely mapped to obtain the inversely mapped Jacobian value. Then, the Gaussian convolution kernel of each pixel is calculated based on the deformation convolution kernel size and the inversely mapped Jacobian value. Finally, the Gaussian convolution kernel is input into the anti-aliasing correction model, and the optimized correction coordinates of each pixel are output to obtain the target corrected image.
[0025] In this disclosure, each pixel in the distorted image is first inversely mapped using an image correction model to obtain initial correction coordinates. Then, the inverse mapping Jacobian ratio and deformation convolution kernel size of each pixel are calculated, followed by the calculation of the Gaussian convolution kernel for each pixel. Finally, the target image is corrected according to the anti-aliasing correction model to obtain the target corrected image. The calculation of the inverse mapping Jacobian ratio and deformation convolution kernel size both consider the adaptive relationship between each pixel and its surrounding pixels. The anti-aliasing correction model can achieve adaptive anti-aliasing correction of distorted images, realizing high-precision correction of distorted images. This solves the technical problem in related technologies where the distortion correction effect is poor when correcting distorted images, failing to meet the requirements of high-precision image analysis and applications. Attached Figure Description
[0026] The accompanying drawings, which are included to provide a further understanding of the invention and form part of this application, illustrate exemplary embodiments of the invention and, together with their description, serve to explain the invention and do not constitute an undue limitation thereof. In the drawings:
[0027] Figure 1 This is a flowchart of an optional method for correcting distorted images according to an embodiment of the present invention;
[0028] Figure 2 This is a flowchart of an optional method for obtaining the pixel coordinates of each pixel in a target distorted image according to an embodiment of the present invention;
[0029] Figure 3 This is a schematic diagram of an optional distorted image correction device according to an embodiment of the present invention;
[0030] Figure 4 This is a hardware structure block diagram of an electronic device (or mobile device) according to an embodiment of the present invention for a method of correcting distorted images. Detailed Implementation
[0031] To enable those skilled in the art to better understand the present invention, the technical solutions of the present invention will be clearly and completely described below with reference to the accompanying drawings of the embodiments of the present invention. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort should fall within the scope of protection of the present invention.
[0032] It should be noted that the terms "first," "second," etc., in the specification, claims, and accompanying drawings of this invention are used to distinguish similar objects and are not necessarily used to describe a specific order or sequence. It should be understood that such data can be interchanged where appropriate so that the embodiments of the invention described herein can be implemented in orders other than those illustrated or described herein. Furthermore, the terms "comprising" and "having," and any variations thereof, are intended to cover a non-exclusive inclusion; for example, a process, method, system, product, or apparatus that comprises a series of steps or units is not necessarily limited to those steps or units explicitly listed, but may include other steps or units not explicitly listed or inherent to such processes, methods, products, or apparatus.
[0033] To facilitate understanding of the present invention by those skilled in the art, some terms or nouns involved in the various embodiments of the present invention are explained below:
[0034] Homography is a transformation method in the field of computer vision that can map a set of points on one plane to another. Mathematically, homography refers to the linear relationship between two vector spaces. In two-dimensional space, if there exists a matrix H such that any point (x,y) is transformed by H to obtain new coordinates (u,v), then this transformation is called two-dimensional homography.
[0035] It should be noted that the method and apparatus for correcting distorted images in this disclosure can be used in the field of biometrics for correcting distorted images, and can also be used in any field other than biometrics for correcting distorted images. This disclosure does not limit the application field of the method and apparatus for correcting distorted images.
[0036] It should be noted that all information (including but not limited to user device information, user personal information, etc.) and data (including but not limited to data used for analysis, stored data, and displayed data) disclosed herein are information and data authorized by the user or fully authorized by all parties. Furthermore, the collection, use, and processing of such data must comply with the relevant laws, regulations, and standards of the relevant countries and regions, and corresponding access points are provided for users to choose to authorize or refuse. For example, this system has interfaces with relevant users or organizations. Before obtaining relevant information, a request to obtain the information must be sent to the aforementioned user or organization through the interface, and the relevant information will be obtained only after receiving consent from the aforementioned user or organization.
[0037] The following embodiments of the present invention can be applied to various image correction systems / applications / devices. The present invention performs initial correction on the distorted image through inverse mapping transformation, and then uses an adaptive anti-aliasing model to optimize the correction of the distorted image, obtaining the target corrected image. This improves the image correction effect and achieves high-precision correction of distorted images.
[0038] The following embodiments of the present invention can be applied to image recognition correction systems / applications / devices in financial institutions. The present invention corrects distorted images by preserving scale through inverse mapping transformation and an anti-aliasing model, preventing drastic scaling during distortion correction and thus improving image correction accuracy. This allows the corrected image to be directly applied to image recognition, increasing recognition accuracy and enhancing the user experience.
[0039] The embodiments of the present invention can also be applied to facial image acquisition systems / applications / devices in the lobbies of financial institutions. By correcting the acquired facial images before recognition, the accuracy of facial recognition can be greatly improved.
[0040] The embodiments of the present invention can also be applied to various image business processing applications / devices of financial institutions, such as facial recognition login, image verification in the business processing process, etc. By preserving the scale inverse mapping transformation and anti-aliasing model, the acquired images are corrected to obtain images with less distortion, thereby improving the efficiency and accuracy of subsequent image verification, improving business processing efficiency, and enhancing the user experience.
[0041] The present invention will now be described in detail with reference to various embodiments.
[0042] Example 1
[0043] According to an embodiment of the present invention, an embodiment of a method for correcting distorted images is provided. It should be noted that the steps shown in the flowchart in the accompanying drawings can be executed in a computer system such as a set of computer-executable instructions. Furthermore, although a logical order is shown in the flowchart, in some cases, the steps shown or described may be executed in a different order than that shown here.
[0044] Figure 1 This is a flowchart of an optional method for correcting distorted images according to an embodiment of the present invention, such as... Figure 1 As shown, the method includes the following steps:
[0045] Step S101: Obtain the pixel coordinates of each pixel in the target distorted image;
[0046] Step S102: Input the pixel coordinates of each pixel into the image correction model, output the initial correction coordinates corresponding to each pixel, and calculate the deformation convolution kernel size based on the initial correction coordinates. The image correction model corrects the target distorted image through inverse mapping transformation.
[0047] Step S103: Input each pixel coordinate into the Jacobian calculation formula to obtain the Jacobian value of each pixel coordinate, and perform inverse mapping calculation on the Jacobian value to obtain the inverse mapped Jacobian value.
[0048] Step S104: Calculate the Gaussian convolution kernel for each pixel based on the deformable convolution kernel size and the Jacobian value after inverse mapping;
[0049] Step S105: Input the Gaussian convolution kernel into the anti-aliasing correction model, output the optimized correction coordinates of each pixel, and obtain the target corrected image.
[0050] Through the above steps, firstly, the pixel coordinates of each pixel in the target distorted image are obtained. Then, the pixel coordinates of each pixel are input into the image correction model, which outputs the initial correction coordinates corresponding to each pixel. Based on the initial correction coordinates, the deformation convolution kernel size is calculated. Next, each pixel coordinate is input into the Jacobian calculation formula to obtain the Jacobian value of each pixel coordinate. The Jacobian value is then inversely mapped to obtain the inversely mapped Jacobian value. Then, based on the deformation convolution kernel size and the inversely mapped Jacobian value, the Gaussian convolution kernel of each pixel is calculated. Finally, the Gaussian convolution kernel is input into the anti-aliasing correction model, which outputs the optimized correction coordinates of each pixel, thus obtaining the target corrected image.
[0051] In this embodiment, firstly, an inverse mapping transformation is performed on each pixel in the distorted image using an image correction model to obtain initial correction coordinates. Then, the inverse mapping Jacobian value and deformation convolution kernel size of each pixel are calculated, followed by the calculation of the Gaussian convolution kernel for each pixel. Finally, the target image is corrected according to the anti-aliasing correction model to obtain the target corrected image. The calculation of the inverse mapping Jacobian value and deformation convolution kernel size both consider the adaptive relationship between each pixel and its surrounding pixels. The anti-aliasing correction model can achieve adaptive anti-aliasing correction of distorted images, realizing high-precision correction of distorted images. This solves the technical problem in related technologies where the distortion correction effect is poor when correcting distorted images, failing to meet the requirements of high-precision image analysis and application.
[0052] The embodiments of the present invention will now be described in detail with reference to the steps described above.
[0053] It should be noted that images captured by camera lenses will exhibit a certain degree of distortion, which can interfere with subsequent applications. For example, in image recognition, it may prevent accurate identification of user information, resulting in a poor user experience. Camera lens distortion can be categorized into radial distortion and tangential distortion. Radial distortion causes varying degrees and directions of deformation in the final image, resulting in barrel or pincushion distortion depending on the angle of curvature. Tangential distortion introduces errors during coordinate system transformations during the imaging process.
[0054] Step S101: Obtain the pixel coordinates of each pixel in the target distorted image.
[0055] Figure 2 This is a flowchart illustrating an optional method for obtaining the pixel coordinates of each pixel in a target distorted image according to an embodiment of the present invention, such as... Figure 2 As shown, the steps to obtain the pixel coordinates of each pixel in the target distorted image include:
[0056] Step S201: Receive source image information of the target distorted image, wherein the source image information includes at least one of the following: source image size, source pixel value;
[0057] Step S202: Scan the target distorted image to obtain scanned image information, wherein the scanned image information includes at least one of the following: scanned image size, scanned pixel values;
[0058] Step S203: If the source image size is not equal to the scanned image size, or if the source pixel value is not equal to the scanned pixel value, determine that there are missing pixels in the target distorted image, and fill in the missing pixels.
[0059] It should be noted that most image distortion occurs at the image boundaries. Distortion causes the image boundaries to become distorted, resulting in black areas. In other words, distorted images will have missing pixels. For distorted images, it is necessary to first obtain the information of the captured source image, then compare the source image information with the distorted image information obtained by scanning to confirm whether there are missing pixels, and then fill in the missing parts to obtain a complete image.
[0060] It should be noted that when filling an image, you can use interpolation based on neighboring pixel values, that is, use the average or median value of the surrounding known pixels to replace the original pixel value at the missing position; or you can use linear interpolation, that is, calculate the gray level of the pixel at the missing position based on the equation of the straight line between two adjacent points, and then fill according to the gray level; or you can use bilinear interpolation, that is, first perform linear interpolation calculations in the horizontal and vertical directions on the two-dimensional plane, and then perform a weighted average of the results to obtain the gray level of the missing pixel, and then fill according to the gray level.
[0061] Step S204: Establish a coordinate system for the target distorted image after filling processing, and collect the pixel coordinates of each pixel.
[0062] It should be noted that after obtaining the complete distorted image, a coordinate system is established for the distorted image, or the distorted image is placed on a drawing software with a pixel coordinate system, so that the pixel coordinates of each pixel in the distorted image can be obtained. During the correction process, each pixel coordinate can be corrected separately to obtain a complete corrected image.
[0063] Optionally, after obtaining the pixel coordinates of each pixel in the target distorted image, the method includes: calculating the coordinate difference between each pixel and its adjacent pixels in the target distorted image to obtain a first coordinate difference.
[0064] It should be noted that, due to image distortion, the coordinate difference between each pixel and its neighboring pixels needs to be calculated before correction. After the inverse mapping transformation, the coordinate difference of each transformed pixel is calculated again. If the coordinate difference is within the preset range, the next step can be performed; otherwise, the initial correction needs to be performed again to obtain the correct correction coordinates.
[0065] Step S102: Input the pixel coordinates of each pixel into the image correction model, output the initial correction coordinates corresponding to each pixel, and calculate the deformation convolution kernel size based on the initial correction coordinates.
[0066] It should be noted that the image correction model uses inverse mapping transformation to correct distorted images. This embodiment of the invention employs a distortion correction model formula that can preserve image scale: Where k is a single-scale coefficient that determines the type of image distortion, (x d ,y d (x) represents the pixel coordinates of each pixel. c Represents the initial corrected x-coordinate, y c The initial ordinate is represented by the distortion correction model formula. The above distortion correction model formula is determined only by the change in one direction. When the image distortion is corrected, the image can be transformed while maintaining its scale. This prevents the image from being drastically scaled during distortion correction, thereby reducing the negative impact caused by image scaling and resulting in fewer errors in the correction. This improves the efficiency and accuracy of image distortion correction.
[0067] The following is an inverse mapping derivation of the above formula: Rewritten as Then substitute it into From this, we can obtain a value about x. d A quartic equation in one variable: Transformation Mathematically, it can be proven that a univariate n-degree equation has n solutions when n ≤ 4, and these solutions can be found algebraically. Only when n > 4, Galois theory proves that the standard form of a univariate n-degree equation cannot be solved algebraically. 4 +bx 3 +cx 2 +dx+e=0 (a,b,c,d,e∈R,anda≠0), but it can be seen that the above quartic equation is a special form without cubic terms, and can be solved by completing the square.
[0068] The above special form of the quartic equation can be written as t 4 +αt 2 +βt+γ=0 (α,β,γ∈R), then α,β,γ in the above formula are:
[0069]
[0070] Since there are no cubic terms in the expression, the remaining quartic and quadratic terms can be transformed into the sum of squares of the linear and quadratic terms, i.e., it becomes:
[0071] (t 2 +z) 2 =(2z-α)t 2 -βt-γ 2 +z 2 ;
[0072] At the same time, the expression on the right side also needs to be transformed into a perfect square form, which requires satisfying the discriminant Δ = b of the quadratic equation. 2 If -4ac = 0, then we can obtain a cubic equation in z: Δ = (-β) 2 -4(2z-α)(-γ+z 2 =0, which is -8z 3 +4αz 2 +8γz+β 2 -4αγ=0, thus obtaining According to Cardin's formula, the values of p and q are:
[0073]
[0074] Using Cardin's formula, the solution for z in this case is:
[0075]
[0076] Since the root test of the cubic equation determines that only one solution satisfies the real number solution, we get z = z0. Substituting this into the initial quartic equation:
[0077]
[0078] Taking the square root of both sides simultaneously, due to the introduction of the concept of imaginary numbers... Therefore, the equation after taking the square root still holds true regardless of whether the result calculated from the expression in the square root is negative:
[0079]
[0080]
[0081] We can obtain a quadratic equation in t, and calculate the discriminant Δ as follows:
[0082]
[0083] The solution to the equation can then be obtained using the quadratic formula:
[0084]
[0085] Therefore, the inverse mapping formula for the distortion correction model that preserves scale can be obtained as follows:
[0086]
[0087]
[0088] By performing an inverse mapping transformation, the initial correction coordinates can be obtained, thereby obtaining the initial correction image.
[0089] Optionally, after inputting the pixel coordinates of each pixel into the image correction model and outputting the initial correction coordinates corresponding to each pixel, the method includes: calculating the coordinate difference between the initial correction coordinates of each pixel and the initial correction coordinates of adjacent pixels to obtain a second coordinate difference; and determining that the corrected initial correction coordinates are correct coordinates if both the first coordinate difference and the second coordinate difference are less than or equal to a preset difference threshold.
[0090] It should be noted that after calculating the initial correction coordinates of each pixel, it is also necessary to perform a difference operation on the initial correction coordinates of each pixel and each of its neighboring pixels. Only when the difference between the coordinates before and after correction is within the preset difference threshold can the correct value be determined.
[0091] Optionally, the step of calculating the deformable convolution kernel size based on the initial correction coordinates includes: determining the convolution region based on the initial correction coordinates of each pixel; calculating the area of the convolution region to obtain the deformable convolution kernel size.
[0092] It should be noted that in the process of mapping the distorted image to the initial corrected image, for a certain pixel (x′, y′) on the initial corrected image, a convolution region needs to be constructed using this pixel. The convolution region determined by this pixel and its surrounding pixels is a square region, and the side length of the region is determined according to the Gaussian radius. Due to the influence of distortion, the inverse mapping transformation results in a deformed quadrilateral. A suitable bounding rectangle needs to be calculated according to the degree of deformation. At this time, the size of the rectangle is the deformation convolution kernel size of the pixel (x′, y′). The deformation convolution kernel size corresponding to each pixel is calculated and stored.
[0093] Step S103: Input each pixel coordinate into the Jacobian calculation formula to obtain the Jacobian value of each pixel coordinate, and perform inverse mapping calculation on the Jacobian value to obtain the inverse mapped Jacobian value.
[0094] It should be noted that after calculating the size of the deformed convolution kernel, it is also necessary to calculate the Jacobian value of each pixel to obtain the inverse mapping Jacobian value. First, a dedicated Jacobian value array is established to store the Jacobian value of each pixel. The storage array needs to be consistent with the image size of the original distorted image and correspond one-to-one with each pixel. Then, the specific pixel coordinates (x, y) on the distorted image are substituted into the Jacobian calculation formula to obtain the Jacobian value corresponding to each point. Based on the properties of Jacobian, the Jacobian value corresponding to the inverse mapping is obtained by calculating the inverse mapping Jacobian value of each pixel according to the above steps.
[0095] Step S104: Calculate the Gaussian convolution kernel for each pixel based on the deformable convolution kernel size and the Jacobian value after inverse mapping.
[0096] Optionally, the formula for calculating the Gaussian convolution kernel is: in, G represents the Gaussian convolution kernel. c (x) represents the deformation convolution kernel size, x0 represents the pixel coordinates, and x represents the initial correction coordinates. The Jacobian ratio is represented by h after the inverse mapping, and h represents the homography. -1 This represents the inverse mapping.
[0097] It should be noted that after calculating the deformation convolution kernel size and the Jacobian value of the inverse mapping for each pixel, substituting them into the calculation formula of the Gaussian convolution kernel can yield the Gaussian convolution kernel, which is used for subsequent anti-aliasing correction calculations.
[0098] Step S105: Input the Gaussian convolution kernel into the anti-aliasing correction model, output the optimized correction coordinates of each pixel, and obtain the target corrected image.
[0099] Optionally, the calculation formula used in the anti-aliasing correction model is: in, This represents the pixel coordinates of each pixel in the target distorted image. H represents the optimized correction coordinates, and H represents the homography transformation. -1 Represents the inverse mapping transformation. This indicates sampling of the image, and I represents the interpolation operation. This represents the Gaussian convolution kernel.
[0100] It should be noted that by inputting the Gaussian convolution kernel calculated in the above steps into the anti-aliasing correction formula, the optimized correction coordinates of each pixel can be obtained. The optimized image not only corrects the distortion, but also reduces the aliasing distortion generated during the correction process. The corrected image is more accurate and realistic than the image obtained by high-frequency filtering, which is convenient for subsequent high-precision image applications.
[0101] Optionally, after inputting the Gaussian convolution kernel into the anti-aliasing correction formula and outputting the optimized correction coordinates of each pixel to obtain the target correction image, the method further includes: performing interpolation on each pixel in the target correction image to obtain the optimized coordinates of each pixel; and filling the optimized coordinates into the target correction image to obtain the optimized target correction image.
[0102] It should be noted that the target correction image is subjected to another interpolation operation to make the image smoother and reduce image distortion. The embodiments of the present invention do not limit the type of interpolation operation. Appropriate interpolation operations can be selected according to the actual situation, such as nearest neighbor interpolation operation, bilinear interpolation operation, etc., to finally obtain the optimized target correction image.
[0103] Through the above embodiments, facial images can be corrected and optimized, and then the optimized facial images can be applied to facial recognition. Other images captured by camera devices or monitoring devices can also be corrected and optimized, and the optimized images can be applied to high-precision recognition fields, etc.
[0104] Through the above embodiments, scale-preserving inverse mapping transformation and anti-aliasing model are used to correct distorted images, so that the images do not undergo drastic scaling during distortion correction, thereby improving the image correction accuracy. This allows the corrected images to be directly applied to image recognition, improving image recognition accuracy and enhancing the user experience.
[0105] The following is a detailed description with reference to another embodiment.
[0106] Example 2
[0107] The image distortion correction device provided in this embodiment includes multiple implementation units, each of which corresponds to a specific implementation step in Embodiment 1 above.
[0108] Figure 3 This is a schematic diagram of an optional distortion image correction device according to an embodiment of the present invention, such as... Figure 3 As shown, the correction device includes: an acquisition unit 31, a first output unit 32, a second output unit 33, a calculation unit 34, and a third output unit 35, wherein,
[0109] Acquisition unit 31 is used to acquire the pixel coordinates of each pixel in the target distorted image;
[0110] The first output unit 32 is used to input the pixel coordinates of each pixel into the image correction model, output the initial correction coordinates corresponding to each pixel, and calculate the deformation convolution kernel size based on the initial correction coordinates. The image correction model corrects the target distorted image through inverse mapping transformation.
[0111] The second output unit 33 is used to input each pixel coordinate into the Jacobian calculation formula to obtain the Jacobian value of each pixel coordinate, and to perform inverse mapping calculation on the Jacobian value to obtain the inverse mapped Jacobian value.
[0112] The calculation unit 34 is used to calculate the Gaussian convolution kernel for each pixel based on the deformable convolution kernel size and the Jacobian value after inverse mapping;
[0113] The third output unit 35 is used to input the Gaussian convolution kernel into the anti-aliasing correction model and output the optimized correction coordinates of each pixel to obtain the target correction image.
[0114] The aforementioned image distortion correction device acquires the pixel coordinates of each pixel in the target distorted image through the acquisition unit 31; inputs the pixel coordinates of each pixel into the image correction model through the first output unit 32, outputs the initial correction coordinates corresponding to each pixel, and calculates the deformation convolution kernel size based on the initial correction coordinates; inputs the pixel coordinates of each pixel into the Jacobian calculation formula through the second output unit 33, obtains the Jacobian value of each pixel coordinate, and performs inverse mapping calculation on the Jacobian value to obtain the inverse-mapped Jacobian value; calculates the Gaussian convolution kernel of each pixel through the calculation unit 34 based on the deformation convolution kernel size and the inverse-mapped Jacobian value; and inputs the Gaussian convolution kernel into the anti-aliasing correction model through the third output unit 35, outputs the optimized correction coordinates of each pixel, and obtains the target corrected image.
[0115] In this embodiment, firstly, an inverse mapping transformation is performed on each pixel in the distorted image using an image correction model to obtain initial correction coordinates. Then, the inverse mapping Jacobian value and deformation convolution kernel size of each pixel are calculated, followed by the calculation of the Gaussian convolution kernel for each pixel. Finally, the target image is corrected according to the anti-aliasing correction model to obtain the target corrected image. The calculation of the inverse mapping Jacobian value and deformation convolution kernel size both consider the adaptive relationship between each pixel and its surrounding pixels. The anti-aliasing correction model can achieve adaptive anti-aliasing correction of distorted images, realizing high-precision correction of distorted images. This solves the technical problem in related technologies where the distortion correction effect is poor when correcting distorted images, failing to meet the requirements of high-precision image analysis and application.
[0116] Optionally, the distortion image correction device further includes: a first receiving module for receiving source image information of the target distorted image, wherein the source image information includes at least one of the following: source image size and source pixel value; a first scanning module for scanning the target distorted image to obtain scanned image information, wherein the scanned image information includes at least one of the following: scanned image size and scanned pixel value; a first determining module for determining that the target distorted image has missing pixels when the source image size is not equal to the scanned image size, or when the source pixel value is not equal to the scanned pixel value, and filling in the missing pixels; and a first establishing module for establishing a coordinate system for the filled target distorted image and acquiring the pixel coordinates of each pixel.
[0117] Optionally, the distortion correction device further includes: a first calculation module, used to calculate the coordinate difference between each pixel and its adjacent pixels in the target distorted image, to obtain a first coordinate difference.
[0118] Optionally, the distortion image correction device further includes: a second calculation module, used to calculate the coordinate difference between the initial corrected coordinates of each pixel and the initial corrected coordinates of adjacent pixels to obtain a second coordinate difference; and a second determination module, used to determine that the corrected initial corrected coordinates are correct coordinates when both the first coordinate difference and the second coordinate difference are less than or equal to a preset difference threshold.
[0119] Optionally, the first output unit 32 includes: a third determining module for determining the convolution region based on the initial correction coordinates of each pixel; and a third calculating module for calculating the area of the convolution region to obtain the size of the deformable convolution kernel.
[0120] Optionally, the distortion correction device further includes: a first calculation module for performing interpolation calculations on each pixel in the target correction image to obtain the optimized coordinates of each pixel; and a first filling module for filling the optimized coordinates into the target correction image to obtain the optimized target correction image.
[0121] Optionally, the formula for calculating the Gaussian convolution kernel is: in, G represents the Gaussian convolution kernel. c (x) represents the deformation convolution kernel size, x0 represents the pixel coordinates, and x represents the initial correction coordinates. The Jacobian value represents the result of the inverse mapping, and h represents the homography. -1 This represents the inverse mapping.
[0122] Optionally, the calculation formula used in the anti-aliasing correction model is: in, This represents the pixel coordinates of each pixel in the target distorted image. H represents the optimized correction coordinates, and H represents the homography transformation. -1 Represents the inverse mapping transformation. This indicates sampling of the image, and I represents the interpolation operation. This represents the Gaussian convolution kernel.
[0123] The aforementioned correction device may also include a processor and a memory. The aforementioned acquisition unit 31, first output unit 32, second output unit 33, calculation unit 34, third output unit 35, etc., are all stored in the memory as program units, and the processor executes the aforementioned program units stored in the memory to realize the corresponding functions.
[0124] The processor described above contains a kernel, which retrieves the corresponding program units from memory. One or more kernels can be configured, and the distorted image can be corrected by adjusting the kernel parameters.
[0125] The aforementioned memory may include non-permanent memory in computer-readable media, such as random access memory (RAM) and / or non-volatile memory, such as read-only memory (ROM) or flash RAM, and the memory includes at least one memory chip.
[0126] According to another aspect of the present invention, a computer-readable storage medium is also provided, the computer-readable storage medium including a stored computer program, wherein, when the computer program is executed, it controls the device where the computer-readable storage medium is located to perform any of the above-described methods for correcting distorted images.
[0127] According to another aspect of the present invention, an electronic device is also provided, including one or more processors and a memory, the memory being used to store one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors cause the one or more processors to implement any of the above-described methods for correcting distorted images.
[0128] This application also provides a computer program product, which, when executed on a data processing device, is suitable for executing an initialization program with the following method steps: obtaining the pixel coordinates of each pixel in the target distorted image; inputting the pixel coordinates of each pixel into an image correction model, outputting the initial correction coordinates corresponding to each pixel, and calculating the deformation convolution kernel size based on the initial correction coordinates; inputting each pixel coordinate into a Jacobi calculation formula to obtain the Jacobi value of each pixel coordinate, and performing inverse mapping calculation on the Jacobi value to obtain the inverse-mapped Jacobi value; calculating the Gaussian convolution kernel of each pixel based on the deformation convolution kernel size and the inverse-mapped Jacobi value; inputting the Gaussian convolution kernel into an anti-aliasing correction model, outputting the optimized correction coordinates of each pixel, and obtaining the target corrected image.
[0129] Figure 4 This is a hardware structure block diagram of an electronic device (or mobile device) according to an embodiment of the present invention for a method of correcting distorted images. Figure 4 As shown, an electronic device may include one or more ( Figure 4 The processor 402 (which may include, but is not limited to, a microprocessor MCU or a programmable logic device FPGA, etc.) and the memory 404 for storing data may also be included. In addition, it may include: a display, an input / output interface (I / O interface), a universal serial bus (USB) port (which may be included as one of the ports of the I / O interface), a network interface, a keyboard, a power supply, and / or a camera. Those skilled in the art will understand that... Figure 4 The structure shown is for illustrative purposes only and does not limit the structure of the electronic device described above. For example, the electronic device may also include... Figure 4 The more or fewer components shown, or having the same Figure 4 The different configurations shown.
[0130] The sequence numbers of the above embodiments of the present invention are for descriptive purposes only and do not represent the superiority or inferiority of the embodiments.
[0131] In the above embodiments of the present invention, the descriptions of each embodiment have different focuses. For parts not described in detail in a certain embodiment, please refer to the relevant descriptions of other embodiments.
[0132] In the several embodiments provided in this application, it should be understood that the disclosed technical content can be implemented in other ways. The device embodiments described above are merely illustrative; for example, the division of units can be a logical functional division, and in actual implementation, there may be other division methods. For instance, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the displayed or discussed mutual coupling, direct coupling, or communication connection may be through some interfaces; the indirect coupling or communication connection between units or modules may be electrical or other forms.
[0133] The units described as separate components may or may not be physically separate. The components shown as units may or may not be physical units; that is, they may be located in one place or distributed across multiple units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0134] Furthermore, the functional units in the various embodiments of the present invention can be integrated into one processing unit, or each unit can exist physically separately, or two or more units can be integrated into one unit. The integrated unit can be implemented in hardware or as a software functional unit.
[0135] If the integrated unit is implemented as a software functional unit and sold or used as an independent product, it can be stored in a computer-readable storage medium. Based on this understanding, the technical solution of the present invention, in essence, or the part that contributes to the prior art, or all or part of the technical solution, can be embodied in the form of a software product. This computer software product is stored in a storage medium and includes several instructions to cause a computer device (which may be a personal computer, server, or network device, etc.) to execute all or part of the steps of the methods described in the various embodiments of the present invention. The aforementioned storage medium includes various media capable of storing program code, such as USB flash drives, read-only memory (ROM), random access memory (RAM), portable hard drives, magnetic disks, or optical disks.
[0136] The above description is only a preferred embodiment of the present invention. It should be noted that for those skilled in the art, several improvements and modifications can be made without departing from the principle of the present invention, and these improvements and modifications should also be considered within the scope of protection of the present invention.
Claims
1. A method for correcting distorted images, characterized in that, include: Obtain the pixel coordinates of each pixel in the target distorted image; The pixel coordinates of each pixel are input into the image correction model, the initial correction coordinates corresponding to each pixel are output, and the deformation convolution kernel size is calculated based on the initial correction coordinates. The image correction model corrects the target distorted image through inverse mapping transformation. Each pixel coordinate is input into the Jacobian calculation formula to obtain the Jacobian value of each pixel coordinate, and the Jacobian value is inversely mapped to obtain the inversely mapped Jacobian value. Calculate the Gaussian convolution kernel for each pixel based on the deformed convolution kernel size and the Jacobian value after inverse mapping; The process of inputting the Gaussian convolution kernel into the anti-aliasing correction model and outputting the optimized correction coordinates of each pixel to obtain the target corrected image includes: substituting the calculated Gaussian convolution kernel into the calculation formula of the anti-aliasing correction model to calculate the optimized correction coordinates of each pixel and obtain the target corrected image.
2. The correction method according to claim 1, characterized in that, The steps to obtain the pixel coordinates of each pixel in the target distorted image include: Receive source image information of the target distorted image, wherein the source image information includes at least one of the following: source image size, source pixel value; The target distorted image is scanned to obtain scanned image information, wherein the scanned image information includes at least one of the following: scanned image size and scanned pixel values; If the size of the source image is not equal to the size of the scanned image, or if the source pixel value is not equal to the scanned pixel value, it is determined that the target distorted image has missing pixels, and the missing pixels are filled in. A coordinate system is established for the target distorted image after the filling process, and the pixel coordinates of each pixel are collected.
3. The correction method according to claim 1, characterized in that, After obtaining the pixel coordinates of each pixel in the target distorted image, the process includes: The coordinate difference between each pixel and its adjacent pixels in the target distorted image is calculated to obtain the first coordinate difference.
4. The correction method according to claim 3, characterized in that, After inputting the pixel coordinates of each pixel into the image correction model and outputting the initial correction coordinates corresponding to each pixel, the process includes: Calculate the coordinate difference between the initial corrected coordinates of each pixel and the initial corrected coordinates of its adjacent pixels to obtain the second coordinate difference; If both the first coordinate difference and the second coordinate difference are less than or equal to a preset difference threshold, the corrected initial calibration coordinates are determined to be correct coordinates.
5. The correction method according to claim 1, characterized in that, The steps for calculating the deformed convolution kernel size based on the initial correction coordinates include: The convolution region is determined based on the initial correction coordinates of each pixel. Calculate the area of the convolution region to obtain the size of the deformable convolution kernel.
6. The correction method according to claim 1, characterized in that, After inputting the Gaussian convolution kernel into the anti-aliasing correction formula and outputting the optimized correction coordinates of each pixel to obtain the target corrected image, the process further includes: Interpolation is performed on each pixel in the target corrected image to obtain the optimized coordinates of each pixel; The optimized coordinates are filled into the target correction image to obtain the optimized target correction image.
7. The correction method according to claim 1, characterized in that, The formula for calculating the Gaussian convolution kernel is: ,in, This refers to the Gaussian convolution kernel. ( The ) represents the size of the deformable convolution kernel. Represents the pixel coordinates, This represents the initial correction coordinates. ( ) represents the Jacobian value after the inverse mapping. This represents a homography mapping. This represents the inverse mapping.
8. The correction method according to claim 1, characterized in that, The calculation formula used in the anti-aliasing correction model is as follows: ,in, This represents the pixel coordinates of each pixel in the target distorted image. This represents the optimized correction coordinates. This represents a homography transformation. Represents the inverse mapping transformation. Indicates sampling of the image. This indicates an interpolation operation. This represents the Gaussian convolution kernel.
9. A device for correcting distorted images, characterized in that, include: The acquisition unit is used to acquire the pixel coordinates of each pixel in the target distorted image; The first output unit is used to input the pixel coordinates of each pixel into the image correction model, output the initial correction coordinates corresponding to each pixel, and calculate the deformation convolution kernel size based on the initial correction coordinates. The image correction model corrects the target distorted image through inverse mapping transformation. The second output unit is used to input each pixel coordinate into the Jacobian calculation formula to obtain the Jacobian value of each pixel coordinate, and to perform inverse mapping calculation on the Jacobian value to obtain the inversely mapped Jacobian value. The calculation unit is used to calculate the Gaussian convolution kernel for each pixel based on the deformed convolution kernel size and the Jacobian value after inverse mapping; The third output unit is used to input the Gaussian convolution kernel into the anti-aliasing correction model and output the optimized correction coordinates of each pixel to obtain the target corrected image. The unit includes: substituting the calculated Gaussian convolution kernel into the calculation formula of the anti-aliasing correction model to calculate the optimized correction coordinates of each pixel and obtain the target corrected image.
10. A computer-readable storage medium, characterized in that, The computer-readable storage medium includes a stored computer program, wherein, when the computer program is executed, it controls the device on which the computer-readable storage medium is located to perform the method for correcting distorted images according to any one of claims 1 to 8.
11. An electronic device, characterized in that, It includes one or more processors and a memory, the memory being used to store one or more programs, wherein when the one or more programs are executed by the one or more processors, the one or more processors cause the one or more processors to implement the method for correcting distorted images according to any one of claims 1 to 8.