A parallel computing optimization method for principal component analysis document skew correction algorithm
By optimizing the principal component analysis algorithm through parallel computing on multiple servers and multi-core processors, the problems of slow speed and high development cost of the document tilt correction algorithm are solved, achieving faster correction speed and lower business costs.
Patent Information
- Application Number
- CN202211278413.7
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2022-10-19
- Publication Date
- 2025-10-17
- Estimated Expiration
- 2042-10-19
AI Technical Summary
Existing document deskew algorithms are slow, expensive to develop, and difficult to port to different computer platforms, especially those without graphics processors.
By distributing multi-page tilted document images to multiple servers and leveraging the parallel computing capabilities of multi-core processors and graphics processors, the principal component analysis algorithm is decomposed into multiple sub-problems, which are processed on multiple cores and computing units respectively, including pixel summation, dimensionality reduction, and variance calculation, thereby optimizing the calculation process.
It significantly improves the speed of document tilt correction, shortens user waiting time, reduces server operating costs, and improves commercial benefits.
Smart Images

Figure CN115631492B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The present application belongs to the field of data correction technology improvement, and particularly relates to a parallel computing optimization method for a principal component analysis document skew correction algorithm. BACKGROUND
[0002] In the process of obtaining an electronic document by scanning or taking a photo, due to the fact that human actions are not accurate and faultless, the phenomenon of document angle skew inevitably occurs. This phenomenon will cause adverse effects on reading and subsequent processing. Therefore, it is necessary to correct the scanned or photographed document that has been skewed. The currently common correction algorithm technical path includes a principal component analysis algorithm, a Hough transform algorithm (also known as Hough transform), a connected domain-based algorithm, etc.
[0003] Among them, the principal component analysis algorithm has simple logic and strong interpretability. Its principle is as follows: step one: set the precision parameters, including the range of attempted rotation and the step angle. Set the initial angle to 0. Step two: rotate the picture to the preset angle. Step three: sum the picture data by row to reduce the dimension to one dimension. Step four: record the correspondence between the preset angle and the variance of this one-dimensional array. Step five: set the next preset angle according to the precision parameter until all angles are tried. Step six: find the preset angle with the maximum variance, which is the correction angle predicted by this algorithm. Since the existing principal component analysis algorithm has a large amount of calculation and a long calculation time, its commercial value is less than that of several algorithms proposed subsequently.
[0004] However, the code implementation of the Hough transform is relatively complex and needs to be developed again for specific mathematical dependent libraries or graphics processors, which has a high development cost and is not suitable for running on computers without graphics processors. It is difficult to migrate this algorithm between different computer platforms and programming languages. Therefore, its commercial value is still limited.
[0005] The code implementation of the connected domain-based algorithm is also relatively complex, has a high development cost, and has little speed improvement. Therefore, its commercial value is still limited.
[0006] Therefore, there is currently a need for a document skew correction technical solution with higher correction speed and faster development speed. SUMMARY
[0007] The present application aims to provide a parallel computing optimization method for a principal component analysis document skew correction algorithm, which aims to solve the technical problems of the existing document skew correction algorithm, such as slow running speed, high development cost, dependence on specific hardware, and difficulty in migrating to different computer platforms.
[0008] The application is implemented by a principal component analysis document skew correction algorithm parallel computing optimization method, which comprises the following steps.
[0009] S1, distribute the input multi-page skewed pictures to multiple different servers running cloud functions;
[0010] S2, the server assigns multiple preset angle transformation verification mathematical features to multiple cores of the logical processor for processing;
[0011] S3, a single core assigns multiple row pixel summation dimension reduction to a single core of the logical processor or a single computing unit of the graphics processor for calculation and processing;
[0012] S4, obtain multiple pixel summations by using the maximum precision summation of the logical processor or the graphics processor operator;
[0013] S5, calculate the variance of the one-dimensional array after dimension reduction of the picture to obtain the mathematical features of the rotated picture, and retain the maximum rotation angle of the picture, and according to the rotation angle, rotate each picture according to the corresponding angle and show it to the user or enter the next process.
[0014] A further technical solution of the application is that in step S1, the principal component analysis of the multi-page skewed document picture is converted into processing of multiple single-page skewed document pictures.
[0015] A further technical solution of the application is that in step S1, the web front end or the client wakes up the cloud function process running on multiple different servers through the API gateway or the load balancer one by one.
[0016] A further technical solution of the application is that in step S2, the single multi-angle transformation verification is divided into multiple single-angle verifications in the cloud function process.
[0017] A further technical solution of the application is that in step S3, the two-dimensional picture is summed and dimension reduced according to the row of pixels, the variance of the summation result is calculated, and the summation operation of different rows does not need to depend on the data outside the row.
[0018] A further technical solution of the application is that in step S4, the single-row pixel summation dimension reduction is converted into multiple pixel integration, multiple low-precision pixel values are spliced and merged into a high-precision value, the operator is used to split the high-precision summation result into multiple low-precision summation results, and four or more pixels are summed by one operation.
[0019] A further technical solution of the application is that in step S5, the following steps are included.
[0020] S51, reducing the image after rotating the single-page image by a predetermined angle to one dimension and calculating the variance of the one-dimensional array to obtain mathematical features of the rotated image;
[0021] S52, after obtaining mathematical features of the single-page image at all angles, retain the correction angle corresponding to the largest rotation angle of the image;
[0022] S53: Rotate each image according to its corresponding correction angle based on the correction angle of the single-page image and transfer it to the next processing flow or display it to the user according to the business flow.
[0023] A further technical solution of the present invention is: before inputting the tilted document image into the algorithm, the color image is preprocessed into a grayscale image, and each pixel in the image is marked as an integer data with a size between 0-255 and a precision of 32 bits.
[0024] A further technical solution of the present invention is that the arithmetic unit of the logic processor has an accuracy of 512 bits.
[0025] The beneficial effects of this invention are: fully utilizing the concurrent capabilities of multi-core processors to improve correction speed without increasing the performance of a single processor core. This shortens the waiting time for users to use the document skew correction function, significantly improving the user experience, and reducing server operating costs when commercializing the document skew correction function, thereby improving commercial benefits. BRIEF DESCRIPTION OF THE DRAWINGS
[0026] Figure 1 This is a flow chart of the principal component analysis algorithm on hardware before optimization in the existing technology.
[0027] Figure 2 This is a flow chart of a parallel computing optimization method for a principal component analysis document skew correction algorithm provided by an embodiment of the present invention.
[0028] Figure 3 The present invention provides a flowchart of a parallel computing optimization method for executing a principal component analysis document tilt correction algorithm.
[0029] Figure 4 This is the flow diagram of the optimized principal component analysis algorithm on hardware. DETAILED DESCRIPTION
[0030] To overcome the shortcomings of existing document de-skew correction algorithms, such as slow execution speed, high development costs, reliance on specialized hardware, and difficulty porting to different computer platforms, the present invention provides an optimization method for a principal component analysis (PCA) algorithm. This optimization method increases the PCA algorithm's execution speed by more than 100 times, while maintaining the original algorithm's advantages of being independent of specialized hardware, simple logic, and easy to develop and port. This makes the optimized PCA algorithm more commercially viable than existing algorithms such as the Hough transform and the connected domain algorithm.
[0031] The basic idea of the present application is to decompose the multi-page skewed document picture principal component analysis problem into sub-problems that can be combined, and to perform synchronous calculation on multi-core, multi-computers of multiple servers, to make full use of all available computing resources to solve the problem, so as to improve the calculation speed, and to improve the performance of the principal component analysis technology route with relatively poor commercial value to a level with significant commercial value advantage.
[0032] As shown in Figure 2 The parallel computing optimization method for the principal component analysis document skew correction algorithm provided by the present application is described in detail as follows:
[0033] Step S1, distribute the input multi-page skewed pictures to multiple different servers running cloud functions; the web front end or client software reads the user input multi-page randomly skewed documents. The pictures of different pages in one input document are scanned or taken separately, and the tilt angles of each page are basically independent random numbers. Therefore, the problem of principal component analysis of multi-page skewed document pictures can be divided into multiple single-page skewed document picture processing problems. The web front end or client can wake up multiple cloud function processes one by one through an API gateway or a load balancer. These processes can work on different servers and use multiple server resources to calculate subsequent problems.
[0034] Step S2, the server assigns multiple preset angle transformation verification mathematical features to multiple cores of the logical processor for processing; the principle of the principal component analysis algorithm is that the principal component analysis problem of a single-page skewed document picture is specifically manifested as a problem of trying to transform and verifying the mathematical features of each possible correct tilt angle. A single multi-angle transformation verification problem can be divided into multiple single-angle transformation verification problems, and a single single-angle transformation verification problem can be assigned to a single core of a logical processor for execution, so as to fully utilize the computing power of the multi-core logical processor.
[0035] Step S3, the single core assigns multiple row pixel summation dimension reduction to a single core of the logical processor or a single computing unit of the graphics processor for calculation and processing; the single-angle transformation verification problem is specifically manifested as a problem of summing and dimension reducing the pixels of a two-dimensional picture by row, and the summation operation on different rows does not need to rely on data outside the row. Therefore, a single multi-row pixel summation dimension reduction problem can be divided into multiple single-row pixel summation dimension reduction problems, and a single single-row pixel summation dimension reduction problem can be assigned to a single core of a logical processor or a single computing unit of a graphics processor for execution.
[0036] Step S4, the maximum precision of the pixel of the logic processor or the graphics processor operator is summed to obtain a plurality of pixel sums; the single-row pixel sum dimension reduction problem is specifically manifested as a problem of integrating a plurality of pixels, and the precision of a single pixel is far less than the maximum precision supported by the logic processor or the graphics processor operator. Therefore, a plurality of low-precision pixel values can be spliced and combined into a high-precision value, the high-precision value is summed by using the operator, and then the high-precision value is split into a plurality of low-precision sum results. Thus, four or more pixels are summed simultaneously in one addition operation.
[0037] Step S5, the variance of the one-dimensional array after the picture dimension reduction is calculated to obtain the mathematical feature of the picture after rotation, the maximum rotation angle of the picture is retained, and each picture is rotated according to the corresponding angle and then displayed to the user or enters the next process; after a single-page picture is rotated at a certain angle, the picture is reduced to one dimension, and the variance of the one-dimensional array is calculated. The value is referred to as the mathematical feature of the picture after rotation; after obtaining the mathematical features of the single-page picture at all angles, the rotation angle corresponding to the maximum mathematical feature of the picture is retained. The value is referred to as the correction angle of the single-page picture; after obtaining the correction angles of all single-page pictures, each picture is rotated according to the corresponding correction angle and then transferred to the next processing process or displayed to the user according to the business needs.
[0038] After taking the above optimization steps on a test set of 27 randomly tilted pictures and 27 non-tilted pictures, a total of 54 pictures, the speed of correcting the tilted document using the principal component analysis algorithm with the same precision parameters on the same server resources is improved by more than 100 times, as shown in the following table.
[0039] Before optimization After optimization Total computation time 248.4 seconds 2.1 seconds Single page computation time 4.6 seconds 0.038 seconds Correction accuracy (TP / TP+FP) 1.0 1.0 Correction recall (TP / TP+FN) 1.0 1.0
[0040] Since the principal component analysis method for correcting the tilted document does not need to understand the color information contained in the picture pixels, before inputting the tilted document picture into the algorithm, the color picture should be preprocessed into a grayscale picture. After the processing is completed, each pixel in the picture is represented as an integer data with a size between 0 and 255.
[0041] Firstly, whether the computer or server deploying the algorithm has a graphics processor or not, the following operations need to be performed:
[0042] 1. Start the API gateway or load balancer, set the balancing strategy to round robin, and guide the entrance traffic to the cloud function or interface service.
[0043] 2. Write client code to enable users to input multiple pages of tilted picture data into the computer, and request the API gateway or load balancer to process the data page by page.
[0044] 3. Write the server code and set the preset rotation angle range and step. Preferably, the angle range is set to 3.2 degrees and the step is 0.2 degrees.
[0045] 4. Rotate the image to be tested according to each alternative angle to obtain a set of alternative images.
[0046] 5. Preferably, a sub-thread or coroutine is started for each candidate image for subsequent processing.
[0047] Then, if the deployed computer or server does not have a graphics processor, perform the following operations: After grayscale image preprocessing, each pixel in the image is represented as integer data with a size between 0 and 255 and a precision of 32 bits.
[0048] Use a logical processor with an arithmetic unit precision of 512 bits, and use an operating environment and programming language that support the high-precision addition function of the arithmetic unit.
[0049] 1. Define a sum function, taking as input an array of pixels in a row of the image, as described in steps 2-5 below.
[0050] 2. Combine the two sets of low-precision original pixel data into two high-precision numbers and input them into the operator for summation.
[0051] 3. Split the sum result into an array consisting of the sum of two pixels.
[0052] 4. Continue to merge the two pixel sum arrays into high-precision numbers and sum them until the sum of all pixels in the entire row is obtained.
[0053] 5. If a child thread or coroutine has been started before, the sum function is directly called on each row of the candidate image. Otherwise, the image is first divided into multiple sub-regions by row (the number of regions does not exceed the number of processor cores). Then, a child thread or coroutine is started for each sub-region, and the sum function is called on each row within the child thread or coroutine. This results in a one-dimensional array consisting of the sum of the pixel values in each row.
[0054] 6. Calculate the variance of the array obtained in the previous step. This variance is called the mathematical feature of this image at this rotation angle.
[0055] If the computer or server being deployed has a graphics processor, follow these steps:
[0056] Use an operating environment and programming language that supports calling a graphics processing unit (GPU) for pixel summation.
[0057] 1. Call the GPU library function to transfer the candidate image to the GPU storage space (video memory)
[0058] 2、If the sub-thread or coroutine has been started before, directly call the summation function in the GPU library function to sum up the alternative picture row by row. Otherwise, first divide the picture into multiple sub-regions by row (the number of regions is at most the number of processor cores), then start a sub-thread or coroutine for each sub-region, and call the summation function in the GPU library function to sum up row by row in the sub-thread or coroutine. Thus, a one-dimensional array composed of the sum of the pixel values of each row is obtained.
[0059] 3、Calculate the variance of the array obtained in the previous step, which is called the mathematical feature of the picture at this rotation angle.
[0060] After completing the above steps, each server process will obtain an array composed of the mathematical features of each alternative picture.
[0061] Then, each server process needs to find the alternative picture corresponding to the maximum value in the array, which is the picture after tilt correction. The server returns the picture to the client asynchronously, and the client can display the corrected picture or transfer the picture stream to the next processing link according to business needs. Thus, the optimized principal component analysis algorithm based on the patent is completed.
[0062] The above only describes the preferred embodiments of the present application and is not intended to limit the present application. Any modifications, equivalent replacements and improvements made within the spirit and principles of the present application shall be included in the protection scope of the present application.
Claims
1. A parallel computing optimization method for principal component analysis document tilt correction algorithm, characterized in that: The parallel computing optimization method of the principal component analysis document tilt correction algorithm comprises the following steps: S1. Distribute the input multiple pages of tilted images to multiple different servers running cloud functions. S2. The server distributes multiple preset angle transformation verification mathematical features to multiple cores of the logical processor for processing; S3, a single core assigns the summation and dimensionality reduction of multiple rows of pixels to a single core of a logical processor or a single computing unit of a graphics processor for computational processing; S4, using the maximum precision sum of pixels of the logic processor or the graphics processor arithmetic unit to obtain the sum of multiple pixels; S5. After reducing the image dimension, calculate the variance of the one-dimensional array to obtain the mathematical characteristics of the rotated image, retain the maximum rotation angle of the image, rotate each image according to its corresponding angle, and then display it to the user or proceed to the next process; In step S1, principal component analysis is performed on the multi-page tilted document image to convert it into multiple single-page tilted document images for processing; The step S2 divides the single multi-angle transformation verification into multiple single-angle verification mathematical feature problems during the cloud function process.
2. The parallel computing optimization method for the principal component analysis document tilt correction algorithm according to claim 1 is characterized in that: In step S1, the web front-end or client wakes up the cloud function processes running on multiple different servers in a one-to-one ratio through the API gateway or load balancer.
3. The parallel computing optimization method for the principal component analysis document tilt correction algorithm according to claim 2 is characterized in that: The step S3 reduces the dimensionality of the two-dimensional image by summing up the pixels in rows, and then calculates the variance of the summation result. The summation operation for different rows does not need to rely on data outside the row.
4. The parallel computing optimization method for the principal component analysis document tilt correction algorithm according to claim 3 is characterized in that: In step S4, the single-row pixel summation is converted into multiple pixel integration by dimensionality reduction, multiple low-precision pixel values are spliced and merged into a high-precision value, and the high-precision summation is split into multiple low-precision summation results using an operator, and four or more pixels are obtained through one operation for summation.
5. The parallel computing optimization method for the principal component analysis document tilt correction algorithm according to claim 4 is characterized in that: The step S5 includes the following steps: S51, reducing the image after rotating the single-page image by a predetermined angle to one dimension and calculating the variance of the one-dimensional array to obtain mathematical features of the rotated image; S52, after obtaining mathematical features of the single-page image at all angles, retain the correction angle corresponding to the largest rotation angle of the image; S53: Rotate each image according to its corresponding correction angle based on the correction angle of the single-page image and transfer it to the next processing flow or display it to the user according to the business flow.
6. The parallel computing optimization method for the principal component analysis document tilt correction algorithm according to claim 5 is characterized in that: Before inputting the tilted document image into the algorithm, the color image is preprocessed into a grayscale image, and each pixel in the image is marked as an integer data with a size between 0 and 255 and a precision of 32 bits.
7. The parallel computing optimization method for the principal component analysis document tilt correction algorithm according to claim 6 is characterized in that: The arithmetic unit precision of the logic processor is 512 bits.
Citation Information
Patent Citations
Complex structure file image inclination quick detection method
CN101149801A
Double view window based route characteristic identifying, deviation measuring, and accurate positioning method
CN105444741A