A document image tilt correction method based on freeman code
By using a document image tilt correction method based on Freeman codes, the problem of the influence of illustrations and tables in complex document images is solved, and a high-precision tilt correction effect is achieved.
Patent Information
- Application Number
- CN202310318258.5
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-03-29
- Publication Date
- 2026-01-20
- Estimated Expiration
- 2043-03-29
AI Technical Summary
Existing document image tilt correction algorithms suffer from low accuracy and lack of robustness when processing complex document images containing illustrations, tables, etc., and cannot effectively remove the influence of non-text images.
A Freeman code-based approach is adopted, which involves document image preprocessing, text connected component extraction, connected component thinning, and tilt angle calculation to filter out text connected components and remove noise. The tilt angle of the text connected components is then calculated using Freeman codes for correction.
It improves the accuracy and robustness of tilt correction for complex document images, effectively removes the influence of non-text images, and ensures the accuracy of overall tilt correction for document images.
Smart Images

Figure CN117253243B_ABST
Abstract
Description
TECHNICAL FIELD
[0001] The application belongs to the technical field of document image tilt correction, and particularly relates to a document image tilt correction method based on a freeman code. BACKGROUND
[0002] In daily life, when we take pictures or scan documents, due to changes in camera focus, shooting angles, lighting, etc., the generated electronic images may be tilted. The tilted electronic document images not only affect the reading of readers, but also affect OCR recognition. Therefore, it is necessary to correct the tilt of the document images, and the detection of the tilt angle of the document is a core step of the correction.
[0003] At present, common tilt detection algorithms include the projection method, the Hough transform method, the nearest neighbor method, the Fourier transform method, etc. The nearest neighbor method has low tilt angle detection accuracy, and the Fourier transform method has too large a calculation amount, so the two methods are less used. The projection method is one of the most common algorithms, which is simple and intuitive, but non-text images such as illustrations in the document will affect the accuracy of the algorithm; the Hough transform method mainly detects the tilt angle according to the straight lines in the document image, but when processing images without straight lines and with little text, detection errors may occur.
[0004] In summary, when correcting the tilt of complex document images containing illustrations, tables, etc., the existing common document image tilt algorithms have certain limitations and are not robust. Based on this, the application designs a document image tilt correction method based on a freeman code to solve the above problems. SUMMARY
[0005] To solve the above technical problems in the prior art, the application provides a document image tilt correction method based on a freeman code, which supports the tilt correction of complex document images containing illustrations, tables, etc.
[0006] The technical scheme adopted by the application is:
[0007] A document image tilt correction method based on a freeman code, characterized in that it specifically comprises the following steps:
[0008] S1: document image preprocessing;
[0009] The image is converted into a gray-scale image, and a binarization operation and morphological processing are performed on the gray-scale image;
[0010] S2: image text connected block extraction;
[0011] The text connected blocks and other image connected blocks in the complex document image are separated, the text connected blocks are screened out, the non-text images are removed, the influence of other images in the document image on the algorithm accuracy is reduced, and the robustness of the algorithm is improved;
[0012] S3: connected block image refinement processing;
[0013] The text connected blocks are refined, the skeleton of the text is extracted, burrs in the skeleton are removed, the image is further denoised, and the accuracy of the algorithm is improved;
[0014] S4: inclination calculation;
[0015] The contour of each connected block is extracted, the boundary tracking of the text connected block contour is performed using the Freeman code, the Freeman code calculation is performed, the chain code value of each connected block contour and the proportion occupied are calculated, and the angle corresponding to the highest proportion of the number of chain code values in the vertical and horizontal directions is taken as the inclination angle of the document image;
[0016] S5: document image inclination correction;
[0017] According to the inclination angle calculated in step S4, the document image is rotated to be vertical, and the inclination correction of the image is completed.
[0018] Further, in step S1, the document image preprocessing includes the following specific steps:
[0019] Convert the original document image into a gray-scale image: read the image, detect the channel number of the image, and if the image is three channels, convert it into a single-channel gray-scale image;
[0020] Perform a binaryzation operation on the gray-scale image: perform binaryzation calculation on the image by using a global binaryzation algorithm, which is beneficial to calculation and reduces the influence of uneven illumination when collecting the document image;
[0021] Perform morphological processing on the image: perform inflation operation on the image to connect characters together as much as possible; and perform erosion operation on the image to separate adjacent characters on the left and right.
[0022] Further, in step S2, the image text connected block extraction includes the following specific steps:
[0023] Find all connected blocks of the image: use the eight-connection algorithm in the seed filling algorithm to extract all connected domains and record the area of the circumscribed rectangle frame of each connected domain;
[0024] Extracting text connected domain: using area threshold method to remove non-text connected domain, calculating the average area of the outer rectangle frame of all connected blocks, the lower limit area is 0.5 times of the average area, and the upper limit area is 4 times of the average area, when the area of the outer rectangle frame of the connected block is in the area range, it is indicated that the connected block is a text connected block, and the non-text connected block in the image is removed.
[0025] Further, in step S3, the connected block image refinement processing includes the following specific steps:
[0026] Image refinement: the screened text connected block is refined, and the zhang-suen algorithm is used to extract the character skeleton;
[0027] Remove skeleton burr: due to the different extraction methods and the interference of noise in the skeleton extraction process, burrs of different degrees are generated, the burr is removed by burr length threshold value, and the accuracy of the algorithm is improved.
[0028] Further, in step S4, the inclination angle calculation includes the following specific steps:
[0029] Selecting a test angle range;
[0030] For each test angle, the original document image is rotated, and the contour of the text connected block after removing the burr is extracted;
[0031] The direction of each connected block contour is calculated, the boundary tracking is performed using the freeman code, and the calculated freeman code value represents the overall direction of the connected block;
[0032] In each connected block freeman code, the proportion of the number of chain code values corresponding to the vertical and horizontal directions is counted;
[0033] If the number of connected blocks is greater than 3, the highest and lowest items of the positive chain code proportion are removed, and then the average value is taken, and the angle corresponding to the highest average value is the inclination angle.
[0034] Compared with the prior art, the beneficial effects of the present application are reflected in:
[0035] 1. The present application supports complex document images containing illustrations, tables and the like, and the text connected block is screened based on the area threshold method of the outer rectangle frame of the connected block;
[0036] 2. The present application further removes noise points in the document image through character skeleton extraction and burr removal, and improves the accuracy of the algorithm;
[0037] 3. The overall direction of the text is obtained by tracking the Freeman code boundary of the text skeleton, and finally the angle corresponding to the highest proportion of horizontal and vertical is selected as the tilt angle, the overall document image is considered, and the accuracy of the algorithm is ensured. BRIEF DESCRIPTION OF DRAWINGS
[0038] Figure 1 A module diagram of the document image tilt correction method based on the Freeman code of the present application.
[0039] Figure 2 A specific flowchart of the document image tilt correction method based on the Freeman code of the present application.
[0040] Figure 3 A document tilt image of the first embodiment of the present application.
[0041] Figure 4 A rotated and corrected image of the first embodiment of the present application. DETAILED DESCRIPTION
[0042] The specific embodiments of the embodiments of the present application will be described in detail below with reference to the accompanying drawings. It should be understood that the specific embodiments described herein are only used to illustrate and explain the embodiments of the present application, and are not used to limit the embodiments of the present application.
[0043] It should be noted that the embodiments in the present application and the features in the embodiments can be combined with each other without conflict.
[0044] The present application will be described in detail below with reference to the accompanying drawings and in combination with exemplary embodiments.
[0045] REFERENCE Figures 1 to 4 The document image tilt correction method based on the Freeman code of the present application is performed according to the following steps:
[0046] S1: Document image preprocessing: converting the image into a gray-scale image, performing a binary operation and morphological processing on the image;
[0047] S2: Image text connected block extraction: separating the text connected block and other image connected blocks in the complex document image, screening out the text connected block, removing the images of illustrations, tables and the like, reducing the influence of other images in the document image on the accuracy of the algorithm, and improving the robustness of the algorithm;
[0048] S3: Connected block image thinning processing: thinning the text connected block, extracting the skeleton of the text, removing burrs in the skeleton, further denoising the image, and improving the accuracy of the algorithm;
[0049] S4: Inclination calculation: extract the outline of each connected block, use the freeman code to track the boundary of the text connected block outline, perform freeman code calculation, calculate the chain code value of each connected block outline and the proportion occupied, and take the angle corresponding to the highest proportion of the number of chain code values in the vertical and horizontal directions as the inclination angle of the document image;
[0050] S5: Document image inclination correction: according to the inclination angle calculated in S4, rotate the document image.
[0051] The embodiment one provides a document image inclination correction method based on freeman code.
[0052] I. Image preprocessing: the original image as shown in the figure is a complex document image containing illustrations; Figure 3
[0053] Convert the original document image into a gray-scale image. The image is three channels, which is converted into a single-channel gray-scale image.
[0054] Binarization operation on the gray-scale image: the image is binarized by using a global binarization algorithm.
[0055] Morphological processing of the image: since the text may be recognized as multiple connected domains during the search for connected blocks, and multiple characters may be recognized as a connected domain due to the close distance between the characters, the image is first dilated to connect the characters together as much as possible, and then eroded to separate the left and right adjacent characters.
[0056] II. Image effective connected block extraction: the text connected block extraction is performed on the preprocessed image, and the non-text connected domains such as illustrations and tables are removed. Specifically:
[0057] Finding all connected blocks of the image: using the eight-connection algorithm in the seed filling algorithm, all connected domains of the image are extracted, and the area of the bounding rectangle frame of each connected domain and the number of connected blocks are recorded.
[0058] Extracting text connected domains: using the area threshold method to remove non-text connected domains, the average area of the bounding rectangle frame of all connected blocks is calculated, the lower limit area is 0.5 times the average area, and the upper limit area is 4 times the average area. When the area of the bounding rectangle frame of the connected block is within the area range, the connected block is a text connected block, and the non-text connected block is removed.
[0059] III. Image thinning: since the freeman code-based algorithm has high requirements for the position of image pixels, the image needs to be further thinned to remove redundant pixels. Specifically:
[0060] The text connected blocks are refined, and the text skeleton is extracted by using the Zhang-Suen algorithm.
[0061] Spur removal: due to the different extraction methods and noise interference in the process of skeleton extraction, different degrees of spur will be generated, the spur is removed by the spur length threshold to improve the accuracy of the algorithm.
[0062] Four, the calculation of the angle of inclination: within a certain angle range, the document image is tracked by the freeman code boundary, the proportion of the freemen chain code value is calculated, and the angle corresponding to the highest proportion is taken as the angle of inclination.
[0063] Select the test angle range [-30, 30], rotate the original document image for each test angle, and extract the outline of the text connected block after removing the spur;
[0064] Calculate the direction of each connected block outline, track the boundary by using the freeman code, and the calculated freeman code value represents the overall direction of the text connected block;
[0065] In each connected block freeman code, the proportion of the number of chain code values (i.e. 0246) corresponding to the vertical and horizontal directions is calculated;
[0066] If the number of connected blocks is greater than 3, remove the highest and lowest positive chain code proportions, and then take the average value, the angle corresponding to the highest average value is the angle of inclination.
[0067] Five, document image tilt correction: based on the obtained angle of inclination, the document image is rotated and converted to complete the tilt correction of the image.
[0068] Although the embodiments of the present application have been shown and described above, it should be understood that the above embodiments are exemplary and should not be construed as limiting the present application, and those skilled in the art can make changes, modifications, replacements and variations to the above embodiments within the scope of the present application.
Claims
1. A document image tilt correction method based on Freeman codes, characterized in that, Specifically, the steps include the following: S1: Document image preprocessing; Convert the image to grayscale, then perform binarization and morphological processing on the grayscale image; S2: Image-text connected component extraction; By separating text connected components from other image connected components in complex document images, filtering out text connected components, and removing non-text images, the impact of other images in the document images on the accuracy of the algorithm is reduced, and the robustness of the algorithm is improved. S3: Thinning of connected component images; The text connected components are refined to extract the skeleton of the text, remove burrs from the skeleton, and further denoise the image to improve the accuracy of the algorithm. S4: Inclination angle calculation; Extract the contour of each connected component, use Freeman codes to perform boundary tracking on the text connected component contours, perform Freeman code calculation, calculate the chain code value and proportion of each connected component contour, and take the angle corresponding to the highest proportion of chain code values in the vertical and horizontal directions as the tilt angle of the document image. S5: Document image tilt correction; Based on the tilt angle calculated in step S4, the document image is rotated to be straightened, thereby completing the tilt correction of the image.
2. The document image tilt correction method based on Freeman code according to claim 1, characterized in that, In step S1, the document image preprocessing includes the following specific steps: Convert the original document image to a grayscale image: Read the image, detect the number of channels in the image, and if the image has three channels, convert it to a single-channel grayscale image; Binarizing grayscale images: Using a global binarization algorithm to perform binarization calculations on images facilitates computation and reduces the impact of uneven lighting during document image collection; Morphological processing of the image: Dilation is applied to the image to make characters as connected as possible; erosion is applied to the image to separate adjacent characters.
3. The document image tilt correction method based on Freeman code according to claim 1, characterized in that, In step S2, the image text connected component extraction includes the following specific steps: Find all connected components in the image: Use the 8-connection algorithm in the seed fill algorithm to extract all connected components and record the area of the bounding rectangle of each connected component; Extracting text connected components: Use the area thresholding method to remove non-text connected components. Calculate the average area of the bounding rectangles of all connected components. The lower limit area is 0.5 times the average area, and the upper limit area is 4 times the average area. When the area of the bounding rectangle of a connected component is within this range, it is considered that the connected component is a text connected component. Remove non-text connected components from the image.
4. The document image tilt correction method based on Freeman code according to claim 1, characterized in that, In step S3, the connected component image thinning process includes the following specific steps: Image thinning: The selected text connected components are thinned, and the text skeleton is extracted using the Zhang-Suen algorithm; Skeleton burr removal: During skeleton extraction, burrs of varying degrees will be generated due to different extraction methods and noise interference. Burrs are identified by a burr length threshold and removed to improve the accuracy of the algorithm.
5. The document image tilt correction method based on Freeman code according to claim 1, characterized in that, In step S4, the tilt angle calculation includes the following specific steps: Select the test angle range; For each test angle, the original document image is rotated, and the outline of the de-glitched text connected components is extracted. The orientation of each connected component's outline is calculated, and Freeman codes are used for boundary tracking. The calculated Freeman code value represents the overall orientation of the connected component. In each connected component Freeman code, the proportion of chain code values in the vertical and horizontal directions is counted. If the number of connected components is greater than 3, remove the items with the highest and lowest proportions of the forward chain codes, and then take the average value. The angle corresponding to the highest average value is the tilt angle.
Citation Information
Patent Citations
Complex document image tilt correction method
CN114140785A
Method and device for correcting tilted text image using expansion method
WO2019056346A1