Archival image cropping and rectification method and system based on straight lines and corner features
Patent Information
- Application Number
- CN202611209139.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-08-11
- Publication Date
- 2026-10-23
AI Technical Summary
本发明的主要目的在于提供了一种基于直线和角点特征的档案图像裁剪纠偏方法、系统及计算机可读存储介质,利用图像直线和角点特征,合理设计算法流程,在硬件设备有限的条件下,不依赖人工标注和大量算力支持实现多种档案数据的高效裁剪和纠偏,以解决现有技术中存在的技术问题
本申请提出的一种基于直线和角点特征的档案图像裁剪纠偏方法,通过步骤S1,图像灰度化,对于多通道图像,计算RGB三通道图像方差,取出方差最大通道图像;步骤S2,对步骤S1中获得的灰度图进行水平和垂直方向梯度分量计算,分别获得水平和垂直方向的梯度二值图;步骤S3,对步骤S2中获得的梯度二值图进行一维算子运算,通过自定义的腐蚀算子,消除毛刺和冗余梯度信息干扰;步骤S4,对步骤S3获得的二值图进行连通域分析,获得上下左右四个方向最长直线区域;步骤S5:直线拟合,拟合步骤S4获得的左右两个方向最长直线;步骤S6,交点计算:步骤S61,交点粗计算:计算步骤S5中拟合直线交点,获得直线交点集合;步骤S62,交点精计算:遍历步骤S61中获得的交点集合
,结合交点领域范围内图像角点特征,计算精确交点集合
;步骤S7,图像纠偏:步骤S71,偏转角度计算:计算步骤S61中获得的精确交点集合
的外接矩形,对外接矩形区域内图像进行直线特征分析,获取直线倾斜角度均值作为图像倾斜角度;步骤S72,执行纠偏:仿射变换及点集变换,获得纠偏矫正后图像和交点集合
;步骤S8:裁剪交点区域,得到档案图像裁剪纠偏后的图像。本申请提出了一种基于直线和角点特征的档案图像裁剪纠偏方法,利用图像直线和角点特征,合理设计算法流程,在硬件设备有限的条件下,不依赖人工标注和大量算力支持实现多种档案数据的高效裁剪和纠偏。
Smart Images

