A method for removing a table background from a document image
By employing background estimation and foreground image construction methods, combined with pixel fusion and grayscale peak sequence processing, the problem of table background interference in document images was solved, effectively preserving table lines and text information, and improving the accuracy of recognition and data extraction.
Patent Information
- Application Number
- CN202611638689.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2026-10-22
- Publication Date
- 2026-11-24
AI Technical Summary
Existing technologies struggle to effectively remove table background interference from document images, especially colored backgrounds and light-colored residual noise, which affects the accuracy of table recognition and data extraction.
A method of background estimation, foreground image construction, and pixel fusion is adopted. Through steps such as median filtering, bilateral filtering, gray-level histogram statistics, and Gaussian filtering, dark and light foreground images are constructed, and pixel fusion and gray-level peak sequence processing are performed to remove background interference.
It achieves robust removal of complex table backgrounds in document images, effectively preserving table lines and text information, and improving the accuracy of subsequent recognition and data extraction.
Smart Images

Figure CN123160604A_ABST
Abstract
Description
Technical Field
[0001] This invention belongs to the field of document image processing technology, and specifically relates to a method for removing the background of a table in a document image. Background Technology
[0002] Tables are an important medium for information storage and transmission, widely used in financial statements, invoices, contracts, and various statistical documents. With the development of digital office and intelligent information extraction technologies, converting paper table documents into digital images through scanning or photography, and automatically extracting structured data from them, has become a core requirement for intelligent document processing. Due to the influence of scanning or photography conditions, document table images often contain various background interferences, including colored backgrounds, light-colored backgrounds, and light-colored residual noise. These background interferences seriously affect the accuracy of subsequent table recognition and data extraction.
[0003] Current mainstream image background removal techniques mostly employ global binarization and a single fixed threshold segmentation strategy, which has poor adaptability. Under complex background interference, it is difficult to balance the integrity of foreground text and table lines with the background removal effect. Existing improved algorithms, such as pixel clustering and block thresholding, have achieved some success, but still suffer from problems such as over-removing residual background noise or mistakenly deleting valid foreground information.
[0004] Existing patent documents, such as "Document Background Interference Removal Method and Device" (Publication No. CN122024246A), propose a background interference removal method based on pixel color clustering. This method relies on color clustering to distinguish between foreground and background, but it is difficult to effectively identify large areas of uniform background with colors similar to the text. Another patent document, "Image Processing Method and Apparatus" (Publication No. WO2018028234A1), proposes a background removal method based on block processing. Although this method alleviates the overprocessing problem caused by a globally uniform threshold to some extent through block thresholding, the background removal after block division still relies on the local statistical information within each data block. For mixed blocks that contain both foreground and complex background, the threshold selection is prone to failure.
[0005] Currently, there is no method for removing table backgrounds from document images. Applying the above methods directly to remove table backgrounds from document images may not achieve the desired results.
[0006] Therefore, proposing a method for targeted removal of table backgrounds is of significant practical importance. Summary of the Invention
[0007] To address the aforementioned technical problems, this invention proposes a method for removing table backgrounds from document images. This method can effectively remove background interference while protecting table lines and text information from damage.
[0008] The technical solution adopted in this invention is as follows: A method for removing table backgrounds from document images, comprising the following steps: Step S1: Document table image reading: Read the document table image I to be processed, convert the document table image I to grayscale, and obtain the first grayscale image I. G ; Step S2: Background estimation: For the first grayscale image I G Median filtering is performed to obtain the first background grayscale image I. cfbg The document table image I is downsampled, median filtered, and bilaterally filtered to obtain the first background image I. b For the first background image I b Upsampling is performed to obtain the second background image I. bg ; Step S3: Foreground Image Construction: Construct the second background image I bg Grayscale conversion yields the second background grayscale image I. Gbg Based on the second background grayscale image I Gbg Construct a dark foreground image I d and bright foreground image I l ; Step S4: Foreground Image Blending: Based on Dark Foreground Image I d With bright foreground image I l Pixel fusion processing is performed on the document table image I to obtain a hybrid image I. blend ; Step S5: Background Removal: Remove the first background grayscale image I cfbg Histogram statistics are performed to obtain a gray-level histogram H. A one-dimensional Gaussian filter is then applied to smooth the gray-level histogram H to obtain a smoothed histogram Hs. s Calculate the grayscale peak sequence P peak Based on grayscale peak sequence P peak For the mixed image I blend The light and dark fill regions are processed to obtain the resulting image I. clean .
[0009] Furthermore, in step S3, based on the second background grayscale image I Gbg Construct a dark foreground image I d and bright foreground image I l The specific steps are as follows: Step S31: Let D represent the brightness residual matrix, let D abs Represents the absolute residual matrix, synchronously traversing the first grayscale image I. G Second background grayscale image I Gbg For each pixel in the array, let p G(x,y) represents the first grayscale image I. G Let p be the value of the pixel whose x-coordinate is currently being traversed and whose y-coordinate is currently being traversed. Gb (x,y) represents the second background grayscale image I. Gbg Let D(u,v) represent the value of the pixel with x-coordinate and y-coordinate currently being traversed in the luminance residual matrix D. Let D(u,v) represent the element with row index u and column index v in the luminance residual matrix D. abs (u,v) represents the absolute residual matrix D. abs The elements with row index u and column index v in the luminance residual matrix D are used to calculate the elements D(u,v) with row index u and column index v in the luminance residual matrix D and the absolute residual matrix D, respectively. abs The element D with row index u and column index v abs (u,v): D(u,v)=p G (x,y)-p Gb (x,y); D abs (u,v)=|D(u,v)|; Step S32: Let T low To set a low threshold, let T high To set a high threshold, set a first index c1 and a second index c2, and calculate the absolute residual matrix D. abs The quantile at the first index c1 yields the first sample quantile p. c1 Calculate the absolute residual matrix D abs The quantile at the second index c2 yields the second sample quantile p. c2 Set the lower quantile coefficient k l Set the high quantile coefficient k h Set the minimum low threshold T low_min Set the maximum low threshold T low_max Set the minimum interval threshold d low Set the maximum high threshold T high_max If p c1 ×k l <T low_min Then T low =T low_min If p c1 ×k l >T low_max Then T low =T low_max Otherwise T low =p c1 ×k l If p c2 ×k h <T low +d low Then Thigh =T low +d low If p c2 ×k h >T high_max Then T high =T high_max Otherwise T high =p c2 ×k h ; Step S33: Let I d1 Let I be the first dark foreground image. l1 For the first bright foreground image, iterate through each element of the brightness residual matrix D; to obtain the first dark foreground image I. d1 And the first bright foreground image I l1 ; Step S34: Set the weak residual coefficient k w , let I d2 Let I represent the second dark foreground image. l2 Representing the second bright foreground image, traversing the absolute residual matrix D abs Each element in the image; to obtain the second dark foreground image I. d2 Second bright foreground image I l2 ; Step S35: For the second dark foreground image I d2 Second bright foreground image I l2 Gaussian filtering is applied to smooth the image, resulting in the third dark foreground image I. d3 and the third bright foreground image I l3 For the third dark foreground image I d3 and the third bright foreground image I l3 Thresholding is performed to obtain the adaptive dark foreground image I. da and adaptive bright foreground image I la , let p αda (x,y) represents the adaptive dark foreground image I. da Let p be the value of the pixel with x-axis and y-axis. αla (x,y) represents the adaptive bright foreground image I. la The value of the pixel with x as the horizontal axis and y as the vertical axis; Step S36: Let D fix Represents a fixed brightness residual matrix, synchronously traversing the first grayscale image I. G And the first background grayscale image I cfbg For each pixel in the array, let p cfbg (x,y) represents the first background grayscale image I. cfbg Let D be the value of the pixel whose x-coordinate is currently being traversed and whose y-coordinate is currently being traversed.fix (u,v) represents the fixed luminance residual matrix D. fix The element with row index u and column index v, D fix (u,v)=p G (x,y)-p cfbg (x,y); Step S37: Set a fixed lower threshold T fixlo Set a fixed upper limit threshold T fixhi , let I dfix Let p represent a dark foreground image with a fixed threshold. αfix (x,y) represents the dark foreground image I with a fixed threshold. dfix The values of the pixels with x-coordinate and y-coordinate are given. Let t1 represent the first intermediate result, and t1 = (-D). fix (u,v)-T fixlo ) / (T fixhi -T fixlo If t1 < 0, then p αfix If (x,y)=0, and t1>1, then p αfix (x,y)=1, otherwise p αfix (x,y)=t1; Step S38: Set the luminance weight w clg , let p αd (x,y) represents the dark foreground image I. d Let p be the value of the pixel with x-axis and y-axis. αl (x,y) represents the bright foreground image I. l The value of the pixel with x-axis and y-axis in the middle, p αd (x,y)=max(p αda (x,y),p αfix (x,y)), p αl (x,y)=p αla (x,y)×w clg ; Step S39: Set the second power law exponent k pwcf The dark foreground image I is updated using the following formula. d and bright foreground image I l The value of each pixel in: p αd (x,y)=(p αd (x,y)) kpwcf ; p αl (x,y)=(p αl (x,y)) kpwcf ; Obtain dark foreground image I dand bright foreground image I l .
[0010] Furthermore, in step S32, the absolute residual matrix D is calculated. abs The quantile at the first index c1 yields the first sample quantile p. c1 The specific steps are as follows: Step S321: Let N abs D represents the absolute residual matrix. abs The total number of elements in the absolute residual matrix D abs The values of all elements in the sequence are arranged in ascending order to obtain the absolute residual sequence D. sort ; Step S322: Let ns represent the first range index c r The corresponding sequence number position, ns=N abs ×c1 / 100; If the index position ns is not an integer, then round up the index position ns to obtain the first index n1; otherwise, the first index n1 is equal to the index position ns; then the first sampling quantile p c1 For the absolute residual sequence D sort The value of the n1-th element.
[0011] Furthermore, in step S33, let I... d1 Let I be the first dark foreground image. l1 For the first bright foreground image, iterate through each element of the brightness residual matrix D; specifically: Step S331: Let p αd1 (x,y) represents the first dark foreground image I. d1 Let p be the value of the pixel with x-axis and y-axis. αl1 (x,y) represents the first bright foreground image I. l1 The value of the pixel with x as the horizontal axis and y as the vertical axis; Step S332: If -D(u,v)>T high Then p αd1 (x,y)=1, if -D(u,v)<T low Then p αd1 If (x,y)=0, otherwise, calculate the first dark foreground image I using the following formula. d1 The value p of the pixel with x-axis and y-axis. αd1 (x,y): p αd1 (x,y)=(-D(u,v)-T low ) / (T high -T low ); Step S333: If D(u,v)>Thigh Then p αl1 (x,y)=1, if D(u,v)<T low Then p αl1 If (x,y)=0, otherwise, calculate the first bright foreground image I using the following formula. l1 The value p of the pixel with x-axis and y-axis. αl1 (x,y): p αl1 (x,y)=(D(u,v)-T low ) / (T high -T low ); Obtain the first dark foreground image I d1 And the first bright foreground image I l1 .
[0012] Furthermore, in step S34, the weak residual coefficient k is set. w , let I d2 Let I represent the second dark foreground image. l2 Representing the second bright foreground image, traversing the absolute residual matrix D abs Each element in; specifically: Step S341: Let p αd2 (x,y) represents the second dark foreground image I. d2 Let p be the value of the pixel with x-axis and y-axis. αl2 (x,y) represents the second bright foreground image I. l2 The value of the pixel with x-coordinate and y-coordinate, if D abs (u,v)<T low ×k w Then p αd2 (x,y)=0, p αl2 (x,y)=0, otherwise, p αd2 (x,y)=p αd1 (x,y), p αl2 (x,y)=p αl1 (x,y) yields the second dark foreground image I. d2 Second bright foreground image I l2 ; Step S342: Set the first power-law exponent k pw The second dark foreground image I is updated using the following formula. d2 Second bright foreground image I l2 The value of each pixel in: p αd2 (x,y)=(p αd2 (x,y)) kpw ; p αl2 (x,y)=(p αl2 (x,y)) kpw .
[0013] Furthermore, in step S35: the third dark foreground image I... d3 and the third bright foreground image I l3 Thresholding is performed to obtain the adaptive dark foreground image I. da and adaptive bright foreground image I la , let p αda (x,y) represents the adaptive dark foreground image I. da Let p be the value of the pixel with x-axis and y-axis. αla (x,y) represents the adaptive bright foreground image I. la The pixel value with x-coordinate and y-coordinate; specifically: Step S351: Set the near-white threshold T nw Traverse the first grayscale image I G For each pixel in the array, let p αd3 (x,y) represents the third dark foreground image I. d3 Let p be the value of the pixel with x-axis and y-axis. αl3 (x,y) represents the third bright foreground image I. l3 The value of the pixel with x-coordinate and y-coordinate, if p G (x,y)>T nw Then p αd3 (x,y)=0, p αl3 (x,y)=0; Step S352: Set the foreground threshold T1, and iterate through the third dark foreground image I. d3 For each pixel in the array, if p αd3 (x,y)<T1, then p αda (x,y)=0, otherwise, p αda (x,y)=p αd3 (x,y) yields the adaptive dark foreground image I. da ; Step S353: Traverse the third bright foreground image I l3 For each pixel in the array, if p αl3 (x,y)<T1, then p αla (x,y)=0, otherwise, p αla (x,y)=p αl3 (x,y) yields the adaptive bright foreground image I. la .
[0014] Furthermore, in step S4, based on the dark foreground image I d With bright foreground image I l Pixel fusion processing is performed on the document table image I to obtain a hybrid image I. blend The specific steps are as follows: Traversing the dark foreground image I d and bright foreground image I l , let p I,c (x, y) represents the value of the pixel with horizontal coordinate x and vertical coordinate y in channel c of the document table image I. Let p blend,c (x,y) represents the blended image I blend The pixel with x-coordinate and y-coordinate represents the value of the pixel in channel c, where channel c belongs to {B, G, R}, where B, G, and R are the blue, green, and red channels, respectively; let q blend (x,y) represents the fusion weight coefficient, and the fusion weight coefficient q is calculated using the following formula. blend (x,y): q blend (x,y)=p αl (x,y)-p αd (x,y)+p αd (x,y)×p αl (x,y); For each channel c, the blended image I is calculated using the following formula. blend The value p of the pixel with x-axis and y-axis in channel c. blend,c (x,y): p blend,c (x,y)=(255-p I,c (x,y))×q blend (x,y)+255×(1-p αl (x,y)).
[0015] Furthermore, in step S5, the grayscale peak sequence P is calculated. peak Based on grayscale peak sequence P peak For the mixed image I blend The light and dark fill regions are processed to obtain the resulting image I. clean The specific steps are as follows: Step S51: Set the cutoff threshold T trunc Set the minimum peak spacing D minpk Set the significance level coefficient k prom Set the minimum peak width threshold T wmin Set the maximum peak width threshold T wmaxpk Set the relative height threshold T rhalf Let H s1This represents the first histogram, H. s1 For smooth histogram H s The index ranges from 0 to the truncation threshold T. trunc Let v be a subsequence of -1. max H represents the first histogram. s1 Let T be the maximum value in T. prom T represents the significance threshold. prom =v max ×k prom ; Use minimum peak spacing D minpk Significance threshold T prom Peak width range (T) wmin ,T wmaxpk ) and relative height threshold T rhalf For the first histogram H s1 Peak detection was performed to obtain the candidate peak sequence P. cand and relative peak width sequence W w Among them, candidate peak sequence P cand It contains the index of each candidate peak, the left boundary index, and the right boundary index, relative to the peak width sequence W. w It includes the relative peak width of each candidate peak; Step S52: Traverse the candidate peak sequence P cand Each candidate peak and its relative peak width sequence W w For each value in the set, let p i This indicates that the candidate peak being traversed is in the first histogram H. s1 The index in, let v i H represents the first histogram. s1 index p i Let l be the value at that location. i Let r represent the left boundary index of the currently traversed candidate peak. i Let w represent the right boundary index of the currently traversed candidate peak. i W represents the relative peak width sequence currently being traversed. w The peak width value in the middle, let v lb H represents the first histogram. s1 Middle left boundary index l i Let v be the value at that point. rb H represents the first histogram. s1 Middle right boundary index r i Let v be the value at that point. base Represents the base value, v base =max(v lb ,v rb Set the base ratio threshold T. rbase Set the maximum relative peak width threshold T whmax If v base / v i ≤T rbase And w i ≤T whmax Then, the candidate peak currently being traversed is added to the peak selection sequence P. filt ; Step S53: Set the associated peak distance threshold T comp Set the saddle point ratio threshold T le For the screening peak sequence P filt Sort the sequences by peak value from largest to smallest to obtain the first sequence P1. Let P2 represent the second sequence, which is initially empty. Let T... saddle T represents the saddle point suspension threshold. saddle =v max ×T le Let N1 represent the number of peaks in the first sequence P1, and set the first loop variable i. b , set the first loop variable i b The initial value is set to 1; Step S531: If the first loop variable i b If the value is greater than N1, then proceed to step S536; Step S532: Let p j In the first sequence P1, the i-th... b A peak, making v j H represents the first histogram. s1 In the first sequence P1, the i-th b Each peak p j The value at that location is set to the first flag f. cp , will the first flag f cp Set the initial value to false, and set the second loop variable i. c , the second loop variable i c The initial value is set to 1, and N2 represents the number of peaks in the second sequence P2; Step S533: If the second loop variable i c If the value is greater than N2, then proceed to step S535; Step S534: Let p k In the second sequence P2, the i-th... c A peak, making v k H represents the first histogram. s1 In the second sequence P2, the i-th c Each peak p k Let d be the value at that location. j,k In the first sequence P1, the i-th... b Each peak p j With the i-th sequence in the second sequence P2 c Each peak p k The grayscale distance between them, d j,k =|p j-p k |, let m j,k H represents the first histogram. s1 In the first sequence P1, the i-th b Each peak p j With the i-th sequence in the second sequence P2 c Each peak p k The minimum value between, if d j,k ≤T comp Calculate the minimum value m j,k If m j,k >T saddle Then the first flag f cp Set to true, then proceed to step S535; Step S5341: Set the second loop variable i c Increment the value by 1, then proceed to step S533; Step S535: If the first flag f cp If it is false, then the i-th element in the first sequence P1 will be... b Each peak p j Add the second sequence P2, and change the first loop variable i b Increment the value by 1, then proceed to step S531; Step S536: Sort the second sequence P2 in ascending order of index to obtain the grayscale peak sequence P. peak ; Step S54: Set the peak offset D peak Set the upper limit threshold T for the grayscale of the region. ghigh Let n peak Represents the grayscale peak sequence P peak The number of mid-peaks; Step S541: If n peak =1, then jump to step S548, if n peak =0, will blend image I blend Copy to Result Image I clean Then proceed to step S549; Step S542: Let P peak [0] represents the grayscale peak sequence P. peak Let P be the index of the first peak. peak [n peak -1] represents the grayscale peak sequence P peak The index of the last peak, let g low Indicates the lower limit of grayscale in the region, g low =P peak [0]-D peak , let g v G represents the grayscale boundary value. v =P peak [n peak-1]-D peak ; Step S543: Let M colres Represents a light-filled mask, traversing the first grayscale image I. G For each pixel in the array, let m colres (u,v) represents the light-colored fill mask M. colres The element with row index u and column index v, if p G (x,y)>g v And p G (x,y)<T ghigh Then m colres (u,v)=1, otherwise m colres (u,v)=0; Step S544: Mix the image I blend The middle is filled with a light-colored mask M colres Set the marked pixels to white; Step S545: Traverse the first grayscale image I G For each pixel in the array, let m deep (u,v) represents the dark fill mask M. deep The element with row index u and column index v, if p G (x,y)>g low And p G (x,y)<g v Then m deep (u,v)=1, otherwise m deep (u,v)=0; Step S546: Set the minimum area threshold T for the region sreg Set the grayscale value G for the area fill. fill For dark fill mask M deep Perform morphological closing operations to obtain the closed mask M. closed After the closing operation, the mask M is extracted. closed The 8-neighbor connected components are used to obtain the connected component set C. reg and label matrix L reg Tag matrix L reg The value of each element in N represents the index of the connected component to which the pixel at that position belongs. Let N be the index of the connected component to which N belongs. cc Represents the set of connected components C reg The number of connected components in M, let M valid Represents the effective region mask, traversing the set of connected components C. reg Each connected component in; Step S5461: For the k-th connected component, k=1,2,…,N cc Let a k Let a represent the area of the k-th connected component, if ak ≥T sreg Then traverse the label matrix L reg Each element in; Step S54611: Let L reg (u,v) represents the label matrix L reg Let m be the element with row index u and column index v currently being traversed. valid (u,v) represents the effective area mask M. valid The element with row index u and column index v, if L reg (u,v)=k, then m valid (u,v)=1; Step S547: Traverse the effective region mask M valid For each element in m, if m valid (u,v)=1 and p G (x,y)≥g low And p G (x,y)≤g v Then the mixed image I blend The pixel with x-coordinate and y-coordinate is set to white. If m valid (u,v)=1 and p G (x,y) <g low or p G (x,y)>g v Then the mixed image I blend The values of the three channels BGR of the pixel with x-axis and y-axis are set to the region fill grayscale value G. fill The resulting image I was obtained. clean Proceed to step S549; Step S548: Let g1 represent the single-peak grayscale boundary value, g1=P peak [n peak -1]-D peak M colres1 This represents a single-peak light-fill mask, traversing the first grayscale image I. G For each pixel in the array, let m colres1 (u,v) represents the single-peak light-colored fill mask M. colres1 The element with row index u and column index v, if p G (x,y)>g1 and p G (x,y)<T ghigh Then m colres1 (u,v)=1, otherwise m colres1 (u,v)=0, the mixed image I blend The mask M is filled with a single peak and light color. colres1 The marked pixels are set to white, resulting in image I. clean; Step S549: Processing complete.
[0016] The beneficial effects of this invention are: through steps such as background estimation, foreground image construction, foreground image blending, and background removal, robust removal of complex table backgrounds from document images is achieved. This method can effectively preserve table lines and text information while removing background interference, thus improving the accuracy of subsequent table recognition and data extraction. Attached Figure Description
[0017] Figure 1 This is a flowchart of a method according to an embodiment of the present invention; Figure 2 This is a document table image according to an embodiment of the present invention; Figure 3 This is the mixed image obtained in step S4 of this embodiment of the invention; Figure 4 This is the result image obtained from step S5 of this embodiment of the invention. Detailed Implementation
[0018] The specific embodiments of the present invention will be further described in detail below with reference to the accompanying drawings. It should be noted that the specific embodiments described herein are for illustrative purposes only and are not intended to limit the scope of the invention.
[0019] This embodiment uses a document table image to illustrate a method for removing the background of a document image table proposed in this invention. For example... Figure 1 As shown in the flowchart, this invention employs the following steps to remove the background from document table images: Step S1: Document Table Image Reading: Read the document table image I to be processed, such as... Figure 2 As shown in the document table image, converting document table image I to grayscale yields the first grayscale image I. G ; Step S2: Background estimation: For the first grayscale image I G Median filtering is performed to obtain the first background grayscale image I. cfbg The document table image I is downsampled, median filtered, and bilaterally filtered to obtain the first background image I. b For the first background image I b Upsampling is performed to obtain the second background image I. bg ; Step S3: Foreground Image Construction: Construct the second background image I bg Grayscale conversion yields the second background grayscale image I. Gbg Based on the second background grayscale image I Gbg Construct a dark foreground image I d and bright foreground image Il ; Step S4: Foreground Image Blending: Based on Dark Foreground Image I d With bright foreground image I l Pixel fusion processing is performed on the document table image I to obtain a hybrid image I. blend ,like Figure 3 The blended image is shown; Step S5: Background Removal: Remove the first background grayscale image I cfbg Histogram statistics are performed to obtain a gray-level histogram H. A one-dimensional Gaussian filter is then applied to smooth the gray-level histogram H to obtain a smoothed histogram Hs. s Calculate the grayscale peak sequence P peak Based on grayscale peak sequence P peak For the mixed image I blend The light and dark fill regions are processed to obtain the resulting image I. clean ,like Figure 4 The resulting image is shown.
[0020] Further, in step S3, based on the second background grayscale image I Gbg Construct a dark foreground image I d and bright foreground image I l The specific steps are as follows: Step S31: Let D represent the brightness residual matrix, let D abs Represents the absolute residual matrix, synchronously traversing the first grayscale image I. G Second background grayscale image I Gbg For each pixel in the array, let p G (x,y) represents the first grayscale image I. G Let p be the value of the pixel whose x-coordinate is currently being traversed and whose y-coordinate is currently being traversed. Gb (x,y) represents the second background grayscale image I. Gbg Let D(u,v) represent the value of the pixel with x-coordinate and y-coordinate currently being traversed in the luminance residual matrix D. Let D(u,v) represent the element with row index u and column index v in the luminance residual matrix D. abs (u,v) represents the absolute residual matrix D. abs The elements with row index u and column index v in the luminance residual matrix D are used to calculate the elements D(u,v) with row index u and column index v in the luminance residual matrix D and the absolute residual matrix D, respectively. abs The element D with row index u and column index v abs (u,v): D(u,v)=p G (x,y)-p Gb (x,y); D abs (u,v)=|D(u,v)|; Step S32: Let T low To set a low threshold, let T high To set a high threshold, set the first index c1=75 and the second index c2=97, and calculate the absolute residual matrix D. abs The quantile at the first index c1 yields the first sample quantile p. c1 Calculate the absolute residual matrix D abs The quantile at the second index c2 yields the second sample quantile p. c2 Set the lower quantile coefficient k l =0.68, set the higher quantile coefficient k h =0.95, set the minimum low threshold T low_min =8, set the maximum low threshold T low_max =24, set the minimum interval threshold d low =12, set the maximum high threshold T high_max =72, if p c1 ×k l <T low_min Then T low =T low_min If p c1 ×k l >T low_max Then T low =T low_max Otherwise T low =p c1 ×k l If p c2 ×k h <T low +d low Then T high =T low +d low If p c2 ×k h >T high_max Then T high =T high_max Otherwise T high =p c2 ×k h ; Step S33: Let I d1 Let I be the first dark foreground image. l1 For the first bright foreground image, iterate through each element in the brightness residual matrix D; Step S331: Let p αd1 (x,y) represents the first dark foreground image I. d1 Let p be the value of the pixel with x-axis and y-axis. αl1 (x,y) represents the first bright foreground image I. l1The value of the pixel with x as the horizontal axis and y as the vertical axis; Step S332: If -D(u,v)>T high Then p αd1 (x,y)=1, if -D(u,v)<T low Then p αd1 If (x,y)=0, otherwise, calculate the first dark foreground image I using the following formula. d1 The value p of the pixel with x-axis and y-axis. αd1 (x,y): p αd1 (x,y)=(-D(u,v)-T low ) / (T high -T low ); Step S333: If D(u,v)>T high Then p αl1 (x,y)=1, if D(u,v)<T low Then p αl1 If (x,y)=0, otherwise, calculate the first bright foreground image I using the following formula. l1 The value p of the pixel with x-axis and y-axis. αl1 (x,y): p αl1 (x,y)=(D(u,v)-T low ) / (T high -T low ); Obtain the first dark foreground image I d1 And the first bright foreground image I l1 ; Step S34: Set the weak residual coefficient k w =0.55, let I d2 Let I represent the second dark foreground image. l2 Representing the second bright foreground image, traversing the absolute residual matrix D abs Each element in; Step S341: Let p αd2 (x,y) represents the second dark foreground image I. d2 Let p be the value of the pixel with x-axis and y-axis. αl2 (x,y) represents the second bright foreground image I. l2 The value of the pixel with x-coordinate and y-coordinate, if D abs (u,v)<T low ×k w Then p αd2 (x,y)=0, p αl2 (x,y)=0, otherwise, pαd2 (x,y)=p αd1 (x,y), p αl2 (x,y)=p αl1 (x,y) yields the second dark foreground image I. d2 Second bright foreground image I l2 ; Step S342: Set the first power-law exponent k pw =2, update the second dark foreground image I using the following formula. d2 Second bright foreground image I l2 The value of each pixel in: p αd2 (x,y)=(p αd2 (x,y)) kpw ; p αl2 (x,y)=(p αl2 (x,y)) kpw ; Step S35: For the second dark foreground image I d2 Second bright foreground image I l2 Gaussian filtering is applied to smooth the image, resulting in the third dark foreground image I. d3 and the third bright foreground image I l3 For the third dark foreground image I d3 and the third bright foreground image I l3 Thresholding is performed to obtain the adaptive dark foreground image I. da and adaptive bright foreground image I la , let p αda (x,y) represents the adaptive dark foreground image I. da Let p be the value of the pixel with x-axis and y-axis. αla (x,y) represents the adaptive bright foreground image I. la The value of the pixel with x as the horizontal axis and y as the vertical axis; Step S351: Set the near-white threshold T nw =235, traverse the first grayscale image I G For each pixel in the array, let p αd3 (x,y) represents the third dark foreground image I. d3 Let p be the value of the pixel with x-axis and y-axis. αl3 (x,y) represents the third bright foreground image I. l3 The value of the pixel with x-coordinate and y-coordinate, if p G (x,y)>T nw Then p αd3 (x,y)=0, p αl3 (x,y)=0; Step S352: Set the foreground threshold T1=0.06, and iterate through the third dark foreground image I. d3 For each pixel in the array, if p αd3 (x,y)<T1, then p αda (x,y)=0, otherwise, p αda (x,y)=p αd3 (x,y) yields the adaptive dark foreground image I. da ; Step S353: Traverse the third bright foreground image I l3 For each pixel in the array, if p αl3 (x,y)<T1, then p αla (x,y)=0, otherwise, p αla (x,y)=p αl3 (x,y) yields the adaptive bright foreground image I. la ; Step S36: Let D fix Represents a fixed brightness residual matrix, synchronously traversing the first grayscale image I. G And the first background grayscale image I cfbg For each pixel in the array, let p cfbg (x,y) represents the first background grayscale image I. cfbg Let D be the value of the pixel whose x-coordinate is currently being traversed and whose y-coordinate is currently being traversed. fix (u,v) represents the fixed luminance residual matrix D. fix The element with row index u and column index v, D fix (u,v)=p G (x,y)-p cfbg (x,y); Step S37: Set a fixed lower threshold T fixlo =12, set a fixed upper limit threshold T fixhi =45, let I dfix Let p represent a dark foreground image with a fixed threshold. αfix (x,y) represents the dark foreground image I with a fixed threshold. dfix The values of the pixels with x-coordinate and y-coordinate are given. Let t1 represent the first intermediate result, and t1 = (-D). fix (u,v)-T fixlo ) / (T fixhi -T fixlo If t1 < 0, then p αfix If (x,y)=0, and t1>1, then p αfix (x,y)=1, otherwise p αfix (x,y)=t1; Step S38: Set the luminance weight wclg =0.45, let I d To represent a dark foreground image, let I... l Let p represent a bright foreground image. αd (x,y) represents the dark foreground image I. d Let p be the value of the pixel with x-axis and y-axis. αl (x,y) represents the bright foreground image I. l The value of the pixel with x-axis and y-axis in the middle, p αd (x,y)=max(p αda (x,y),p αfix (x,y)), p αl (x,y)=p αla (x,y)×w clg ; Step S39: Set the second power law exponent k pwcf =2, update the dark foreground image I using the following formula. d and bright foreground image I l The value of each pixel in: p αd (x,y)=(p αd (x,y)) kpwcf ; p αl (x,y)=(p αl (x,y)) kpwcf ; Obtain dark foreground image I d and bright foreground image I l ; Further, in step S32, the absolute residual matrix D is calculated. abs The quantile at the first index c1 yields the first sample quantile p. c1 The specific steps are as follows: Step S321: Let N abs D represents the absolute residual matrix. abs The total number of elements in the absolute residual matrix D abs The values of all elements in the sequence are arranged in ascending order to obtain the absolute residual sequence D. sort ; Step S322: Let ns represent the first range index c r The corresponding sequence number position, ns=N abs ×c1 / 100; If the index position ns is not an integer, then round up the index position ns to obtain the first index n1; otherwise, the first index n1 is equal to the index position ns; then the first sampling quantile p c1 For the absolute residual sequence D sortThe value of the n1-th element; Furthermore, in step S4, based on the dark foreground image I d With bright foreground image I l Pixel fusion processing is performed on the document table image I to obtain a hybrid image I. blend The specific steps are as follows: Traversing the dark foreground image I d and bright foreground image I l , let p I,c (x, y) represents the value of the pixel with horizontal coordinate x and vertical coordinate y in channel c of the document table image I. Let p blend,c (x,y) represents the blended image I blend Let q be the value of the pixel with x-coordinate and y-coordinate in channel c, where channel c belongs to {B, G, R}. blend (x,y) represents the fusion weight coefficient, and the fusion weight coefficient q is calculated using the following formula. blend (x,y): q blend (x,y)=p αl (x,y)-p αd (x,y)+p αd (x,y)×p αl (x,y); For each channel c, the blended image I is calculated using the following formula. blend The value p of the pixel with x-axis and y-axis in channel c. blend,c (x,y): p blend,c (x,y)=(255-p I,c (x,y))×q blend (x,y)+255×(1-p αl (x,y)).
[0021] Further, in step S5, the grayscale peak sequence P is calculated. peak Based on grayscale peak sequence P peak For the mixed image I blend The light and dark fill regions are processed to obtain the resulting image I. clean The specific steps are as follows: Step S51: Set the cutoff threshold T trunc =248, set the minimum peak spacing D minpk =10, set the significance level coefficient k. prom =0.01, set the minimum peak width threshold T wmin =1, set the maximum peak width threshold T wmaxpk =12, set the relative height threshold T rhalf =0.5, let Hs1 This represents the first histogram, H. s1 For smooth histogram H s The index ranges from 0 to the truncation threshold T. trunc Let v be a subsequence of -1. max H represents the first histogram. s1 Let T be the maximum value in T. prom T represents the significance threshold. prom =v max ×k prom Using minimum peak spacing D minpk Significance threshold T prom Peak width range (T) wmin ,T wmaxpk ) and relative height threshold T rhalf For the first histogram H s1 Peak detection was performed to obtain the candidate peak sequence P. cand and relative peak width sequence W w Among them, candidate peak sequence P cand It contains the index of each candidate peak, the left boundary index, and the right boundary index, relative to the peak width sequence W. w It includes the relative peak width of each candidate peak; The peak detection algorithm in the above steps is a common method for histogram peak detection in images. See Sezan M. A peak detection algorithm and its application to histogram-based image data reduction [J]. Computer Vision, Graphics, and Image Processing, 1989, 47 (3): 396-396. DOI:10.1016 / 0734-189X(89)90124-2.
[0022] Step S52: Traverse the candidate peak sequence P cand Each candidate peak and its relative peak width sequence W w For each value in the set, let p i This indicates that the candidate peak being traversed is in the first histogram H. s1 The index in, let v i H represents the first histogram. s1 index p i Let l be the value at that location. i Let r represent the left boundary index of the currently traversed candidate peak. i Let w represent the right boundary index of the currently traversed candidate peak. i W represents the relative peak width sequence currently being traversed. wThe peak width value in the middle, let v lb H represents the first histogram. s1 Middle left boundary index l i Let v be the value at that point. rb H represents the first histogram. s1 Middle right boundary index r i Let v be the value at that point. base Represents the base value, v base =max(v lb ,v rb Set the base ratio threshold T. rbase =0.22, set the maximum relative peak width threshold T whmax =3, if v base / v i ≤T rbase And w i ≤T whmax Then, the candidate peak currently being traversed is added to the peak selection sequence P. filt ; Step S53: Set the associated peak distance threshold T comp =35, set the saddle point ratio threshold T le =0.015, for the selected peak sequence P filt Sort the sequences by peak value from largest to smallest to obtain the first sequence P1. Let P2 represent the second sequence, which is initially empty. Let T... saddle T represents the saddle point suspension threshold. saddle =v max ×T le Let N1 represent the number of peaks in the first sequence P1, and set the first loop variable i. b , set the first loop variable i b The initial value is set to 1; Step S531: If the first loop variable i b If the value is greater than N1, then proceed to step S536; Step S532: Let p j In the first sequence P1, the i-th... b A peak, making v j H represents the first histogram. s1 In the first sequence P1, the i-th b Each peak p j The value at that location is set to the first flag f. cp , will the first flag f cp Set the initial value to false, and set the second loop variable i. c , the second loop variable i c The initial value is set to 1, and N2 represents the number of peaks in the second sequence P2; Step S533: If the second loop variable i cIf the value is greater than N2, then proceed to step S535; Step S534: Let p k In the second sequence P2, the i-th... c A peak, making v k H represents the first histogram. s1 In the second sequence P2, the i-th c Each peak p k Let d be the value at that location. j,k In the first sequence P1, the i-th... b Each peak p j With the i-th sequence in the second sequence P2 c Each peak p k The grayscale distance between them, d j,k =|p j -p k |, if d j,k ≤T comp Calculate the first histogram H s1 In the second sequence P2, the i-th c Each peak p j With the i-th sequence in the second sequence P2 c Each peak p k The minimum value m between j,k If m j,k >T saddle Then the first flag f cp Set to true, then proceed to step S535; Step S5341: Set the second loop variable i c Increment the value by 1, then proceed to step S533; Step S535: If the first flag f cp If it is false, then the i-th element in the first sequence P1 will be... b Each peak p j Add the second sequence P2, and change the first loop variable i b Increment the value by 1, then proceed to step S531; Step S536: Sort the second sequence P2 in ascending order of index to obtain the grayscale peak sequence P. peak ; Step S54: Set the peak offset D peak =20, set the upper limit threshold T for the grayscale of the region. ghigh =240, let n peak Represents the grayscale peak sequence P peak The number of mid-peaks; Step S541: If n peak =1, then jump to step S548, if n peak =0, will blend image I blend Copy to Result Image I cleanThen proceed to step S549; Step S542: Let P peak [0] represents the grayscale peak sequence P. peak Let P be the index of the first peak. peak [n peak -1] represents the grayscale peak sequence P peak The index of the last peak, let g low Indicates the lower limit of grayscale in the region, g low =P peak [0]-D peak , let g v G represents the grayscale boundary value. v =P peak [n peak -1]-D peak ; Step S543: Let M colres Represents a light-filled mask, traversing the first grayscale image I. G For each pixel in the array, let m colres (u,v) represents the light-colored fill mask M. colres The element with row index u and column index v, if p G (x,y)>g v And p G (x,y)<T ghigh Then m colres (u,v)=1, otherwise m colres (u,v)=0; Step S544: Mix the image I blend The middle is filled with a light-colored mask M colres Set the marked pixels to white; Step S545: Let M deep Represents a dark-filled mask, traversing the first grayscale image I G For each pixel in the array, let m deep (u,v) represents the dark fill mask M. deep The element with row index u and column index v, if p G (x,y)>g low And p G (x,y)<g v Then m deep (u,v)=1, otherwise m deep (u,v)=0; Step S546: Set the minimum area threshold T for the region sreg =5000, set the area fill grayscale value G. fill =130, for dark fill mask M deep Perform morphological closing operations to obtain the closed mask M.closed After the closing operation, the mask M is extracted. closed The 8-neighbor connected components are used to obtain the connected component set C. reg and label matrix L reg Tag matrix L reg The value of each element in N represents the index of the connected component to which the pixel at that position belongs. Let N be the index of the connected component to which N belongs. cc Represents the set of connected components C reg The number of connected components in M, let M valid Represents the effective region mask, traversing the set of connected components C. reg Each connected component in; Step S5461: For the k-th connected component, k=1,2,…,N cc Let a k Let a represent the area of the k-th connected component, if a k ≥T sreg Then traverse the label matrix L reg Each element in; Step S54611: Let L reg (u,v) represents the label matrix L reg Let m be the element with row index u and column index v currently being traversed. valid (u,v) represents the effective area mask M. valid The element with row index u and column index v, if L reg (u,v)=k, then m valid (u,v)=1; Step S547: Traverse the effective region mask M valid For each element in m, if m valid (u,v)=1 and p G (x,y)≥g low And p G (x,y)≤g v Then the mixed image I blend The pixel with x-coordinate and y-coordinate is set to white. If m valid (u,v)=1 and p G (x,y) <g low or p G (x,y)>g v Then the mixed image I blend The values of the three channels BGR of the pixel with x-axis and y-axis are set to the region fill grayscale value G. fill The resulting image I was obtained. clean Proceed to step S549; Step S548: Let g1 represent the single-peak grayscale boundary value, g1=P peak [npeak -1]-D peak M colres1 This represents a single-peak light-fill mask, traversing the first grayscale image I. G For each pixel in the array, let m colres1 (u,v) represents the single-peak light-colored fill mask M. colres1 The element with row index u and column index v, if p G (x,y)>g1 and p G (x,y)<T ghigh Then m colres1 (u,v)=1, otherwise m colres1 (u,v)=0, the mixed image I blend The mask M is filled with a single peak and light color. colres1 The marked pixels are set to white, resulting in image I. clean .
[0023] Step S549: Processing complete; The above description is a preferred embodiment of the present invention and is not intended to limit the present invention. All equivalent or modified embodiments made without departing from the spirit disclosed in the present invention should be included within the scope of protection of the present invention.
Claims
1. A method for removing background from document images and tables, characterized in that: Removing the table background involves the following steps: Step S1: Document table image reading: Read the document table image I to be processed, convert the document table image I to grayscale, and obtain the first grayscale image I. G ; Step S2: Background estimation: For the first grayscale image I G Median filtering is performed to obtain the first background grayscale image I. cfbg The document table image I is downsampled, median filtered, and bilaterally filtered to obtain the first background image I. b For the first background image I b Upsampling is performed to obtain the second background image I. bg ; Step S3: Foreground Image Construction: Construct the second background image I bg Grayscale conversion yields the second background grayscale image I. Gbg Based on the second background grayscale image I Gbg Construct a dark foreground image I d and bright foreground image I l ; Step S4: Foreground Image Blending: Based on Dark Foreground Image I d With bright foreground image I l Pixel fusion processing is performed on the document table image I to obtain a hybrid image I. blend ; Step S5: Background Removal: Remove the first background grayscale image I cfbg Histogram statistics are performed to obtain a gray-level histogram H. A one-dimensional Gaussian filter is then applied to smooth the gray-level histogram H to obtain a smoothed histogram Hs. s Calculate the grayscale peak sequence P peak Based on grayscale peak sequence P peak For the mixed image I blend The light and dark fill regions are processed to obtain the resulting image I. clean .
2. The method for removing document image table background according to claim 1, characterized in that: In step S3, based on the second background grayscale image I Gbg Construct a dark foreground image I d and bright foreground image I l The specific steps are as follows: Step S31: Let D represent the brightness residual matrix, let D abs Represents the absolute residual matrix, synchronously traversing the first grayscale image I. G Second background grayscale image I Gbg For each pixel in the array, let p G (x,y) represents the first grayscale image I. G Let p be the value of the pixel whose x-coordinate is currently being traversed and whose y-coordinate is currently being traversed. Gb (x,y) represents the second background grayscale image I. Gbg Let D(u,v) represent the value of the pixel with x-coordinate and y-coordinate currently being traversed in the luminance residual matrix D. Let D(u,v) represent the element with row index u and column index v in the luminance residual matrix D. abs (u,v) represents the absolute residual matrix D. abs The elements with row index u and column index v in the luminance residual matrix D are used to calculate the elements D(u,v) with row index u and column index v in the luminance residual matrix D and the absolute residual matrix D, respectively. abs The element D with row index u and column index v abs (u,v): D(u,v)=p G (x,y)-p Gb (x,y); D abs (u,v)=|D(u,v)|; Step S32: Let T low To set a low threshold, let T high To set a high threshold, set a first index c1 and a second index c2, and calculate the absolute residual matrix D. abs The quantile at the first index c1 yields the first sample quantile p. c1 Calculate the absolute residual matrix D abs The quantile at the second index c2 yields the second sample quantile p. c2 Set the lower quantile coefficient k l Set the high quantile coefficient k h Set the minimum low threshold T low_min Set the maximum low threshold T low_max Set the minimum interval threshold d low Set the maximum high threshold T high_max If p c1 ×k l <T low_min Then T low =T low_min If p c1 ×k l >T low_max Then T low =T low_max Otherwise T low =p c1 ×k l If p c2 ×k h <T low +d low Then T high =T low +d low If p c2 ×k h >T high_max Then T high =T high_max Otherwise T high =p c2 ×k h ; Step S33: Let I d1 Let I be the first dark foreground image. l1 For the first bright foreground image, iterate through each element in the brightness residual matrix D; Obtain the first dark foreground image I d1 And the first bright foreground image I l1 ; Step S34: Set the weak residual coefficient k w , let I d2 Let I represent the second dark foreground image. l2 Representing the second bright foreground image, traversing the absolute residual matrix D abs Each element in; Obtain the second dark foreground image I d2 Second bright foreground image I l2 ; Step S35: For the second dark foreground image I d2 Second bright foreground image I l2 Gaussian filtering is applied to smooth the image, resulting in the third dark foreground image I. d3 and the third bright foreground image I l3 For the third dark foreground image I d3 and the third bright foreground image I l3 Thresholding is performed to obtain the adaptive dark foreground image I. da and adaptive bright foreground image I la , let p αda (x,y) represents the adaptive dark foreground image I. da Let p be the value of the pixel with x-axis and y-axis. αla (x,y) represents the adaptive bright foreground image I. la The value of the pixel with x as the horizontal axis and y as the vertical axis; Step S36: Let D fix Represents a fixed brightness residual matrix, synchronously traversing the first grayscale image I. G And the first background grayscale image I cfbg For each pixel in the array, let p cfbg (x,y) represents the first background grayscale image I. cfbg Let D be the value of the pixel whose x-coordinate is currently being traversed and whose y-coordinate is currently being traversed. fix (u,v) represents the fixed luminance residual matrix D. fix The element with row index u and column index v, D fix (u,v)=p G (x,y)-p cfbg (x,y); Step S37: Set a fixed lower threshold T fixlo Set a fixed upper limit threshold T fixhi , let I dfix Let p represent a dark foreground image with a fixed threshold. αfix (x,y) represents the dark foreground image I with a fixed threshold. dfix The values of the pixels with x-coordinate and y-coordinate are given. Let t1 represent the first intermediate result, and t1 = (-D). fix (u,v)-T fixlo ) / (T fixhi -T fixlo If t1 < 0, then p αfix If (x,y)=0, and t1>1, then p αfix (x,y)=1, otherwise p αfix (x,y)=t1; Step S38: Set the luminance weight w clg , let p αd (x,y) represents the dark foreground image I. d Let p be the value of the pixel with x-axis and y-axis. αl (x,y) represents the bright foreground image I. l The value of the pixel with x-axis and y-axis in the middle, p αd (x,y)=max(p αda (x,y),p αfix (x,y)), p αl (x,y)=p αla (x,y)×w clg ; Step S39: Set the second power law exponent k pwcf The dark foreground image I is updated using the following formula. d and bright foreground image I l The value of each pixel in: p αd (x,y)=(p αd (x,y)) kpwcf ; p αl (x,y)=(p αl (x,y)) kpwcf ; Obtain dark foreground image I d and bright foreground image I l .
3. The method for removing table background from document images according to claim 2, characterized in that: In step S32, the absolute residual matrix D is calculated. abs The quantile at the first index c1 yields the first sample quantile p. c1 The specific steps are as follows: Step S321: Let N abs D represents the absolute residual matrix. abs The total number of elements in the absolute residual matrix D abs The values of all elements in the sequence are arranged in ascending order to obtain the absolute residual sequence D. sort ; Step S322: Let ns represent the first range index c r The corresponding sequence number position, ns=N abs ×c1 / 100; If the index position ns is not an integer, then round up the index position ns to obtain the first index n1; otherwise, the first index n1 is equal to the index position ns; then the first sampling quantile p c1 For the absolute residual sequence D sort The value of the n1-th element.
4. The method for removing document image table background according to claim 3, characterized in that: In step S33, let I d1 Let I be the first dark foreground image. l1 For the first bright foreground image, iterate through each element in the brightness residual matrix D; Specifically: Step S331: Let p αd1 (x,y) represents the first dark foreground image I. d1 Let p be the value of the pixel with x-axis and y-axis. αl1 (x,y) represents the first bright foreground image I. l1 The value of the pixel with x as the horizontal axis and y as the vertical axis; Step S332: If -D(u,v)>T high Then p αd1 (x,y)=1, if -D(u,v)<T low Then p αd1 If (x,y)=0, otherwise, calculate the first dark foreground image I using the following formula. d1 The value p of the pixel with x-axis and y-axis. αd1 (x,y): p αd1 (x,y)=(-D(u,v)-T low ) / (T high -T low ); Step S333: If D(u,v)>T high Then p αl1 (x,y)=1, if D(u,v)<T low Then p αl1 If (x,y)=0, otherwise, calculate the first bright foreground image I using the following formula. l1 The value p of the pixel with x-axis and y-axis. αl1 (x,y): p αl1 (x,y)=(D(u,v)-T low ) / (T high -T low ); Obtain the first dark foreground image I d1 And the first bright foreground image I l1 .
5. The method for removing table background from document images according to claim 4, characterized in that: In step S34, the weak residual coefficient k is set. w , let I d2 Let I represent the second dark foreground image. l2 Representing the second bright foreground image, traversing the absolute residual matrix D abs Each element in; Specifically: Step S341: Let p αd2 (x,y) represents the second dark foreground image I. d2 Let p be the value of the pixel with x-axis and y-axis. αl2 (x,y) represents the second bright foreground image I. l2 The value of the pixel with x-coordinate and y-coordinate, if D abs (u,v)<T low ×k w Then p αd2 (x,y)=0, p αl2 (x,y)=0, otherwise, p αd2 (x,y)=p αd1 (x,y), p αl2 (x,y)=p αl1 (x,y) yields the second dark foreground image I. d2 Second bright foreground image I l2 ; Step S342: Set the first power-law exponent k pw The second dark foreground image I is updated using the following formula. d2 Second bright foreground image I l2 The value of each pixel in: p αd2 (x,y)=(p αd2 (x,y)) kpw ; p αl2 (x,y)=(p αl2 (x,y)) kpw 。 6. The method for removing table background from document images according to claim 5, characterized in that: In step S35: For the third dark foreground image I d3 and the third bright foreground image I l3 Thresholding is performed to obtain the adaptive dark foreground image I. da and adaptive bright foreground image I la , let p αda (x,y) represents the adaptive dark foreground image I. da Let p be the value of the pixel with x-axis and y-axis. αla (x,y) represents the adaptive bright foreground image I. la The pixel value with x-coordinate and y-coordinate; specifically: Step S351: Set the near-white threshold T nw Traverse the first grayscale image I G For each pixel in the array, let p αd3 (x,y) represents the third dark foreground image I. d3 Let p be the value of the pixel with x-axis and y-axis. αl3 (x,y) represents the third bright foreground image I. l3 The value of the pixel with x-coordinate and y-coordinate, if p G (x,y)>T nw Then p αd3 (x,y)=0, p αl3 (x,y)=0; Step S352: Set the foreground threshold T1, and iterate through the third dark foreground image I. d3 For each pixel in the array, if p αd3 (x,y)<T1, then p αda (x,y)=0, otherwise, p αda (x,y)=p αd3 (x,y) yields the adaptive dark foreground image I. da ; Step S353: Traverse the third bright foreground image I l3 For each pixel in the array, if p αl3 (x,y)<T1, then p αla (x,y)=0, otherwise, p αla (x,y)=p αl3 (x,y) yields the adaptive bright foreground image I. la .
7. The method for removing table background from document images according to claim 6, characterized in that: In step S4, based on the dark foreground image I d With bright foreground image I l Pixel fusion processing is performed on the document table image I to obtain a hybrid image I. blend The specific steps are as follows: Traversing the dark foreground image I d and bright foreground image I l , let p I,c (x, y) represents the value of the pixel with horizontal coordinate x and vertical coordinate y in channel c of the document table image I. Let p blend,c (x,y) represents the blended image I blend The pixel with x-coordinate and y-coordinate represents the value of the pixel in channel c, where channel c belongs to {B, G, R}, where B, G, and R are the blue, green, and red channels, respectively; let q blend (x,y) represents the fusion weight coefficient, and the fusion weight coefficient q is calculated using the following formula. blend (x,y): que blend (x,y)=p αl (x,y)-p αd (x,y)+p αd (x,y)×p αl (x,y); For each channel c, the blended image I is calculated using the following formula. blend The value p of the pixel with x-axis and y-axis in channel c. blend,c (x,y): p blend,c (x,y)=(255-p I,c (x,y))×q blend (x,y)+255×(1-p αl (x,y))。 8. The method for removing table background from document images according to claim 7, characterized in that: In step S5, the grayscale peak sequence P is calculated. peak Based on grayscale peak sequence P peak For the mixed image I blend The light and dark fill regions are processed to obtain the resulting image I. clean The specific steps are as follows: Step S51: Set the cutoff threshold T trunc Set the minimum peak spacing D minpk Set the significance level coefficient k prom Set the minimum peak width threshold T wmin Set the maximum peak width threshold T wmaxpk Set the relative height threshold T rhalf Let H s1 This represents the first histogram, H. s1 For smooth histogram H s The index ranges from 0 to the truncation threshold T. trunc Let v be a subsequence of -1. max H represents the first histogram. s1 Let T be the maximum value in T. prom T represents the significance threshold. prom =v max ×k prom ; Use minimum peak spacing D minpk Significance threshold T prom Peak width range (T) wmin ,T wmaxpk ) and relative height threshold T rhalf For the first histogram H s1 Peak detection was performed to obtain the candidate peak sequence P. cand and relative peak width sequence W w Among them, candidate peak sequence P cand It contains the index of each candidate peak, the left boundary index, and the right boundary index, relative to the peak width sequence W. w It includes the relative peak width of each candidate peak; Step S52: Traverse the candidate peak sequence P cand Each candidate peak and its relative peak width sequence W w For each value in the set, let p i This indicates that the candidate peak being traversed is in the first histogram H. s1 The index in, let v i H represents the first histogram. s1 index p i Let l be the value at that location. i Let r represent the left boundary index of the currently traversed candidate peak. i Let w represent the right boundary index of the currently traversed candidate peak. i W represents the relative peak width sequence currently being traversed. w The peak width value in the middle, let v lb H represents the first histogram. s1 Middle left boundary index l i Let v be the value at that point. rb H represents the first histogram. s1 Middle right boundary index r i Let v be the value at that point. base Represents the base value, v base =max(v lb ,v rb Set the base ratio threshold T. rbase Set the maximum relative peak width threshold T whmax If v base / v i ≤T rbase And w i ≤T whmax Then, the candidate peak currently being traversed is added to the peak selection sequence P. filt ; Step S53: Set the associated peak distance threshold T comp Set the saddle point ratio threshold T le For the screening peak sequence P filt Sort the sequences by peak value from largest to smallest to obtain the first sequence P1. Let P2 represent the second sequence, which is initially empty. Let T... saddle T represents the saddle point suspension threshold. saddle =v max ×T le Let N1 represent the number of peaks in the first sequence P1, and set the first loop variable i. b , set the first loop variable i b The initial value is set to 1; Step S531: If the first loop variable i b If the value is greater than N1, then proceed to step S536; Step S532: Let p j In the first sequence P1, the i-th... b A peak, making v j H represents the first histogram. s1 In the first sequence P1, the i-th b Each peak p j The value at that location is set to the first flag f. cp , will the first flag f cp Set the initial value to false, and set the second loop variable i. c , the second loop variable i c The initial value is set to 1, and N2 represents the number of peaks in the second sequence P2; Step S533: If the second loop variable i c If the value is greater than N2, then proceed to step S535; Step S534: Let p k In the second sequence P2, the i-th... c A peak, making v k H represents the first histogram. s1 In the second sequence P2, the i-th c Each peak p k Let d be the value at that location. j,k In the first sequence P1, the i-th... b Each peak p j With the i-th sequence in the second sequence P2 c Each peak p k The grayscale distance between them, d j,k =|p j -p k |, let m j,k H represents the first histogram. s1 In the first sequence P1, the i-th b Each peak p j With the i-th sequence in the second sequence P2 c Each peak p k The minimum value between, if d j,k ≤T comp Calculate the minimum value m j,k If m j,k >T saddle Then the first flag f cp Set to true, then proceed to step S535; Step S5341: Set the second loop variable i c Increment the value by 1, then proceed to step S533; Step S535: If the first flag f cp If it is false, then the i-th element in the first sequence P1 will be... b Each peak p j Add the second sequence P2, and change the first loop variable i b Increment the value by 1, then proceed to step S531; Step S536: Sort the second sequence P2 in ascending order of index to obtain the grayscale peak sequence P. peak ; Step S54: Set the peak offset D peak Set the upper limit threshold T for the grayscale of the region. ghigh Let n peak Represents the grayscale peak sequence P peak The number of mid-peaks; Step S541: If n peak =1, then jump to step S548, if n peak =0, will blend image I blend Copy to Result Image I clean Then proceed to step S549; Step S542: Let P peak [0] represents the grayscale peak sequence P. peak Let P be the index of the first peak. peak [n peak -1] represents the grayscale peak sequence P peak The index of the last peak, let g low Indicates the lower limit of grayscale in the region, g low =P peak [0]-D peak , let g v G represents the grayscale boundary value. v =P peak [n peak -1]-D peak ; Step S543: Let M colres Represents a light-filled mask, traversing the first grayscale image I. G For each pixel in the array, let m colres (u,v) represents the light-colored fill mask M. colres The element with row index u and column index v, if p G (x,y)>g v And p G (x,y)<T ghigh Then m colres (u,v)=1, otherwise m colres (u,v)=0; Step S544: Mix the image I blend The middle is filled with a light-colored mask M colres Set the marked pixels to white; Step S545: Traverse the first grayscale image I G For each pixel in the array, let m deep (u,v) represents the dark fill mask M. deep The element with row index u and column index v, if p G (x,y)>g low And p G (x,y)<g v Then m deep (u,v)=1, otherwise m deep (u,v)=0; Step S546: Set the minimum area threshold T for the region sreg Set the grayscale value G for the area fill. fill For dark fill mask M deep Perform morphological closing operations to obtain the closed mask M. closed After the closing operation, the mask M is extracted. closed The 8-neighbor connected components are used to obtain the connected component set C. reg and label matrix L reg Tag matrix L reg The value of each element in N represents the index of the connected component to which the pixel at that position belongs. Let N be the index of the connected component to which N belongs. cc Represents the set of connected components C reg The number of connected components in M, let M valid Represents the effective region mask, traversing the set of connected components C. reg Each connected component in; Step S5461: For the k-th connected component, k=1,2,…,N cc Let a k Let a represent the area of the k-th connected component, if a k ≥T sreg Then traverse the label matrix L reg Each element in; Step S54611: Let L reg (u,v) represents the label matrix L reg Let m be the element with row index u and column index v currently being traversed. valid (u,v) represents the effective area mask M. valid The element with row index u and column index v, if L reg (u,v)=k, then m valid (u,v)=1; Step S547: Traverse the effective region mask M valid For each element in m, if m valid (u,v)=1 and p G (x,y)≥g low And p G (x,y)≤g v Then the mixed image I blend The pixel with x-coordinate and y-coordinate is set to white. If m valid (u,v)=1 and p G (x,y) <g low or p G (x,y)>g v Then the mixed image I blend The values of the three channels BGR of the pixel with x-axis and y-axis are set to the region fill grayscale value G. fill The resulting image I was obtained. clean Proceed to step S549; Step S548: Let g1 represent the single-peak grayscale boundary value, g1=P peak [n peak -1]-D peak M colres1 This represents a single-peak light-fill mask, traversing the first grayscale image I. G For each pixel in the array, let m colres1 (u,v) represents the single-peak light-colored fill mask M. colres1 The element with row index u and column index v, if p G (x,y)>g1 and p G (x,y)<T ghigh Then m colres1 (u,v)=1, otherwise m colres1 (u,v)=0, the mixed image I blend The mask M is filled with a single peak and light color. colres1 The marked pixels are set to white, resulting in image I. clean ; Step S549: Processing complete.
Citation Information
Patent Citations
Document background interference removing method and device
CN122024246A
Image processing method and apparatus
WO2018028234A1
