A fast image correction method based on classical statistical methods
By identifying the four corner points of the image through grayscale, binarization, FoF clustering and projection based on classic statistical methods, the problems of inaccurate corner point identification and long running time in the existing technology are solved, and efficient image correction effect is achieved.
Patent Information
- Application Number
- CN202210895435.1
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-07-26
- Publication Date
- 2025-10-03
- Estimated Expiration
- 2042-07-26
AI Technical Summary
The existing image correction methods based on Canny edge detection and Hough transform have problems such as inaccurate recognition of the four corner points and long running time, resulting in poor image correction effects.
Based on the classical statistical method, the four corner points are identified through grayscale, binarization, FoF clustering and projection, the edge detection step is skipped, and the four vertices of the image are determined by combining rotation projection and fixed-angle projection for perspective transformation correction.
It improves the accuracy of corner point recognition and the success rate of image correction, simplifies the operation steps and reduces the running time, thus improving user work efficiency.
Smart Images

Figure CN115272120B_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the field of image processing, and in particular to a fast correction method for images based on classical statistical methods. Background Art
[0002] In daily life, people sometimes need to use their mobile phones to take photos of certain documents and send them to others, or upload documents like receipts and test papers. If a mobile phone is used to take a photo directly, the resulting image will contain both the desired target and unwanted background areas. Furthermore, image tilt can make the image difficult to read or inconvenient to use. Image correction methods can address these issues, ensuring that the corrected image is exactly the desired target drawing. After obtaining the captured image, an algorithm detects the four corner points of the target drawing, and then uses perspective changes to obtain the desired image.
[0003] Typical methods for detecting four corner points include grayscale image-based corner detection, binary image-based corner detection, and contour curve-based corner detection. However, these methods can easily detect unwanted corner points, significantly complicating subsequent perspective transformations and potentially preventing the desired image from being successfully transformed. Therefore, existing technical solutions use edge detection to detect four edges and thus determine the four corner points, rather than directly using corner detection. For example, image correction methods based on Canny edge detection and Hough transform can detect four edges and thus determine the four corner points.
[0004] Specifically, the existing image correction method based on Canny edge detection and Hough transform includes: first graying the image, then using the Canny edge detection operator to extract the image edges (the obtained edges are noisy and incomplete), binarizing and then using Hough transform to remove some noise, performing straight line edge detection, finding the four edges of the target drawing, finding the four corner points of the target drawing through the intersection of the four edges, and finally using the open source computer vision library OpenCV to perform perspective transformation on the target drawing to obtain the corrected image.
[0005] The disadvantages of existing image correction methods based on Canny edge detection and Hough transform are: 1) the existing technology does not accurately identify the four corner points of the target drawings in some data sets, so that the required image cannot be smoothly transformed, resulting in poor image correction effect;
[0006] 2) The existing technology has a complex structure and takes a long time to run. Summary of the Invention
[0007] The present invention aims to provide a fast image correction method based on classical statistical methods to solve the problem of low image correction accuracy, while simplifying the image correction operation steps and reducing the running time to improve user work efficiency.
[0008] To achieve the above objectives, the present invention provides a method for rapid correction of images based on classical statistical methods, comprising:
[0009] S1: grayscale the image to be processed to obtain a grayscale image;
[0010] S2: Binarize the grayscale image after grayscale processing to obtain bright pixels;
[0011] S3: Use FoF clustering to perform cluster analysis on the bright pixels. The largest cluster obtained by the cluster analysis corresponds to the target drawing, thereby selecting the area of the target drawing;
[0012] S4: performing rotational projection and fixed-angle projection on the coordinates of the bright pixel points in the target drawing area to respectively determine the four vertices of the target drawing;
[0013] S5: Obtaining a first perspective transformation matrix according to the coordinates of the four vertices of the image to be processed and the coordinates of the four vertices of the target drawing obtained by the rotation projection, and performing perspective transformation on the first perspective transformation matrix and the image to be processed to obtain an image corrected by the rotation projection step;
[0014] S6: Obtaining a second perspective transformation matrix based on the coordinates of the four vertices of the image to be processed and the coordinates of the four vertices of the target drawing obtained by fixed-angle projection, and performing perspective transformation on the image to be processed based on the second perspective transformation matrix to obtain an image corrected by the fixed-angle projection step;
[0015] S7: Compare the images obtained in step S5 and step S6 to see if they are consistent. If they are consistent, select one image to output; otherwise, select the image with better correction effect to output.
[0016] Before step S1, the method further includes step S0: using the PIL library in Python to read the image to be processed and converting its data into two-dimensional data.
[0017] In step S1, when performing grayscale processing, the grayscale formula used is:
[0018] gray=R×0.299+G×0.587+B×0.114,
[0019] Where gray is the grayscale value, R represents the red pixel value, G represents the green pixel value, and B represents the blue pixel value; or
[0020] In step S1, when performing grayscale processing, the grayscale formula used is:
[0021] gray={[R^2.2+(1.5×G)^2.2+(0.6×B)^2.2] / [1+1.5^2.2+0.6^2.2]}^(1 / 2.2),
[0022] Among them, gray is the grayscale value, R represents the red pixel value, G represents the green pixel value, and B represents the blue pixel value.
[0023] In step S2, the binarization process includes: first setting a grayscale threshold, updating the grayscale of pixels whose grayscale is greater than the grayscale threshold to the grayscale maximum value, and updating the grayscale of pixels whose grayscale is less than the grayscale threshold to the grayscale minimum value, thereby achieving binarization and selecting bright pixel points.
[0024] The grayscale threshold is determined by using one of a histogram bimodal method and a kernel density estimation method;
[0025] The histogram bimodal method includes:
[0026] Step S21: obtaining a grayscale statistical histogram of the grayscale image, which is a bimodal graph; Step S22: taking the grayscale value corresponding to the valley between the two peaks of the grayscale statistical histogram as the grayscale threshold;
[0027] The kernel density estimation method includes:
[0028] S21': fitting the grayscale image data using non-parametric kernel estimation to obtain a kernel density estimation curve, which is a bimodal graph; Step S22': taking the grayscale value corresponding to the valley between the two peaks of the kernel density estimation curve as the grayscale threshold.
[0029] Among them, the point with the largest vertical coordinate value is selected as the first peak of the bimodal graph, and its corresponding grayscale value is recorded as p;
[0030] The gray value x of the second peak of the bimodal graph is calculated according to the following formula:
[0031] argmax D=(xp) 2 ×hist(x),
[0032] Among them, x is the grayscale value, and hist(x) is the vertical coordinate value of the bimodal graph corresponding to the grayscale value.
[0033] Before step S3, the method further includes step S30: randomly selecting a predetermined proportion of bright pixel points from all bright pixel points using random.choice() of the numpy library in Python.
[0034] The step S4 comprises:
[0035] S41: Establish a coordinate system with the bottom edge of the image to be processed as the x-axis, the left edge as the y-axis, and the lower left vertex as the origin O, and set A = (1, 1) and B = (1, -1);
[0036] S42: performing rotational projection on the bright pixel points in the area of the target drawing;
[0037] S43: Performing fixed-angle projection on bright pixel points in the area of the target drawing.
[0038] The step S42 includes:
[0039] S421: Project the bright pixel points onto the lines OA and OB respectively;
[0040] S422: After the projection is completed, the lines OA and OB are simultaneously rotated 1° clockwise with point O as the center, and then the bright pixel points are projected onto the two new lines OA and OB obtained after the rotation of the lines OA and OB;
[0041] S423: Repeat step S422 until the lines OA and OB have been rotated 90° clockwise;
[0042] S424: Among the projections made on line OA and the line obtained by rotation, find the projection with the largest difference between the maximum and minimum projection values, and use the pixel points corresponding to the maximum and minimum projection values as the two vertices of the first diagonal line. Similarly, among the projections made on line OB and the line obtained by rotation, find the projection with the largest difference between the maximum and minimum projection values, and use the pixel points corresponding to the maximum and minimum projection values as the two vertices of the second diagonal line.
[0043] And the step S43 includes:
[0044] S431: Project the bright pixel points onto the line OA. The point with the smallest projection value is the lower left vertex, and the point with the largest projection value is the upper right vertex.
[0045] S432: Project the bright pixel points onto the straight line OB. The point with the smallest projection value is the upper left vertex, and the point with the largest projection value is the lower right vertex.
[0046] The fast image correction method of the present invention, which is based on classical statistical methods, identifies four corner points through clustering and projection, skipping the edge detection step in the prior art, thereby avoiding the problem of inaccurate edge detection caused by Canny edge detection and Hough transform in the prior art. Moreover, the combination of the two projection methods can correct images with excessive horizontal tilt angles as well as vertical tilt images, thereby improving the accuracy of corner point recognition, increasing the success rate and accuracy of image correction, and improving the image correction effect.
[0047] In addition, the fast correction method of the image based on the classical statistical method of the present invention realizes the corner point detection of the target drawing in two steps of clustering and projection, so the running time is short. Other inventions use edge detection based on the Canny operator and Hough transform, and then obtain the corner points of the target drawing by finding the intersection of the four edges in three steps. Therefore, the structure of the present invention is simpler than other inventions and improves the running efficiency. BRIEF DESCRIPTION OF THE DRAWINGS
[0048] Figure 1 The figure is an overall flow chart of a method for rapid correction of an image based on a classical statistical method according to an embodiment of the present invention.
[0049] Figure 2 It is the kernel density estimation curve.
[0050] Figure 3 is a schematic diagram of the image to be processed.
[0051] Figure 4 It is a schematic diagram of the principle of projecting bright pixel points onto straight lines OA and OB respectively.
[0052] Figure 5 It is a schematic diagram of the positions of the four vertices obtained by projection. DETAILED DESCRIPTION
[0053] The present invention will be further described below with reference to specific examples. It should be understood that the following examples are only used to illustrate the present invention and are not intended to limit the scope of the present invention.
[0054] The principle of the fast image correction method based on classical statistical methods of the present invention is as follows: the edges of the target drawing are found by clustering the grayscale and binarized images, and then the pixel points of the target drawing are projected in a specific direction to obtain the four corner points of the target drawing. Finally, the cv2 library in Python is used to perform perspective transformation to obtain the corrected image.
[0055] like Figure 1 As shown, the fast correction method of the picture based on the classical statistical method of the present invention includes the following steps:
[0056] Step S0: Reading the image to be processed, which specifically includes: using the PIL library in Python to read the image to be processed and converting its data into two-dimensional data for subsequent grayscale processing;
[0057] Step S1: grayscale the image to be processed to obtain a grayscale image;
[0058] Among them, when performing grayscale processing, the grayscale formula used is a common grayscale formula. In this embodiment, the grayscale formula used is:
[0059] gray=R×0.299+G×0.587+B×0.114,
[0060] Among them, gray is the grayscale value, R represents Red (red pixel value), G represents Green (green pixel value), and B represents Blue (blue pixel value).
[0061] In other embodiments, the grayscale formula used may also be a Gamma correction grayscale formula, that is, the grayscale formula is:
[0062] gray={[R^2.2+(1.5×G)^2.2+(0.6×B)^2.2] / [1+1.5^2.2+0.6^2.2]}^(1 / 2.2).
[0063] Step S2: Binarize the grayscale image after grayscale processing to obtain bright pixels;
[0064] Binarization can convert a grayscale image into a binary image. Specifically, the binarization process involves first setting a grayscale threshold, updating the grayscale of pixels with grayscale greater than the grayscale threshold to the grayscale maximum value (i.e., updating to black), and updating the grayscale of pixels with grayscale less than the grayscale threshold to the grayscale minimum value (i.e., updating to white), thereby achieving binarization and selecting the bright pixels in the image.
[0065] The grayscale threshold value can be obtained by any of the following methods:
[0066] Method Histogram Bimodal Method
[0067] Since the present invention limits the background to be as pure as possible and in strong contrast with the target drawing, the histogram bimodal method includes:
[0068] Step S21: obtaining a grayscale statistical histogram of the grayscale image, where the grayscale statistical histogram is a bimodal graph;
[0069] Step S22: taking the gray value corresponding to the valley between the two peaks of the gray statistical histogram as the gray threshold. Thus, the gray threshold (critical gray value) is obtained using the histogram bimodal method.
[0070] Specifically, in step S32, the point with the largest vertical coordinate value (i.e., the number of pixels) of the bimodal graph is selected as the first peak, and its corresponding grayscale value is recorded as p;
[0071] The gray value x of the second peak of the bimodal graph is calculated according to the following formula:
[0072] argmax D=(xp) 2 ×hist(x),
[0073] Where x is the grayscale value, ranging from 0 to 255, and hist(x) is the ordinate value (i.e., the number of pixels) of the bimodal graph corresponding to the grayscale value. In other words, the x that maximizes D is the grayscale value corresponding to the required second peak.
[0074] After obtaining the two peaks, the gray value of the point with the smallest ordinate value (ie, the number of pixels) in the gray histogram between the two peaks is taken as the gray threshold.
[0075] For different pictures, the binarization threshold obtained by this method is also different.
[0076] Method 2: Kernel density estimation method
[0077] The kernel density estimation method specifically includes:
[0078] Step S21': fitting the grayscale image data using non-parametric kernel estimation to obtain a kernel density estimation curve, wherein the kernel density estimation curve is a bimodal graph;
[0079] Since the present invention limits the background to be as pure as possible and in strong contrast with the target drawing, the histogram after grayscale conversion is a bimodal graph. The kernel density estimation curve can be obtained by fitting the data using non-parametric kernel estimation, such as Figure 2 As shown in Figure 3, the kernel density estimation curve obtained by the kernel density estimation method is also a bimodal graph, with the horizontal axis being the grayscale value and the vertical axis being the density, indicating that the overall distribution is a mixed distribution of bright and dark parts.
[0080] Step S22 ′: taking the grayscale value corresponding to the valley between the two peaks of the kernel density estimation curve as the grayscale threshold.
[0081] The kernel density estimation method can use various kernel functions, including the Gaussian kernel, triangular kernel, Epanechnikov kernel, cosine kernel, and biweight kernel. Simulation experiments show that using different kernel functions does not affect the determination of the two peaks and the valley, and the Gaussian kernel is generally sufficient. The peaks correspond to the areas with the highest and second highest density in the kernel density estimation curve. Once the two peaks are found, the grayscale value of the point with the lowest density between the two peaks is the desired grayscale threshold. The binarization threshold obtained by this method is different for different images, making it adaptive.
[0082] Step S30: downsampling the bright pixels to improve the operation efficiency;
[0083] In this embodiment, the purpose of this step is to reduce the amount of computation by reducing the number of pixels used for subsequent clustering and projection, thereby increasing the operating speed. In other embodiments, step S30 may be omitted.
[0084] Step S30 includes: using random.choice() of the numpy library in Python to randomly select a predetermined proportion of bright pixels from all bright pixels; in this embodiment, the predetermined proportion is one twenty-fifth.
[0085] Random selection here means sampling according to a uniform distribution, randomly selecting one twenty-fifth of all bright pixels.
[0086] The predetermined ratio can vary within a wide range. The closer the predetermined ratio is to 0, the faster the operation speed. However, as the predetermined ratio decreases, the image resolution decreases, which leads to a decrease in operation accuracy, that is, the recognition deviation of the four corner points may be too large. The closer the predetermined ratio is to 1, the better the operation result, but the operation speed also decreases.
[0087] Step S3: Use FoF clustering to perform cluster analysis on the bright pixels. The largest cluster obtained by the cluster analysis corresponds to the target drawing, thereby selecting the area of the target drawing;
[0088] In this embodiment, since step S30 is included, the bright pixel points refer to the bright pixel points that have been downsampled.
[0089] The background of the original image to be processed may accidentally include some drawings we don’t need (such as Figure 3 The target drawing has the largest area, so the largest cluster corresponds to the target drawing. The clustering process records the category and coordinates of each pixel. The category with the largest number of pixels is the largest cluster. Once the largest cluster is determined, the coordinates of all pixels in the target drawing can be determined, ultimately revealing the target drawing area.
[0090] When performing cluster analysis, the input data includes the horizontal and vertical coordinates of the bright pixel points.
[0091] FoF clustering actually uses kd tree to build index, through FoF clustering method and reverse clustering, so the parameter eps is set to 20 and min_samples is set to 1, where the parameter eps represents the radius of the neighborhood around a point, and min_samples represents the number of points contained in the neighborhood at least, where the distance between two points is measured using Euclidean distance.
[0092] Other clustering methods are less effective. In particular, the kd-tree combined with DBSCAN is a fast and effective FoF clustering method used in astronomy for cosmic particle clustering. Compared to most clustering algorithms, FoF clustering can be applied to millions of data points, allowing it to run quickly even without downsampling. Furthermore, FoF clustering does not require a predetermined number of clusters and can also remove some noise points.
[0093] Step S4: performing rotational projection and fixed-angle projection on the coordinates of the bright pixel points in the area of the target drawing to respectively determine the four vertices of the target drawing.
[0094] In this embodiment, because step S30 performs downsampling, the display Figure 3 The area of the target drawing only has 1 / 25 of all bright pixels, and only these pixels are used to perform step S4.
[0095] The step S4 comprises:
[0096] Step S41: Figure 4 As shown, Figure 3 The bottom of the original image to be processed is the x-axis, the left is the y-axis, the lower left vertex is the origin O to establish a coordinate system, and set A = (1, 1), B = (1, -1);
[0097] That is, point O = (0,0), which is the origin, point A is (1,1), point B is (1,-1), and straight lines OA and OB are already Figure 4 The coordinate data of the pixel points also use this coordinate system. The red points are the bright pixels of the target drawing.
[0098] The projection part is divided into two steps.
[0099] Step S42: performing rotational projection on the bright pixel points in the area of the target drawing.
[0100] Step S42 includes:
[0101] Step S421: Figure 4 As shown, the bright pixels are projected onto the straight lines OA and OB respectively;
[0102] Step S422: After the projection is completed, the lines OA and OB are simultaneously rotated 1° clockwise around point O, and then the bright pixel points are projected onto the two new lines OA and OB obtained after the rotation;
[0103] Step S423: Repeat step S422 (i.e., the straight lines OA and OB are rotated 1° clockwise each time after projection) until the straight lines OA and OB have been rotated 90° clockwise.
[0104] Step S424: Among the projections made on the straight line OA and the straight line obtained by rotation, find the projection with the largest difference between the maximum and minimum values of the projection, that is, the straight line is exactly parallel to a diagonal line of the target drawing, and the pixel points corresponding to the maximum and minimum values of the projection are used as the two vertices of the first diagonal line; similarly, among the projections made on the straight line OB and the straight line obtained by rotation, find the projection with the largest difference between the maximum and minimum values of the projection, so as to determine the two vertices of the second diagonal line.
[0105] Thus, the coordinate values of the four vertices are determined. The positional relationship of the four vertices is determined based on the coordinate values. Then, the lengths of the line segments between the vertices are compared to determine the long and short sides of the target image. Thus, the four vertices of the upper left, lower left, upper right, and lower right of the target image, i.e., the four corner points, are determined. Figure 5 As shown in the figure, the black points are the corner points. Rotated projection is suitable for paper with a large degree of skewness.
[0106] Step S43: Figure 4 As shown, fixed-angle projection is performed on the bright pixel points in the area of the target drawing, that is, the bright pixel points in the area of the target drawing are projected onto fixed straight lines OA and OB.
[0107] Step S43 includes:
[0108] Step S431: Project the bright pixel points onto the line OA. The point with the smallest projection value is the lower left vertex, and the point with the largest projection value is the upper right vertex.
[0109] Step S432: Project the bright pixel points onto the line OB. The point with the smallest projection value is the upper left vertex (the projection value can be negative), and the point with the largest projection value is the lower right vertex.
[0110] This will give you the four vertices, or corner points, of the target image. Fixed-angle projection is suitable for images with large distortion but small skew.
[0111] When encountering images with large degrees of skew and distortion, you can use both methods (rotational projection and fixed-angle projection) at the same time.
[0112] Step S5: obtaining a first perspective transformation matrix based on the coordinates of the four vertices of the original image to be processed and the coordinates of the four vertices of the target drawing obtained by rotational projection, and performing perspective transformation on the image to be processed based on the first perspective transformation matrix to obtain an image corrected by the rotational projection step;
[0113] Step S5 specifically includes: setting a00=(0,0), a01=(0,h), a10=(w,0), a11=(w,h) as the lower left vertex, upper left vertex, lower right vertex and upper right vertex of the original image to be processed, respectively, where w and h are the width and height of the original image to be processed, respectively; at the same time, setting b00, b01, b10, b11 as the lower left vertex, upper left vertex, lower right vertex and upper right vertex of the target drawing obtained by rotation projection, respectively; using the coordinates of a00, a01, a10, a11 and b00, b01, b10, b11 as input parameters of the getPerspectiveTransform() function respectively; using the getPerspectiveTransform() function to obtain the first perspective transformation matrix M, and using the warpPerspective() function to perform perspective transformation based on the first perspective transformation matrix M and the image to be processed input at the beginning to obtain the image corrected by the rotation projection step.
[0114] Therefore, the input parameters of the getPerspectiveTransform() function in Python's cv2 library are the coordinates of the four vertices of the target drawing obtained by the rotation projection method [b00, b01, b10, b11] and the coordinates of the four vertices of the original image to be processed [a00, a01, a10, a11], so that the result output by the getPerspectiveTransform() function is the perspective transformation matrix.
[0115] Among them, the width and height of the original image to be processed are obtained in the following way: the data obtained after reading the original image to be processed is three-dimensional data, that is, a set of data of h×w×3, where h represents the height here and w represents the width here.
[0116] Step S6: obtaining a second perspective transformation matrix based on the coordinates of the four vertices of the original image to be processed and the coordinates of the four vertices of the target drawing obtained by fixed-angle projection, and performing perspective transformation on the image to be processed based on the second perspective transformation matrix to obtain the image corrected by the fixed-angle projection step;
[0117] Step S6 specifically includes: setting c00, c01, c10, c11 as the lower left vertex, upper left vertex, lower right vertex and upper right vertex of the target drawing obtained by fixed-angle projection respectively; using the coordinates of a00, a01, a10, a11 and c00, c01, c10, c11 as input parameters of the getPerspectiveTransform() function respectively; using the getPerspectiveTransform() function to obtain a second perspective transformation matrix, and using the warpPerspective() function to perform perspective transformation based on the second perspective transformation matrix and the image to be processed input at the beginning to obtain the image corrected in the fixed-angle projection step.
[0118] Therefore, c00, c01, c10, and c11 are the lower left vertex, upper left vertex, lower right vertex, and upper right vertex of the target drawing obtained by the fixed-angle projection method. Repeat the above operation to obtain the image corrected by the fixed-angle projection step.
[0119] Step S7: Compare the images obtained in step S5 and step S6 to see if they are consistent. If they are consistent, select one image to output; otherwise, select the image with better correction effect.
[0120] The above description is merely a preferred embodiment of the present invention and is not intended to limit the scope of the present invention. Various modifications are possible. Any simple, equivalent changes and modifications made in accordance with the claims and description of the present invention are within the scope of protection of the patent claims. Anything not fully described in this invention is conventional technology.
Claims
1. A fast image correction method based on classical statistical methods, characterized in that: include: Step S1: grayscale the image to be processed to obtain a grayscale image; Step S2: Binarize the grayscale image after grayscale processing to obtain bright pixels; Step S3: Use FoF clustering to perform cluster analysis on the bright pixels. The largest cluster obtained by the cluster analysis corresponds to the target drawing, thereby selecting the area of the target drawing; Step S4: performing rotational projection and fixed-angle projection on the coordinates of the bright pixel points in the target drawing area to respectively determine the four vertices of the target drawing; Step S5: Obtaining a first perspective transformation matrix based on the coordinates of the four vertices of the image to be processed and the coordinates of the four vertices of the target drawing obtained by rotational projection, and performing perspective transformation on the image to be processed based on the first perspective transformation matrix to obtain an image corrected by the rotational projection step; Step S6: Obtain a second perspective transformation matrix based on the coordinates of the four vertices of the image to be processed and the coordinates of the four vertices of the target drawing obtained by fixed-angle projection, and perform perspective transformation on the image to be processed based on the second perspective transformation matrix to obtain an image corrected by the fixed-angle projection step; Step S7: Compare the images obtained in step S5 and step S6 to see if they are consistent. If they are consistent, select one image to output; Otherwise, the image with better correction effect is selected for output; The step S4 comprises: Step S41: Establish a coordinate system with the bottom edge of the image to be processed as the x-axis, the left edge as the y-axis, and the lower left vertex as the origin O, and set A = (1, 1) and B = (1, -1); Step S42: performing rotational projection on the bright pixel points in the area of the target drawing; Step S43: performing fixed-angle projection on the bright pixel points in the area of the target drawing; The step S42 includes: Step S421: Project the bright pixel points onto the lines OA and OB respectively; Step S422: After the projection is completed, the lines OA and OB are simultaneously rotated 1° clockwise around point O, and then the bright pixel points are projected onto the two new lines OA and OB obtained after the rotation; Step S423: Repeat step S422 until the lines OA and OB have been rotated 90° clockwise; Step S424: Among the projections made on line OA and the rotated line, find the projection with the largest difference between the maximum and minimum projections. The pixel points corresponding to the maximum and minimum projections are used as the two vertices of the first diagonal line. Similarly, among the projections made on line OB and the rotated line, find the projection with the largest difference between the maximum and minimum projections. The pixel points corresponding to the maximum and minimum projections are used as the two vertices of the second diagonal line. And the step S43 includes: Step S431: Project the bright pixel points onto the line OA. The point with the smallest projection value is the lower left vertex, and the point with the largest projection value is the upper right vertex. Step S432: Project the bright pixel points onto the line OB. The point with the smallest projection value is the upper left vertex, and the point with the largest projection value is the lower right vertex.
2. The method for rapid correction of images based on classical statistical methods according to claim 1, characterized in that: Before step S1, the method further includes step S0: using the PIL library in Python to read the image to be processed and converting its data into two-dimensional data.
3. The method for rapid correction of images based on classical statistical methods according to claim 1, characterized in that: In step S1, when performing grayscale processing, the grayscale formula used is: gray = R×0.299 + G×0.587 + B×0.114, Where gray is the grayscale value, R represents the red pixel value, G represents the green pixel value, and B represents the blue pixel value; or In step S1, when performing grayscale processing, the grayscale formula used is: gray = {[R ^ 2.2 + (1.5× G) ^ 2.2 + (0.6 × B) ^ 2.2] / [1 + 1.5 ^ 2.2 +0.6 ^ 2.2]} ^ (1 / 2.2), Among them, gray is the grayscale value, R represents the red pixel value, G represents the green pixel value, and B represents the blue pixel value.
4. The method for rapid correction of images based on classical statistical methods according to claim 1, characterized in that: In step S2, the binarization process includes: first setting a grayscale threshold, updating the grayscale of pixels whose grayscale is greater than the grayscale threshold to the grayscale maximum value, and updating the grayscale of pixels whose grayscale is less than the grayscale threshold to the grayscale minimum value, thereby achieving binarization and selecting bright pixel points.
5. The method for rapid correction of images based on classical statistical methods according to claim 4, characterized in that: The grayscale threshold is determined by using one of a histogram bimodal method and a kernel density estimation method; The histogram bimodal method includes: Step S21: obtaining a grayscale statistical histogram of the grayscale image, which is a bimodal graph; Step S22: taking the grayscale value corresponding to the valley between the two peaks of the grayscale statistical histogram as the grayscale threshold; The kernel density estimation method includes: Step S21': fitting the grayscale image data using non-parametric kernel estimation to obtain a kernel density estimation curve, which is a bimodal graph; Step S22': taking the grayscale value corresponding to the valley between the two peaks of the kernel density estimation curve as the grayscale threshold.
6. The method for rapid correction of images based on classical statistical methods according to claim 5, characterized in that: The point with the largest vertical coordinate value is selected as the first peak of the bimodal graph, and its corresponding grayscale value is recorded as p; The gray value x of the second peak of the bimodal graph is calculated according to the following formula: argmax D = (x - p) 2 × hist(x), Where x is the grayscale value, and hist(x) is the vertical coordinate value of the bimodal graph corresponding to the grayscale value.
7. The method for rapid correction of images based on classical statistical methods according to claim 1, characterized in that: Before step S3, the method further includes step S30: randomly selecting a predetermined proportion of bright pixel points from all bright pixel points using random.choice() of the numpy library in Python.
Citation Information
Patent Citations
Eye glint imaging in see-through computer display systems
US20160116979A1
Delayed Telop Aid
US20220050454A1