Figure CN122967280A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of text image processing technology, and in particular to a method, system, and computer-readable storage medium for cropping and correcting archival images based on straight line and corner features. Background Technology
[0002] Image cropping and correction of archives refers to the cropping of main content and text skew correction of image files obtained by scanning or photographing paper archives during the digitization process. It is a crucial step in the entire digitization process, determining the visual presentation of the digitized result and directly affecting the accuracy of subsequent optical character recognition (OCR). Existing methods for image cropping and correction of archives can be mainly divided into the following three categories: (1) Traditional image processing methods, including the use of algorithms such as line detection, threshold segmentation, edge detection, connected component analysis, and region growing to analyze image features; (2) Laser-assisted method: By using a laser irradiation device at a fixed angle, several red laser rays are projected onto the paper document. By calculating the deformation of the current laser ray and the reference laser ray, the geometric and perspective correction of the image is achieved. (3) Deep learning methods mainly include target segmentation and target detection methods based on convolutional neural networks. By pre-labeling a large number of samples, the segmentation or detection algorithm is trained so that the model has the ability to infer the main region of the image.
[0003] Each of the aforementioned methods has its advantages and disadvantages. Traditional image processing methods, while having poor adaptability, have the lowest requirements for computing power and imaging equipment, and are mostly used in scenarios with limited hardware and relatively simple tasks. Laser-assisted methods typically have high accuracy, but require additional laser modules, and their effectiveness is generally limited for some highly reflective materials, making them mostly used for books or ancient archives. Deep learning methods have the strongest adaptability, but their accuracy depends on the number of samples and the quality of annotations, and they require high computing power, making them mostly used for complex tasks with good hardware. In summary, this paper proposes a method for cropping and correcting archival images based on line and corner features. By fusing features such as image gradients, lines, and corners, and rationally designing the algorithm flow, it uses a coarse localization method based on line detection combined with a fine localization method based on corner gradient histogram information. Under limited hardware conditions, it achieves efficient cropping and correction of archival images using only a single industrial camera and extremely low computing power.
[0004] Therefore, there is an urgent need for a method that can efficiently crop and correct various types of archival data without relying on manual annotation and a large amount of computing power. Summary of the Invention
[0005] (a) Technical problems to be solved The main objective of this invention is to provide a method, system, and computer-readable storage medium for cropping and correcting archival images based on straight line and corner features. By utilizing the straight line and corner features of the image and rationally designing the algorithm flow, it can achieve efficient cropping and correction of various archival data under limited hardware conditions without relying on manual annotation and a large amount of computing power, thereby solving the technical problems existing in the prior art.
[0006] (II) Technical Solution To achieve the above objectives, this invention provides a method for cropping and correcting archival images based on straight line and corner features, comprising the following steps: Step S1: Image grayscale conversion. For multi-channel images, calculate the variance of the RGB three-channel images and extract the image of the channel with the largest variance. Step S2: Calculate the horizontal and vertical gradient components of the grayscale image obtained in step S1 to obtain the horizontal and vertical gradient binary images respectively. Step S3: Perform one-dimensional operator operations on the gradient binary map obtained in step S2. Eliminate glitch and redundant gradient information interference through a custom erosion operator. Step S4: Perform connected component analysis on the binary graph obtained in step S3 to obtain the longest straight-line regions in the four directions of up, down, left, and right. Step S5: Line fitting, fitting the longest straight lines in the left and right directions obtained in step S4; Step S6, intersection calculation: Step S61, coarse calculation of intersection points: calculate the intersection points of the fitted lines in step S5 to obtain the set of line intersection points. ; Step S62, fine calculation of intersection points: traverse the set of intersection points obtained in step S61. By combining the corner features of the image within the intersection region, the precise intersection set is calculated. ; Step S7, Image Correction: Step S71, Deflection Angle Calculation: Calculate the precise intersection point set obtained in step S61. The bounding rectangle is used to perform linear feature analysis on the image within the bounding rectangle region, and the average tilt angle of the straight lines is obtained as the image tilt angle. Step S72: Perform correction: affine transformation and point set transformation to obtain the corrected image and intersection point set. ; Step S8: Crop the intersection area to obtain the cropped and corrected image of the archive image.
[0007] Preferably, if the image in step S1 is a single-channel image, this step is skipped.
[0008] Preferably, step S2 includes: Step S21, Median filtering: The median filtering algorithm is used to filter out noise such as salt and pepper, scan lines, and moiré patterns in the image while preserving the image edge features; Step S22: Directly use the grayscale difference between neighboring pixels to calculate the gradients in the X and Y directions respectively; X-direction gradient calculation: Obtain the vertical edge; calculate the gradient in the Y direction: .
[0009] Preferably, in step S4, connected component analysis is performed on the binary graph obtained in step S3 after eliminating redundant gradients. Each edge is analyzed sequentially, and all contours in the binary graph are traversed. The contours are sorted by the width of the bounding rectangle of the contours, the longest contour is taken out, and it is determined whether the width of the contour is greater than a preset minimum contour threshold. If it is greater, the contour is taken as the corresponding edge line contour. This process is repeated to obtain the set D of edge line contours in the four directions of top, bottom, left and right. In step S4, the widest contour is taken for the top and bottom edges, and the longest contour is taken for the left and right edges.
[0010] Preferably, in step S5, the left and right edge contours in the edge line contour set D obtained in step S4 are fitted with lines using the least squares fitting algorithm. The slope and intercept of the two lines are calculated respectively, thus obtaining the equations of the left and right edge lines. and .
[0011] Preferably, in step S6, the coarse calculation of the intersection point in step S61 includes: directly calculating the circumscribed rectangle of the contour, and substituting the y-coordinate values of the bottom edge of the circumscribed rectangle of the upper edge contour of set D into the equation. and Find the intersection point of the upper edges. and Substitute the y-coordinate values of the top edge of the circumscribed rectangle of the lower edge contour of set D into the input... and Find the intersection point of the lower edge. and Obtain a rough set of clipping intersections. Fitting results of the equations of the four edge lines and coarse calculation results of the intersection points; Step S62, the fine calculation of intersection points, includes: obtaining the gradient map of the coarse intersection point neighborhood, and trimming the intersection point set based on the coarse clipping obtained in step S61. Taking the intersection point as the center and a neighborhood distance of 50 pixels, the gradient maps in the X and Y directions are taken within the neighborhood. Take gradient plot centered Calculate the set of pixel values within the range to obtain the neighborhood map set in the X direction. Y-direction domain graph set Calculate the gradient histogram and calculate the gradient histogram for each image set. and Pixel values are mapped to the X and Y directions to obtain gradient distribution histograms in the X and Y directions; intersection points are calculated, and the coordinates corresponding to the largest column in the gradient distribution histograms in the X and Y directions are taken as the intersection point values, thus obtaining the set of precise cropping intersection points. .
[0012] Preferably, in step S7, the deflection angle calculation in step S71 includes: calculating the precise cut intersection set obtained in step S62. The bounding rectangle Rect1 is used to crop the Rect1 region of the median-filtered image. Perform linear feature analysis; use the Canny operator to... Perform edge detection to obtain a binary edge map. For binary graphs Perform Hough transform line detection to obtain a set of lines. traversal calculation The angle between the center line and the X and Y directions is filtered out and removed if the angle exceeds [the specified value]. The straight lines are used to obtain the filtered set of straight lines. The set is filtered again using the median absolute deviation algorithm. By identifying the outlier lines, we can obtain the final set of lines for calculating the deflection angle. ; Traverse the set Find the mean of the included angles along the center line to obtain the deflection angle. ; Step S72, the execution of the correction calculation, includes: based on the deflection angle Perform an affine transformation and rotation on the original image, and then apply the point set... Perform point set transformation to obtain the corrected image and the cropped point set. Preferably, in step S8, the intersection area is trimmed based on the corrected trimming point set obtained in step S72. and the corrected image, through Create a mask image, and create a new canvas with a size of [size missing]. The size of the bounding rectangle and the canvas fill color are the same as in step S71. The average grayscale value of the image within 50 pixels of the four edges is used to correct the image after skewing. The values within the region are copied to a new layer to obtain the final cropping and correction results.
[0013] The present invention also provides an archival image cropping and correction system based on straight line and corner features, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, it implements the steps of an archival image cropping and correction method based on straight line and corner features as described above.
[0014] The present invention also provides a computer-readable storage medium storing a computer program, which, when executed by a processor, implements the steps of a method for cropping and correcting archival images based on straight line and corner features as described in any of the preceding claims.
[0015] Beneficial effects This application proposes a method for cropping and correcting archival images based on straight line and corner features. The method comprises the following steps: Step S1: Image grayscale conversion; for multi-channel images, calculation of the variance of the RGB three-channel image, extracting the channel with the largest variance; Step S2: Calculation of horizontal and vertical gradient components on the grayscale image obtained in Step S1, obtaining horizontal and vertical gradient binary images respectively; Step S3: One-dimensional operator operation on the gradient binary image obtained in Step S2, using a custom erosion operator to eliminate burrs and redundant gradient information interference; Step S4: Connectivity analysis on the binary image obtained in Step S3 to obtain the longest straight line regions in the four directions (up, down, left, and right); Step S5: Line fitting, fitting the longest straight lines in the left and right directions obtained in Step S4; Step S6: Intersection point calculation: Step S61: Coarse intersection point calculation, calculating the intersection points of the fitted lines in Step S5 to obtain a set of line intersection points. Step S62, fine calculation of intersection points: traverse the set of intersection points obtained in step S61. By combining the corner features of the image within the intersection region, the precise intersection set is calculated. Step S7, Image Correction: Step S71, Deflection Angle Calculation: Calculate the precise intersection point set obtained in Step S61. The bounding rectangle is used to perform linear feature analysis on the image within the bounding rectangle region, and the average tilt angle of the straight lines is obtained as the image tilt angle; in step S72, correction is performed: affine transformation and point set transformation are performed to obtain the corrected image and the intersection point set. Step S8: Crop the intersection area to obtain the cropped and corrected image of the archive image. This application proposes an archive image cropping and correction method based on line and corner features. By utilizing the line and corner features of the image and rationally designing the algorithm flow, it can achieve efficient cropping and correction of various archive data under the condition of limited hardware equipment, without relying on manual annotation and a large amount of computing power. Attached Figure Description
[0016] Figure 1 This is a schematic diagram of a method for cropping and correcting archival images based on straight lines and corner features, provided in this embodiment.
[0017] Figure 2 This is a comparison diagram of the image gradient calculation structure of the operator in step S22 of this embodiment and the Sobel operator.
[0018] Figure 3The figure shows a comparison of the effects of the one-way one-dimensional operator operation before and after step S3 in this embodiment.
[0019] Figure 4 This is the maximum straight line contour and fitting result of the right edge in step S5 of this embodiment.
[0020] Figure 5 This refers to the fitting results of the four-edge line equations and the coarse calculation results of the intersection points in step S61 of this embodiment.
[0021] Figure 6 This is the gradient histogram mapping result of the upper right vertex X and Y in the reverse direction in step S62 of this embodiment.
[0022] Figure 7 This is the precise calculation result of step S62 in this embodiment.
[0023] Figure 8 This is the set of lines used to calculate the deflection angle in step S71 of this embodiment.
[0024] Figure 9 This is the correction result of step S72 in this embodiment.
[0025] Figure 10 This is the final cropping effect and the result after contrast adjustment in step S8 of this embodiment.
[0026] Figure 11 This is a schematic diagram of the hardware structure of an archival image cropping and correction system based on straight line and corner features, provided in this embodiment. Detailed Implementation
[0027] To better explain and facilitate understanding of the present invention, the present invention will be described in detail below with reference to the accompanying drawings and specific embodiments.
[0028] It should be noted that all directional indications (such as up, down, left, right, front, back, etc.) in the embodiments of the present invention are only used to explain the relative positional relationship and movement of each component in a certain specific posture (as shown in the figure). If the specific posture changes, the directional indication will also change accordingly.
[0029] Furthermore, in this invention, descriptions involving "first," "second," etc., are for descriptive purposes only and should not be construed as indicating or implying their relative importance or implicitly specifying the number of technical features indicated. Thus, a feature defined as "first" or "second" may explicitly or implicitly include at least one of that feature. In the description of this invention, "a plurality of" means at least two, such as two, three, etc., unless otherwise explicitly specified.
[0030] In this invention, unless otherwise explicitly specified and limited, the terms "connection" and "fixed" should be interpreted broadly. For example, "fixed" can mean a fixed connection, a detachable connection, or an integral part; "connection" can mean a mechanical connection or an electrical connection; it can mean a direct connection or an indirect connection through an intermediate medium; it can mean the internal communication of two components or the interaction between two components, unless otherwise explicitly limited. Those skilled in the art can understand the specific meaning of the above terms in this invention according to the specific circumstances.
[0031] like Figure 1 As shown, this embodiment provides a method for cropping and correcting archival images based on straight line and corner features. The method includes steps S1 to S8.
[0032] Step S1: Image grayscale conversion. For multi-channel images, calculate the variance of the RGB three-channel images and extract the image of the channel with the largest variance. Step S2: Calculate the horizontal and vertical gradient components of the grayscale image obtained in step S1 to obtain the horizontal and vertical gradient binary images respectively. Step S3: Perform one-dimensional operator operations on the gradient binary map obtained in step S2. Eliminate glitch and redundant gradient information interference through a custom erosion operator. Step S4: Perform connected component analysis on the binary graph obtained in step S3 to obtain the longest straight-line regions in the four directions of up, down, left, and right. Step S5: Line fitting, fitting the longest straight lines in the left and right directions obtained in step S4; Step S6, intersection calculation: Step S61, coarse calculation of intersection points: calculate the intersection points of the fitted lines in step S5 to obtain the set of line intersection points. ; Step S62, fine calculation of intersection points: traverse the set of intersection points obtained in step S61. By combining the corner features of the image within the intersection region, the precise intersection set is calculated. ; Step S7, Image Correction: Step S71, Deflection Angle Calculation: Calculate the precise intersection point set obtained in step S61. The bounding rectangle is used to perform linear feature analysis on the image within the bounding rectangle region, and the average tilt angle of the straight lines is obtained as the image tilt angle. Step S72: Perform correction: affine transformation and point set transformation to obtain the corrected image and intersection point set. ; Step S8: Crop the intersection area to obtain the cropped and corrected image of the archive image.
[0033] Preferably, if the image in step S1 is a single-channel image, this step is skipped.
[0034] Preferably, step S2 includes: Step S21, Median filtering: The median filtering algorithm is used to filter out noise such as salt and pepper, scan lines, and moiré patterns in the image while preserving the image edge features; Step S22: Directly use the grayscale difference between neighboring pixels to calculate the gradients in the X and Y directions respectively; X-direction gradient calculation: Obtain the vertical edge; calculate the gradient in the Y direction: .
[0035] Preferably, in step S4, connected component analysis is performed on the binary graph obtained in step S3 after eliminating redundant gradients. Each edge is analyzed sequentially, and all contours in the binary graph are traversed. The contours are sorted by the width of the bounding rectangle of the contours, the longest contour is taken out, and it is determined whether the width of the contour is greater than a preset minimum contour threshold. If it is greater, the contour is taken as the corresponding edge line contour. This process is repeated to obtain the set D of edge line contours in the four directions of top, bottom, left and right. In step S4, the widest contour is taken for the top and bottom edges, and the longest contour is taken for the left and right edges.
[0036] Preferably, in step S5, the left and right edge contours in the edge line contour set D obtained in step S4 are fitted with lines using the least squares fitting algorithm. The slope and intercept of the two lines are calculated respectively, thus obtaining the equations of the left and right edge lines. and .
[0037] Preferably, in step S6, the coarse calculation of the intersection point in step S61 includes: directly calculating the circumscribed rectangle of the contour, and substituting the y-coordinate values of the bottom edge of the circumscribed rectangle of the upper edge contour of set D into the equation. and Find the intersection point of the upper edges. and Substitute the y-coordinate values of the top edge of the circumscribed rectangle of the lower edge contour of set D into the input... and Find the intersection point of the lower edge. and Obtain a rough set of clipping intersections. Fitting results of the equations of the four edge lines and coarse calculation results of the intersection points; Step S62, the fine calculation of intersection points, includes: obtaining the gradient map of the coarse intersection point neighborhood, and trimming the intersection point set based on the coarse clipping obtained in step S61. Taking the intersection point as the center and a neighborhood distance of 50 pixels, the gradient maps in the X and Y directions are taken within the neighborhood. Take gradient plot centered Calculate the set of pixel values within the range to obtain the neighborhood map set in the X direction. Y-direction domain graph set Calculate the gradient histogram and calculate the gradient histogram for each image set. and Pixel values are mapped to the X and Y directions to obtain gradient distribution histograms in the X and Y directions; intersection points are calculated, and the coordinates corresponding to the largest column in the gradient distribution histograms in the X and Y directions are taken as the intersection point values, thus obtaining the set of precise cropping intersection points. .
[0038] Preferably, in step S7, the deflection angle calculation in step S71 includes: calculating the precise cut intersection set obtained in step S62. The bounding rectangle Rect1 is used to crop the Rect1 region of the median-filtered image. Perform linear feature analysis; use the Canny operator to... Perform edge detection to obtain a binary edge map. For binary graphs Perform Hough transform line detection to obtain a set of lines. traversal calculation The angle between the center line and the X and Y directions is filtered out and removed if the angle exceeds [the specified value]. The straight lines are used to obtain the filtered set of straight lines. The set is filtered again using the median absolute deviation algorithm. By identifying the outlier lines, we can obtain the final set of lines for calculating the deflection angle. ; Traverse the set Find the mean of the included angles along the center line to obtain the deflection angle. ; Step S72, the execution of the correction calculation, includes: based on the deflection angle Perform an affine transformation and rotation on the original image, and then apply the point set... Perform point set transformation to obtain the corrected image and the cropped point set. Preferably, in step S8, the intersection area is trimmed based on the corrected trimming point set obtained in step S72. and the corrected image, through Create a mask image, and create a new canvas with a size of [size missing]. The size of the bounding rectangle and the canvas fill color are the same as in step S71. The average grayscale value of the image within 50 pixels of the four edges is used to correct the image after skewing. The values within the region are copied to a new layer to obtain the final cropping and correction results.
[0039] Specifically, the following example illustrates this. In this example, the shooting device is HIKVISION MV-CE060-10GM, the scanning device is EPSON DS-870, the operating system is Ubuntu 22.04, and the programming language is C++11.
[0040] Step S1: Image grayscale conversion. For multi-channel images, calculate the variance of grayscale values for each of the RGB three channels and take the channel image with the largest variance as the grayscale image. If the image is a single-channel image, skip this step.
[0041] Step S2: Gradient calculation; Step S2.1: Median filtering. Considering that the algorithm needs to utilize image edge and intersection features, the median filtering algorithm is used here to filter out noise such as salt and pepper, scan lines, and moiré patterns in the image while preserving image edge features.
[0042] Step S2.2: Calculate the gradients in the X and Y directions respectively. Considering that the overall image has already undergone filtering in step S2.1, in order to save computation and to retain more edge details in the output gradient map, the Sobel operator is not used here for gradient calculation. Instead, the gray-level difference between neighboring pixels is used directly. Taking the X-direction gradient calculation as an example... The vertical edge is obtained, and the gradient calculation in the Y direction is similar. The comparison of image gradient calculation results using the operator presented in this paper and the Sobel operator is shown in the figure below. Figure 2 As shown, the gradient map edge information obtained by directly using the difference between adjacent pixels is more complete.
[0043] Step S3: One-dimensional operator operation. Perform one-dimensional operator operations on the binary gradient maps in the X and Y directions obtained in step S2.2 respectively to eliminate glitches and redundant gradient information interference. Compare the effects before and after the operation. Figure 3 As shown, the algorithm logic is as follows:
[0044] Step S4: Binary graph analysis. Perform connected component analysis on the binary graph obtained in step S3 after eliminating redundant gradients. Taking the right edge as an example, traverse all contours in the binary graph, sort them according to the width of the bounding rectangle of the contour, take out the longest contour, and determine whether the width of the contour is greater than the preset minimum contour threshold. Here, the threshold is 0.35*dstImg.height. If it is greater, take the contour as the right edge straight contour. Note that the widest contour is taken for the top and bottom edges, and the longest contour is taken for the left and right edges, and so on, to obtain the set D of straight contours of the four directions of top, bottom, left and right.
[0045] Step S5: Line Fitting. Perform line fitting on the left and right edge contours in the edge line contour set D obtained in Step S4. The fitting algorithm is least squares fitting. Calculate the slope and intercept of each line to obtain the equations of the left and right edge lines. and Taking the right edge as an example, the maximum straight line contour and fitting result of the right edge are as follows: Figure 4 As shown.
[0046] Step S6: Intersection point calculation. Based on the edge line contour set D obtained in step S4 and the left and right edge line equations obtained in step S5, as well as the image corner feature information, calculate the cropping intersection point.
[0047] Step S6.1: Coarse calculation of intersection points. To save computation, the intersection points of the upper and lower edge straight lines are not obtained by straight line fitting. Instead, the circumscribed rectangle of the contour is calculated directly. The y-coordinate values of the bottom edge of the circumscribed rectangle of the upper edge contour in set D are substituted into the calculation. and Find the intersection point of the upper edges. and Similarly, take the y-coordinate value of the top edge of the circumscribed rectangle of the lower edge contour of set D and substitute it into the equation. and Find the intersection point of the lower edge. and After completing the above steps, a rough set of clipping intersections is obtained. The fitting results of the equations for the four edge lines and the coarse calculation results of the intersection points are as follows: Figure 5 As shown.
[0048] Step S6.2: Fine calculation of intersection points. In the coarse matching of intersection points, there is a slight straight line fitting error. However, due to the long length of the fitted straight line, the error is amplified. In order to avoid this error amplification effect, the error is corrected by calculating the gradient map histogram projection in the neighborhood based on the coarse trimming of intersection points.
[0049] (a) Obtain the gradient map of the coarse intersection neighborhood, based on the coarse clipping intersection set obtained in step S6.1. Taking the intersection point as the center and a neighborhood distance of 50 pixels, the gradient maps in the X and Y directions are taken within the neighborhood. Take gradient plot centered Calculate the set of pixel values within the range to obtain the neighborhood map set in the X direction. Y-direction domain graph set .
[0050] (b) Calculate the gradient histogram and calculate the gradient histogram for each image set. and The pixel values are mapped to the X and Y directions to obtain gradient distribution histograms in the X and Y directions. To reduce computational cost, this step simplifies the process by utilizing gradient histogram information instead of complex methods such as corner matching. Experiments have verified that this method is highly feasible in the field of archival image cropping with obvious right-angle features. Taking the intersection point at the right edge vertex as an example, the X and Y inverse gradient histogram mapping results are as follows: Figure 6 As shown.
[0051] (c) Calculate the intersection points. Take the coordinates of the column with the largest gradient distribution histogram in the X and Y directions as the intersection point values, thus obtaining the precise clipping intersection point set. The precise calculation results are as follows: Figure 7 As shown.
[0052] Step S7: Image correction. Calculate the image deflection angle and perform correction based on the deflection angle.
[0053] Step S7.1 Deflection angle calculation: Calculate the set of precise cutting intersections obtained in step S6.2. The bounding rectangle Rect1 is used to crop the Rect1 region of the median-filtered image. Perform linear characteristic analysis.
[0054] (a) Using the Canny operator Perform edge detection to obtain a binary edge map. ; (b) For binary graphs Perform Hough transform line detection to obtain a set of lines. traversal calculation The angle between the center line and the X and Y directions is filtered out and removed if the angle exceeds [the specified value]. The straight lines are used to obtain the filtered set of straight lines. The set is filtered again using the Median Absolute Deviation (MAD) algorithm. By identifying the outlier lines, we can obtain the final set of lines for calculating the deflection angle. Calculate the set of lines with deflection angles, such as Figure 8 As shown; (c) Traversing the set Find the mean of the included angles along the center line to obtain the deflection angle. ; Step S7.2 Perform correction based on the deflection angle. Perform an affine transformation and rotation on the original image, and then apply the point set... Perform point set transformation to obtain the corrected image and the cropped point set. The correction results are as follows Figure 9 As shown.
[0055] Step S8: Crop the intersection area based on the corrected cropping point set obtained in step S7.2. and the corrected image, through Create a mask image, and create a new canvas with a size of [size missing]. The size of the bounding rectangle and the canvas fill color are the same as in step S7.1. The average grayscale value of the image within 50 pixels of the four edges is used to correct the image after skewing. The region values are copied to a new layer to obtain the final cropping and correction results, such as... Figure 10 As shown.
[0056] This application also provides a system for cropping and correcting archival images based on straight line and corner features, including a memory, a processor, and a computer program stored in the memory and executable on the processor. When the processor executes the computer program, it implements the steps of a method for cropping and correcting archival images based on straight line and corner features as described above.
[0057] like Figure 11 As shown, this application also provides a computer-readable storage medium storing a computer program, which, when executed by a processor, implements the steps of a method for cropping and correcting archival images based on straight line and corner features as described in any of the preceding claims.
[0058] Figure 11 This is a schematic diagram of the hardware structure for running a method for cropping and correcting archival images based on line and corner features, according to an embodiment of the present invention. Figure 11 As shown, this embodiment / computer 6 includes: a processor 60, a memory 61, and a computer program 62 stored in the memory 61 and executable on the processor 60, such as a program for running a method for cropping and correcting archival images based on line and corner features. When the processor 60 executes the computer program 62, it implements the steps in the various embodiments described above for running a method for cropping and correcting archival images based on line and corner features. Alternatively, when the processor 60 executes the computer program 62, it implements the functions of each module / unit in the various device embodiments described above.
[0059] For example, the computer program 62 may be divided into one or more modules / units, which are stored in the memory 61 and executed by the processor 60 to complete the present invention. The one or more modules / units may be a series of computer program instruction segments capable of performing a specific function, which describe the execution process of the computer program 62 in the computer 6.
[0060] The computer 6 can be a desktop computer, laptop, handheld computer, cloud server, or other computing device. The computer 6 may include, but is not limited to, a processor 60 and a memory 61. Those skilled in the art will understand that... Figure 11 This is merely an example of computer 6 and does not constitute a limitation on computer 6. It may include more or fewer components than shown, or combine certain components, or different components. For example, computer 6 may also include input / output devices, network access devices, buses, etc.
[0061] The processor 60 may be a central processing unit (CPU), or other general-purpose processors, digital signal processors (DSPs), application-specific integrated circuits (ASICs), field-programmable gate arrays (FPGAs), or other programmable logic devices, discrete gate or transistor logic devices, discrete hardware components, etc. A general-purpose processor may be a microprocessor or any conventional processor.
[0062] The memory 61 can be an internal storage unit of the computer 6, such as a hard drive or memory. The memory 61 can also be an external storage device of the computer 6, such as a plug-in hard drive, smart media card (SMC), secure digital (SD) card, flash card, etc., equipped on the terminal device. Furthermore, the memory 61 can include both internal storage units and external storage devices of the computer 6. The memory 61 is used to store the computer program and other programs and data required by the terminal device. The memory 61 can also be used to temporarily store data that has been output or will be output.
[0063] Those skilled in the art will clearly understand that, for the sake of convenience and brevity, the above-described division of functional units and modules is merely an example. In practical applications, the above functions can be assigned to different functional units and modules as needed, that is, the internal structure of the device can be divided into different functional units or modules to complete all or part of the functions described above. The functional units and modules in the embodiments 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. Furthermore, the specific names of the functional units and modules are only for easy differentiation and are not intended to limit the scope of protection of this application. The specific working process of the units and modules in the above system can be referred to the corresponding process in the foregoing method embodiments, and will not be repeated here.
[0064] In the above embodiments, the descriptions of each embodiment have different focuses. For parts that are not described in detail or recorded in a certain embodiment, please refer to the relevant descriptions of other embodiments.
[0065] Those skilled in the art will recognize that the units and algorithm steps of the various examples described in conjunction with the embodiments disclosed herein can be implemented in electronic hardware, or a combination of computer software and electronic hardware. Whether these functions are implemented in hardware or software depends on the specific application and design constraints of the technical solution. Those skilled in the art can use different methods to implement the described functions for each specific application, but such implementations should not be considered beyond the scope of this invention.
[0066] In the embodiments provided by this invention, it should be understood that the disclosed apparatus / terminal devices and methods can be implemented in other ways. For example, the apparatus / terminal device embodiments described above are merely illustrative. For instance, the division of modules or units is only a logical functional division, and in actual implementation, there may be other division methods. For example, multiple units or components may be combined or integrated into another system, or some features may be ignored or not executed. Furthermore, the coupling or direct coupling or communication connection shown or discussed may be through some interfaces; the indirect coupling or communication connection between devices or units may be electrical, mechanical, or other forms.
[0067] 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 network units. Some or all of the units can be selected to achieve the purpose of this embodiment according to actual needs.
[0068] 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.
[0069] If the integrated module / 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, all or part of the processes in the methods of the above embodiments can also be implemented by a computer program instructing related hardware. The computer program can be stored in a computer-readable storage medium, and when executed by a processor, it can implement the steps of the various method embodiments described above. The computer program includes computer program code, which can be in the form of source code, object code, executable files, or certain intermediate forms. The computer-readable medium can include: any entity or device capable of carrying the computer program code, recording media, USB flash drives, portable hard drives, magnetic disks, optical disks, computer memory, read-only memory (ROM), random access memory (RAM), electrical carrier signals, telecommunication signals, and software distribution media, etc. It should be noted that the content included in the computer-readable medium can be appropriately added or removed according to the requirements of legislation and patent practice in the jurisdiction. For example, in some jurisdictions, according to legislation and patent practice, computer-readable media do not include electrical carrier signals and telecommunication signals.
[0070] The above are merely specific application examples of the present invention and do not constitute any limitation on the scope of protection of the present invention. In addition to the above embodiments, the present invention may have other implementations. All technical solutions formed by equivalent substitution or equivalent transformation fall within the scope of protection claimed by the present invention.
Claims
1. A method for cropping and correcting archival images based on straight line and corner features, characterized in that, Including the following steps: Step S1: Image grayscale conversion. For multi-channel images, calculate the variance of the RGB three-channel images and extract the image of the channel with the largest variance. Step S2: Calculate the horizontal and vertical gradient components of the grayscale image obtained in step S1 to obtain the horizontal and vertical gradient binary images respectively. Step S3: Perform one-dimensional operator operations on the gradient binary map obtained in step S2. Eliminate glitch and redundant gradient information interference through a custom erosion operator. Step S4: Perform connected component analysis on the binary graph obtained in step S3 to obtain the longest straight-line regions in the four directions of up, down, left, and right. Step S5: Line fitting, fitting the longest straight lines in the left and right directions obtained in step S4; Step S6, intersection calculation: Step S61, coarse calculation of intersection points: calculate the intersection points of the fitted lines in step S5 to obtain the set of line intersection points. ; Step S62, fine calculation of intersection points: traverse the set of intersection points obtained in step S61. By combining the corner features of the image within the intersection region, the precise intersection set is calculated. ; Step S7, Image Correction: Step S71, Deflection Angle Calculation: Calculate the precise intersection point set obtained in step S61. The bounding rectangle is used to perform linear feature analysis on the image within the bounding rectangle region, and the average tilt angle of the straight lines is obtained as the image tilt angle. Step S72: Perform correction: affine transformation and point set transformation to obtain the corrected image and intersection point set. ; Step S8: Crop the intersection area to obtain the cropped and corrected image of the archive image.
2. The method for cropping and correcting archival images based on straight line and corner features according to claim 1, characterized in that, If the image in step S1 is a single-channel image, then this step is skipped.
3. The method for cropping and correcting archival images based on straight line and corner features according to claim 1, characterized in that, Step S2 includes: Step S21, Median filtering: The median filtering algorithm is used to filter out noise such as salt and pepper, scan lines, and moiré patterns in the image while preserving the image edge features; Step S22: Directly use the grayscale difference between neighboring pixels to calculate the gradients in the X and Y directions respectively; X-direction gradient calculation: Obtain the vertical edge; calculate the gradient in the Y direction: .
4. The method for cropping and correcting archival images based on straight line and corner features according to claim 1, characterized in that, In step S4, connected component analysis is performed on the binary graph obtained in step S3 after eliminating redundant gradients. Each edge is analyzed sequentially. All contours in the binary graph are traversed and sorted by the width of the bounding rectangle of the contour. The longest contour is taken out and it is determined whether the width of the contour is greater than the preset minimum contour threshold. If it is greater, the contour is taken as the corresponding edge line contour. This process is repeated to obtain the set D of edge line contours in the four directions of top, bottom, left and right. In step S4, the widest contour is taken for the top and bottom edges, and the longest contour is taken for the left and right edges.
5. The method for cropping and correcting archival images based on straight line and corner features according to claim 4, characterized in that, In step S5, the left and right edge contours in the edge line contour set D obtained in step S4 are fitted with lines using the least squares fitting algorithm. The slope and intercept of the two lines are calculated respectively, thus obtaining the equations of the left and right edge lines. and .
6. The method for cropping and correcting archival images based on straight line and corner features according to claim 5, characterized in that, In step S6, the coarse calculation of the intersection point in step S61 includes: directly calculating the bounding rectangle of the contour, and substituting the y-coordinate values of the bottom edge of the bounding rectangle of the upper edge contour of set D into the equation. and Find the intersection point of the upper edges. and Substitute the y-coordinate values of the top edge of the circumscribed rectangle of the lower edge contour of set D into the input... and Find the intersection point of the lower edge. and Obtain a rough set of clipping intersections. Fitting results of the equations of the four edge lines and coarse calculation results of the intersection points; Step S62, the fine calculation of intersection points, includes: obtaining the gradient map of the coarse intersection point neighborhood, and trimming the intersection point set based on the coarse clipping obtained in step S61. Taking the intersection point as the center and a neighborhood distance of 50 pixels, the gradient maps in the X and Y directions are taken within the neighborhood. Take gradient plot centered Calculate the set of pixel values within the range to obtain the neighborhood map set in the X direction. Y-direction domain graph set Calculate the gradient histogram and calculate the gradient histogram for each image set. and Pixel values are mapped to the X and Y directions to obtain gradient distribution histograms in the X and Y directions; intersection points are calculated, and the coordinates corresponding to the largest column in the gradient distribution histograms in the X and Y directions are taken as the intersection point values, thus obtaining the precise cropping intersection point set. .
7. The method for cropping and correcting archival images based on straight line and corner features according to claim 6, characterized in that, In step S7, the deflection angle calculation in step S71 includes: calculating the precise cut intersection set obtained in step S62. The bounding rectangle Rect1 is used to crop the Rect1 region of the median-filtered image. Perform linear characteristic analysis; use the Canny operator to... Perform edge detection to obtain a binary edge map. For binary graphs Perform Hough transform line detection to obtain a set of lines. traversal calculation The angle between the center line and the X and Y directions is filtered out and removed if the angle exceeds [the specified value]. The straight lines are used to obtain the filtered set of straight lines. The set is filtered again using the median absolute deviation algorithm. By identifying the outlier lines, we can obtain the final set of lines for calculating the deflection angle. ; Traverse the set Find the mean of the included angles along the center line to obtain the deflection angle. ; Step S72, the execution of the correction calculation, includes: based on the deflection angle Perform an affine transformation and rotation on the original image, and then apply the point set... Perform point set transformation to obtain the corrected image and the cropped point set. .
8. The method for cropping and correcting archival images based on straight line and corner features according to claim 7, characterized in that, In step S8, the intersection area is trimmed based on the corrected trimming point set obtained in step S72. and the corrected image, through Create a mask image, and create a new canvas with a size of [size missing]. The size of the bounding rectangle and the canvas fill color are the same as in step S71. The average grayscale value of the image within 50 pixels of the four edges is used to correct the image after skewing. The values within the region are copied to a new layer to obtain the final cropping and correction results.
9. A system for cropping and correcting archival images based on straight line and corner features, comprising a memory, a processor, and a computer program stored in the memory and executable on the processor, characterized in that, When the processor executes the computer program, it implements the steps of the archival image cropping and correction method based on straight line and corner features as described in any one of claims 1 to 8.
10. A computer-readable storage medium storing a computer program, characterized in that, When the computer program is executed by the processor, it implements the steps of the archival image cropping and correction method based on straight line and corner features as described in any one of claims 1 to 8.