Seal image background interference identification method

By preprocessing, segmenting and adaptive brightness calculation of seal images, combined with foreground contour analysis, the interference elements in the background of seal images are identified, and the problem of low accuracy of seal image recognition in the prior art is solved, and efficient seal extraction and image quality protection are achieved.

CN119888753APending Publication Date: 2025-04-25SHANGHAI ZHIYU INFORMATION TECH CO LTD +1
View PDF 1 Cites 0 Cited by

Patent Information

Application Number
CN202411965324.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2024-12-30
Publication Date
2025-04-25

AI Technical Summary

Technical Problem

The prior art is difficult to accurately identify whether there are interfering elements such as black text and table line segments in the seal image, resulting in reduced seal extraction accuracy and damage to seal image quality.

Method used

Through seal image preprocessing, segmentation, adaptive brightness calculation and foreground profile analysis, it is possible to identify whether there are interfering elements in the background of the seal image. Specific steps include image graying and binarization, foreground and background segmentation, adaptive brightness value calculation, foreground outline minimum external rectangle area calculation, and interference element recognition.

Benefits of technology

Accurate identification of the background interference of seal image is achieved, avoiding damage to the quality of seal image during seal extraction, and improving the accuracy of seal extraction.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN119888753A_ABST
    Figure CN119888753A_ABST
Patent Text Reader

Abstract

The invention discloses a seal image background interference identification method comprising the following steps: S1, reading a seal image, and preprocessing the seal image; s2, segmenting the seal image into a foreground image and a background image, and extracting a foreground contour from the foreground image; s3, according to the histogram of the background image, calculating a self-adaptive brightness value conforming to a brightness interval of the background image; s4, calculating the minimum bounding rectangle area of each contour of the foreground image; and S5, judging background interference of the seal image. According to the invention, based on the feature difference between the foreground information and the background information of the seal image and the feature difference based on the image brightness, interference information such as characters and table line segments in the background of the seal image is accurately identified, and reference information is provided for subsequent seal background interference removal and seal identification.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] The invention belongs to the field of seal image processing, and in particular relates to a method for identifying seal image background interference. Background Art

[0002] In the era of digitalization and intelligent office, documents containing seals are gradually stored, transmitted and processed in the form of digital images. Extracting seals from digital document images containing seals can provide technical support for downstream tasks such as seal review and seal text recognition, and significantly reduce manpower input and improve work efficiency. However, for high-quality seal images, the existing seal extraction algorithm will reduce the quality of the original seal image during the processing. Therefore, accurately identifying whether the seal image contains interference pixels and selecting an appropriate seal extraction strategy based on the recognition results can avoid damaging the quality of the original seal image and significantly improve the accuracy of seal extraction. In addition, the recognition method of seal image background interference can also be used as a tool to evaluate the quality of seal images and help to quickly screen out high-quality seal image data.

[0003] There is a patent document named "A method and device for identifying the background interference degree of an image" (publication number: CN109410169B). This invention first obtains several main images in the image through CNN, and then preliminarily selects the main image with an area larger than a preset threshold, and finally compares the difference between the hue average value of the main image and the hue average value of the non-main image, thereby identifying the background interference degree of the image. However, simply dividing the image into main images and non-main images to identify various types of feature differences will result in the inability to accurately identify subtle pixel interference. Using only hue as an identification indicator of background interference cannot effectively identify background interference of black pixels. Therefore, it is particularly important to develop a simple and efficient algorithm that can accurately identify whether the background of the seal image contains interference pixels. Summary of the invention

[0004] To solve the above problems, the present invention proposes a method for identifying background interference of seal images. The method can accurately and efficiently identify whether there are interference elements such as black text and table segments in the background of the seal image. It can not only serve as a tool for evaluating the quality of seal images, but also help optimize the processing flow of the seal extraction algorithm for pure seal images.

[0005] The present invention proposes a method for identifying background interference of a seal image, and the technical solution thereof is as follows:

[0006] Step S1: preprocessing the seal image; reading the first image I, graying and binarizing the first image I to obtain the second image It;

[0007] Step S2: seal image segmentation: segmenting the first image I into a foreground image If and a background image Ib, and extracting a foreground contour from the foreground image If to obtain a foreground contour set Lc;

[0008] Step S3: adaptive brightness solution: according to the histogram of the background image Ib, calculate the adaptive brightness value Va that meets the brightness range of the background image Ib;

[0009] Step S4: Calculate the minimum circumscribed rectangular area of ​​the foreground contour; traverse each foreground contour in the foreground contour set Lc, calculate the minimum circumscribed rectangular area of ​​each foreground contour, and obtain the foreground contour minimum circumscribed rectangular area set Larea;

[0010] Step S5; Identification of seal image background interference: traverse each foreground contour minimum circumscribed rectangle area in the foreground contour minimum circumscribed rectangle area set Larea, count the number of foreground contours whose minimum circumscribed rectangle area is greater than the set area upper limit area_max, and obtain the number of extra-large contours count_oversize; traverse each foreground contour minimum circumscribed rectangle in the foreground contour minimum circumscribed rectangle set Lrect, calculate in turn the number of non-adaptive brightness range pixels total_hsv_p whose pixels in each foreground contour minimum circumscribed rectangle area are not within the adaptive brightness value Va range, count the number of foreground contours whose non-adaptive brightness range pixels total_hsv_p is greater than the set pixel number upper limit overhsv_max, and obtain the number of non-brightness range contours count_overhsv; based on the number of extra-large contours count_oversize and the number of non-brightness range contours count_overhsv, identify the seal image background interference.

[0011] Furthermore, in step S2, the first image I is segmented into a foreground image If and a background image Ib, and a foreground contour is extracted from the foreground image If to obtain a foreground contour set Lc. The specific steps are as follows:

[0012] Step S21, using a kernel kernel with a width of m and a height of n, performing c morphological erosion operations on the second image It to obtain a third image Ite, where c is the number of morphological erosion operations, and c>1;

[0013] Step S22, based on the first image I, copy the foreground image If and the background image Ib, use the third image Ite as a mask, traverse each pixel in the third image Ite, and let x ite represents the x coordinate of the pixel point in the third image Ite currently being traversed, let y iteRepresents the y - coordinate of the pixel point in the third image Ite that is currently being traversed. If the pixel value of the pixel at coordinates (x ite , y ite ) in the third image Ite is equal to 0, then set the pixel value of the pixel at coordinates (x ite , y ite ) in the foreground image If to 255; otherwise, set the pixel value of the pixel at coordinates (x ite , y ite ) in the background image Ib to 255;

[0014] Step S23: Use the contour detection algorithm to extract the foreground contour from the foreground image If to obtain the foreground contour set Lc.

[0015] Furthermore, in step S3, according to the histogram of the background image Ib, calculate the adaptive brightness value Va that conforms to the brightness interval of the background image Ib. The specific steps are as follows:

[0016] Step S31: Calculate the histogram hist of the background image Ib;

[0017] Step S32: According to the width width and height height of the first image I, use the following formula to calculate the total pixel area total_p of the first image I:

[0018] total_p = width × height;

[0019] Step S33: Set the lower limit min_index of the histogram subscript, set the upper limit max_index of the histogram subscript, select the data with subscripts in the interval [min_index:max_index] in the histogram hist to obtain the valid histogram valid_hist, and find the peak hist_peak and the corresponding peak subscript hist_peak_i in the valid histogram valid_hist;

[0020] Step S34: Set the lower limit peak_min of the peak, set the default value Va_default of the brightness value. If hist_peak < peak_min, then set the value of the adaptive brightness value Va to the default value Va_default of the brightness value and jump to step S4;

[0021] Step S35: Set the lower limit Va_min of the brightness value. If Va_min > hist_peak_i, then set the value of the adaptive brightness value Va to the lower limit Va_min of the brightness value; otherwise, set the value of the adaptive brightness value Va to the peak subscript hist_peak_i.

[0022] Furthermore, in step S4, each foreground contour in the foreground contour set Lc is traversed, and the minimum circumscribed rectangular area of ​​each foreground contour is calculated to obtain the foreground contour minimum circumscribed rectangular area set Larea, and the specific steps are as follows:

[0023] Step S41, setting the area lower limit area_min, and setting the first variable i; the initial value of the first variable i is set to 1;

[0024] Step S42, taking the i-th foreground contour contour from the foreground contour set Lc i , where i is the first variable i, solve for the foreground contour contour i The minimum enclosing rectangle rect i , let rect h i Represents the minimum enclosing rectangle rect i The height of rect w i Represents the minimum enclosing rectangle rect i Width;

[0025] Step S43, according to the minimum enclosing rectangle rect i , use the following formula to calculate the area of ​​the minimum enclosing rectangle area i :

[0026] area i= rect h i ×rect w i ;

[0027] Step S44, if area i >area_min, the minimum enclosing rectangle rect i Add to the foreground contour minimum bounding rectangle set Lrect, and set the area of ​​the minimum bounding rectangle area i Add to the foreground contour minimum circumscribed rectangle area set Larea;

[0028] Step S45, increase the value of the first variable i by 1. If the first variable i is less than or equal to the number of elements in the foreground contour set Lc, go to step S42.

[0029] Further, in step S5, each foreground contour minimum circumscribed rectangular area in the foreground contour minimum circumscribed rectangular area set Larea is traversed, and the number of foreground contours whose minimum circumscribed rectangular area is greater than the set area upper limit area_max is counted to obtain the number of oversized contours count_oversize. The specific steps are as follows:

[0030] Step S511, setting the area upper limit area_max, setting the second variable j; setting the initial value of the oversized contour count_oversize to 0, and setting the initial value of the second variable j to 1;

[0031] Step S512: Take the jth minimum bounding rectangle area from the foreground contour minimum bounding rectangle area set Larea. j , where j is the second variable j;

[0032] Step S513, if area j >area_max, then increase the value of count_oversize, the number of oversized contours, by 1;

[0033] Step S514, increase the value of the second variable j by 1. If the second variable j is less than or equal to the number of elements in the foreground contour minimum circumscribed rectangular area set Larea, go to step S512.

[0034] Further, in step S5, each foreground contour minimum bounding rectangle in the foreground contour minimum bounding rectangle set Lrect is traversed, and the number of non-adaptive brightness range pixels total_hsv_p whose pixel points in each foreground contour minimum bounding rectangle area are not in the adaptive brightness value Va range is calculated in turn, and the number of foreground contours whose non-adaptive brightness range pixels total_hsv_p is greater than the set pixel number upper limit overhsv_max is counted to obtain the number of non-brightness range contours count_overhsv, and based on the number of extra-large contours count_oversize and the number of non-brightness range contours count_overhsv, the background interference of the seal image is identified, and the specific steps are as follows:

[0035] Step S5201, setting the number of non-brightness range contours count_overhsv, setting the upper limit of the number of pixels overhsv_max, setting the upper limit of the number of extra-large contours threshold_1, setting the upper limit of the number of non-brightness range contours threshold_2, and setting a third variable k; the initial value of the number of non-brightness range contours count_overhsv is set to 0, and the initial value of the third variable k is set to 1;

[0036] Step S5202: Take the kth minimum bounding rectangle rect from the foreground contour minimum bounding rectangle set Lrect k , where k is the third variable k, rect cx k Represents the minimum enclosing rectangle rect k The x coordinate of the geometric center point, let rect cyk Represents the minimum enclosing rectangle rect k The y coordinate of the geometric center point, let rect h k Represents the minimum enclosing rectangle rect k The height of rect w k Represents the minimum enclosing rectangle rect k The width of rect a k Represents the minimum enclosing rectangle rect k The angle with the horizontal direction;

[0037] Step S5203: Create a first mask of the same size as the first image I. k , where the first mask k The initial value of all pixels in is set to 0, according to the minimum enclosing rectangle rect k The rectangular area described by the first mask k In the minimum bounding rectangle rect k The geometric center coordinates are (rect cx k ,rect cy k ), minimum enclosing rectangle rect k The height of rect h k , the minimum enclosing rectangle rect k The width of rect w k , the minimum enclosing rectangle rect k The angle between the horizontal direction and the horizontal direction is rect a k The pixel values ​​in the area are set to 1, and the minimum bounding rectangle mask mask_rect of the kth contour is obtained. k , where k is the third variable k;

[0038] Step S5204: copy the fourth image Irect based on the first image I k , set the minimum bounding rectangle mask_rect k As a mask, traverse the minimum enclosing rectangle mask_rect k For each pixel in rect Represents the minimum enclosing rectangle mask mask_rect k The x coordinate of rect Represents the minimum enclosing rectangle mask mask_rect k The y coordinate of the minimum bounding rectangle mask mask_rectk The coordinates in (x rect ,y rect ) is equal to 0, and the fourth image Irect k The median coordinate is (x rect ,y rect )’s pixel value is set to 255;

[0039] Step S5205: convert the fourth image Irect k Convert to hue H, saturation S, brightness V color space to get the fifth image Irect_hsv k ;

[0040] Step S5206, set the lower limit of hue H h_lower, set the upper limit of hue H h_upper, set the lower limit of saturation S s_lower, set the upper limit of saturation S s_upper, set the lower limit of brightness V v_lower, and create an image that is the same as the fifth image Irect_hsv k A second mask of the same size hsv_mask k , where the second mask hsv_mask k The initial value of all pixels in is set to 1; let x hsv k Represents the fifth image Irect_hsv k The x coordinate of hsv k Represents five images Irect_hsv k The y coordinate of the fifth image Irect_hsv k The coordinates in (x hsv k, y hsv k ) is within the range of hue H lower limit h_lower to hue H upper limit h_upper, saturation range is within the range of saturation S lower limit s_lower to saturation S upper limit s_upper, and brightness range is within the range of brightness V lower limit v_lower to adaptive brightness value Va, then the second mask hsv_mask k The median coordinate is (x hsv k, y hsv k )’s pixel value is set to 0;

[0041] Step S5207, counting the second mask hsv_mask k The number of pixels with a pixel value of 1 in total_hsv_p k ;

[0042] Step S5208, if total_hsv_pk >overhsv_max, then increase the value of count_overhsv, the number of contours in the non-brightness range, by 1;

[0043] Step S5209, increase the value of the third variable k by 1. If the third variable k is less than or equal to the number of elements in the minimum circumscribed rectangle set Lrect of the foreground contour, go to step S5202;

[0044] Step S5210: If count_oversize>threshold_1 or count_overhsv>threshold_2, it is determined that the seal image contains background interference; otherwise, it is determined that the seal image does not contain background interference.

[0045] The beneficial effect of the present invention is: the present invention provides a method for identifying background interference of a seal image, firstly dividing the seal image into a foreground image and a background image, then calculating the brightness range of the background image, and finally making a comprehensive judgment based on the area ratio of each contour of the foreground image and the brightness difference between each contour of the foreground image and the background image, so as to accurately identify whether the seal image contains background interference. BRIEF DESCRIPTION OF THE DRAWINGS

[0046] The present invention will be further described in detail below in conjunction with the accompanying drawings and specific embodiments.

[0047] Figure 1 is a method flow chart of an embodiment of the present invention;

[0048] Figure 2 It is the second image It obtained in step S1 of the embodiment of the present invention. DETAILED DESCRIPTION

[0049] The specific implementation of the present invention will be further described in detail below in conjunction with the accompanying drawings in the embodiments of the present invention. It should be noted that the specific embodiment of the method for identifying background interference of a seal image according to the present invention is only used as an example and is not intended to limit the present invention.

[0050] This embodiment takes two seal images, namely a white background seal image and a gray background seal image, as examples to illustrate a seal image background interference recognition method proposed by the present invention. Figure 1 As shown in the method flow chart, the present invention adopts the following steps to identify whether there is background interference in the seal image:

[0051] Step S1: Seal image preprocessing: Read the first image I, grayscale and binarize the first image I to obtain the second image It, such as Figure 2 As shown;

[0052] The image binarization algorithm in the above steps is a common method for image binarization. For details, see Tensmeyer, Chris and Tony R. Martinez. "Historical Document Image Binarization: A Review." SN Computer Science 1, 2020.

[0053] Step S2: seal image segmentation: segmenting the first image I into a foreground image If and a background image Ib, and extracting a foreground contour from the foreground image If to obtain a foreground contour set Lc;

[0054] The contour detection algorithm in the above steps is a common method for contour detection in images. For details, see Algburi, Riyadh & Gao, Hong & Al-Huda, Zaid. (2022). A new synergy of singular spectrum analysis with a conscious algorithm to detect faults in industrial robotics. Neural Computing and Applications. 34.10.1007 / s00521-021-06848-0;

[0055] Step S3: adaptive brightness solution: according to the histogram of the background image Ib, calculate the adaptive brightness value Va that meets the brightness range of the background image Ib;

[0056] Step S4: Calculate the minimum circumscribed rectangular area of ​​the foreground contour; traverse each foreground contour in the foreground contour set Lc, calculate the minimum circumscribed rectangular area of ​​each foreground contour, and obtain the foreground contour minimum circumscribed rectangular area set Larea;

[0057] Step S5; Identification of seal image background interference: traverse each foreground contour minimum circumscribed rectangle area in the foreground contour minimum circumscribed rectangle area set Larea, count the number of foreground contours whose minimum circumscribed rectangle area is greater than the set area upper limit area_max, and obtain the number of extra-large contours count_oversize; traverse each foreground contour minimum circumscribed rectangle in the foreground contour minimum circumscribed rectangle set Lrect, calculate in turn the number of non-adaptive brightness range pixels total_hsv_p of each foreground contour minimum circumscribed rectangle area whose pixel points are not within the adaptive brightness value Va range, count the number of foreground contours whose non-adaptive brightness range pixels total_hsv_p is greater than the set pixel number upper limit overhsv_max, obtain the number of non-brightness range contours count_overhsv, and identify seal image background interference based on the number of extra-large contours count_oversize and the number of non-brightness range contours count_overhsv.

[0058] Furthermore, in step S2, the first image I is segmented into a foreground image If and a background image Ib, and a foreground contour is extracted from the foreground image If to obtain a foreground contour set Lc, and the specific steps are as follows:

[0059] Step S21, using a kernel kernel with a width of m=3 and a height of n=3, performing c=2 morphological erosion operations on the second image It to obtain a third image Ite, where c is the number of morphological erosion operations, and c>1;

[0060] The morphological processing algorithm in the above steps is a common method for image morphological processing. For details, see Kumaki T, Fujita T, Fujino T, et al. Morphological Methods in Image Processing for Embedded Processors[J]. Journal of Signal Processing, 2018, 22;

[0061] Step S22, based on the first image I, copy the foreground image If and the background image Ib, use the third image Ite as a mask, traverse each pixel in the third image Ite, and let x ite represents the x coordinate of the third image Ite, let y ite Represents the y coordinate of the third image Ite. If the coordinate in the third image Ite is (x ite ,y ite ) is equal to 0, and the pixel with coordinate (x ite ,y ite) Set the pixel value of the pixel to 255, otherwise set the pixel value of the pixel at the coordinate (x ite , y ite ) in the background image Ib to 255;

[0062] Step S23, use the contour detection algorithm to extract the foreground contour from the foreground image If to obtain the foreground contour set Lc.

[0063] The contour detection algorithm in the above steps is a common method for contour detection. See Kelm, Andre & Rao, Vijesh & Udo. (2019). Object Contour and Edge Detection with RefineContourNet. 10.1007 / 978 - 3 - 030 - 29888 - 3_20.

[0064] Furthermore, in step S3, according to the histogram of the background image Ib, calculate the adaptive brightness value Va that conforms to the brightness interval of the background image Ib. The specific steps are as follows:

[0065] Step S31, calculate the histogram hist of the background image Ib;

[0066] Step S32, according to the width width and height height of the first image I, use the following formula to calculate the total pixel area total_p of the first image I:

[0067] total_p = width × height

[0068] Step S33, set the lower limit min_index of the histogram subscript to 127, set the upper limit max_index of the histogram subscript to 250, select the data with subscripts in the interval [min_index:max_index] in the histogram hist to obtain the valid histogram valid_hist, and find the peak hist_peak and the corresponding peak subscript hist_peak_i in the valid histogram valid_hist;

[0069] Step S34, set the lower limit of the peak peak_min = total_p × 0.05, set the default brightness value Va_default = 127. If hist_peak < peak_min, then set the value of the adaptive brightness value Va to the default brightness value Va_default and jump to step S4;

[0070] Step S35, setting the lower limit of the brightness value Va_min=46, if Va_min>hist_peak_i, then the value of the adaptive brightness value Va is set to the lower limit of the brightness value Va_min, otherwise the value of the adaptive brightness value Va is set to the peak subscript hist_peak_i.

[0071] Furthermore, in step S4, each foreground contour in the foreground contour set Lc is traversed, and the minimum circumscribed rectangular area of ​​each foreground contour is calculated to obtain the foreground contour minimum circumscribed rectangular area set Larea, and the specific steps are as follows:

[0072] Step S41, setting the area lower limit area_min=total_p×0.002, setting the first variable i; the initial value of the first variable i is set to 1;

[0073] Step S42, taking the i-th foreground contour contour from the foreground contour set Lc i , where i is the first variable i, solve for the foreground contour contour i The minimum enclosing rectangle rect i , let rect h i Represents the minimum enclosing rectangle rect i The height of rect w i Represents the minimum enclosing rectangle rect i Width;

[0074] Step S43, according to the minimum enclosing rectangle rect i , use the following formula to calculate the area of ​​the minimum enclosing rectangle area i :

[0075] area i= rect h i ×rect w i

[0076] Step S44, if area i >area_min, the minimum enclosing rectangle rect i Add to the foreground contour minimum bounding rectangle set Lrect, and set the area of ​​the minimum bounding rectangle area i Add to the foreground contour minimum circumscribed rectangle area set Larea;

[0077] Step S45, increase the value of the first variable i by 1. If the first variable i is less than or equal to the number of elements in the foreground contour set Lc, go to step S42.

[0078] Further, in step S5, each foreground contour minimum circumscribed rectangular area in the foreground contour minimum circumscribed rectangular area set Larea is traversed, and the number of foreground contours whose minimum circumscribed rectangular area is greater than the set area upper limit area_max is counted to obtain the number of oversized contours count_oversize. The specific steps are as follows:

[0079] Step S511, set the area upper limit area_max = total_p × 0.1, set the second variable j; the initial value of the oversized contour count_oversize is set to 0, and the initial value of the second variable j is set to 1;

[0080] Step S512: Take the jth minimum bounding rectangle area from the foreground contour minimum bounding rectangle area set Larea. j , where j is the second variable j;

[0081] Step S513, if area j >area_max, then increase the value of count_oversize, the number of oversized contours, by 1;

[0082] Step S514, increase the value of the second variable j by 1. If the second variable j is less than or equal to the number of elements in the foreground contour minimum circumscribed rectangular area set Larea, go to step S512.

[0083] Further, in step S5, each foreground contour minimum bounding rectangle in the foreground contour minimum bounding rectangle set Lrect is traversed, and the number of non-adaptive brightness range pixels total_hsv_p whose pixels are not in the adaptive brightness value Va range in each foreground contour minimum bounding rectangle area is calculated in turn, and the number of foreground contours whose non-adaptive brightness range pixels total_hsv_p is greater than the set pixel number upper limit overhsv_max is counted to obtain the number of non-brightness range contours count_overhsv, and based on the number of extra-large contours count_oversize and the number of non-brightness range contours count_overhsv, the seal image background interference is identified, and the specific steps are as follows:

[0084] Step S5201, set the number of non-brightness range contours count_overhsv, set the upper limit of the number of pixels overhsv_max=total_p×0.01, set the upper limit of the number of extra-large contours threshold_1=2, set the upper limit of the number of non-brightness range contours threshold_2=1, and set the third variable k; the initial value of the number of non-brightness range contours count_overhsv is set to 0, and the initial value of the third variable k is set to 1;

[0085] Step S5202: Take the kth minimum bounding rectangle rect from the foreground contour minimum bounding rectangle set Lrect k , where k is the third variable k, rect cx k Represents the minimum enclosing rectangle rect k The x coordinate of the geometric center point, let rect cy k Represents the minimum enclosing rectangle rect k The y coordinate of the geometric center point, let rect h k Represents the minimum enclosing rectangle rect k The height of rect w k Represents the minimum enclosing rectangle rect k The width of rect a k Represents the minimum enclosing rectangle rect k The angle with the horizontal direction;

[0086] Step S5203: Create a first mask of the same size as the first image I. k , where the first mask k The initial value of all pixels in is set to 0, according to the minimum enclosing rectangle rect k The rectangular area described by the first mask k In the minimum bounding rectangle rect k The geometric center coordinates are (rect cx k ,rect cy k ), minimum enclosing rectangle rect k The height of rect h k , the minimum enclosing rectangle rect k The width of rect w k , the minimum enclosing rectangle rect k The angle between the horizontal direction and the horizontal direction is rect a k The pixel values ​​in the area are set to 1, and the minimum bounding rectangle mask mask_rect of the kth contour is obtained. k , where k is the third variable k;

[0087] Step S5204: copy the fourth image Irect based on the first image I k , set the minimum bounding rectangle mask_rectk As a mask, traverse the minimum enclosing rectangle mask_rect k For each pixel in rect Represents the minimum enclosing rectangle mask mask_rect k The x coordinate of rect Represents the minimum enclosing rectangle mask mask_rect k The y coordinate of the minimum bounding rectangle mask mask_rect k The coordinates in (x rect ,y rect ) is equal to 0, and the fourth image Irect k The median coordinate is (x rect ,y rect )’s pixel value is set to 255;

[0088] Step S5205: convert the fourth image Irect k Convert to hue H, saturation S, brightness V color space to get the fifth image Irect_hsv k ;

[0089] Step S5206, set the lower limit of hue H h_lower = 0, set the upper limit of hue H h_upper = 180, set the lower limit of saturation S s_lower = 0, set the upper limit of saturation S s_upper = 255, set the lower limit of brightness V v_lower = 0, and create an image with the fifth image Irect_hsv k A second mask of the same size hsv_mask k , where the second mask hsv_mask k The initial value of all pixels in is set to 1; let x hsv k Represents five images Irect_hsv k The x coordinate of hsv k Represents five images Irect_hsv k The y coordinate of the five images Irect_hsv k The coordinates in (x hsv k, y hsv k ) is within the range of hue H lower limit h_lower to hue H upper limit h_upper, saturation range is within the range of saturation S lower limit s_lower to saturation S upper limit s_upper, and brightness range is within the range of brightness V lower limit v_lower to adaptive brightness value Va, then the second mask hsv_mask k The median coordinate is (x hsvk, y hsv k )’s pixel value is set to 0;

[0090] Step S5207, counting the second mask hsv_mask k The number of pixels with a pixel value of 1 in total_hsv_p k ;

[0091] Step S5208, if total_hsv_p k >overhsv_max, then increase the value of count_overhsv, the number of contours in the non-brightness range, by 1;

[0092] Step S5209, increase the value of the third variable k by 1. If the third variable k is less than or equal to the number of elements in the minimum circumscribed rectangle set Lrect of the foreground contour, go to step S5202;

[0093] Step S5210: If count_oversize>threshold_1 or count_overhsv>threshold_2, it is determined that the seal image contains background interference; otherwise, it is determined that the seal image does not contain background interference.

[0094] The above description is a preferred embodiment of the present invention and is not intended to limit the present invention. Any equivalent or modification that does not deviate from the spirit disclosed in the present invention should be included in the scope of protection of the present invention.

Claims

1. A method for identifying background interference of a seal image, characterized in that: The steps are as follows: Step S1: preprocessing the seal image; reading the first image I, graying and binarizing the first image I to obtain the second image It; Step S2: Seal image segmentation; The first image I is divided into a foreground image If and a background image Ib, and a foreground contour is extracted from the foreground image If to obtain a foreground contour set Lc; Step S3; Adaptive brightness solution; According to the histogram of the background image Ib, an adaptive brightness value Va that conforms to the brightness interval of the background image Ib is calculated; Step S4: Calculate the minimum circumscribed rectangular area of ​​the foreground contour; traverse each foreground contour in the foreground contour set Lc, calculate the minimum circumscribed rectangular area of ​​each foreground contour, and obtain the foreground contour minimum circumscribed rectangular area set Larea; Step S5; Identification of seal image background interference: traverse each foreground contour minimum circumscribed rectangle area in the foreground contour minimum circumscribed rectangle area set Larea, count the number of foreground contours whose minimum circumscribed rectangle area is greater than the set area upper limit area_max, and obtain the number of extra-large contours count_oversize; traverse each foreground contour minimum circumscribed rectangle in the foreground contour minimum circumscribed rectangle set Lrect, calculate in turn the number of non-adaptive brightness range pixels total_hsv_p whose pixels in each foreground contour minimum circumscribed rectangle area are not within the adaptive brightness value Va range, count the number of foreground contours whose non-adaptive brightness range pixels total_hsv_p is greater than the set pixel number upper limit overhsv_max, and obtain the number of non-brightness range contours count_overhsv; based on the number of extra-large contours count_oversize and the number of non-brightness range contours count_overhsv, identify the seal image background interference.

2. The method for recognizing background interference of a seal image according to claim 1, characterized in that: In step S2, the first image I is divided into a foreground image If and a background image Ib, and a foreground contour is extracted from the foreground image If to obtain a foreground contour set Lc. The specific steps are as follows: Step S21, using a kernel kernel with a width of m and a height of n, performing c morphological erosion operations on the second image It to obtain a third image Ite, where c is the number of morphological erosion operations, and c>1; Step S22, based on the first image I, copy the foreground image If and the background image Ib, use the third image Ite as a mask, traverse each pixel in the third image Ite, and let x ite represents the x coordinate of the pixel point in the third image Ite currently being traversed, let y ite Indicates the y coordinate of the pixel point in the third image Ite currently being traversed. If the coordinate in the third image Ite is (x ite ,y ite ) is equal to 0, then the pixel with coordinate (x ite ,y ite ) is set to 255, otherwise the pixel with coordinate (x ite ,y ite )’s pixel value is set to 255; Step S23: using a contour detection algorithm, extracting foreground contours from the foreground image If to obtain a foreground contour set Lc.

3. A method for identifying background interference of a seal image according to claim 2, characterized in that: In step S3, based on the histogram of the background image Ib, the adaptive brightness value Va that meets the brightness range of the background image Ib is calculated. The specific steps are as follows: Step S31, calculating a histogram hist of the background image Ib; Step S32: Calculate the total pixel area total_p of the first image I according to the width width of the first image I and the height height of the first image I using the following formula: total_p = width × height; Step S33: Set the lower limit of the histogram subscript min_index, set the upper limit of the histogram subscript max_index, select the data in the histogram hist with subscripts in the interval [min_index:max_index] to obtain the valid histogram valid_hist, and find the peak hist_peak and the corresponding peak subscript hist_peak_i in the valid histogram valid_hist; Step S34: Set the lower limit of the peak peak_min, set the default value of the brightness value Va_default. If hist_peak < peak_min, set the value of the adaptive brightness value Va to the default brightness value Va_default, and jump to Step S4; Step S35: Set the lower limit of the brightness value Va_min. If Va_min > hist_peak_i, set the value of the adaptive brightness value Va to the lower limit of the brightness value Va_min, otherwise set the value of the adaptive brightness value Va to the peak subscript hist_peak_i.

4. The method for identifying background interference of a seal image according to claim 3, characterized in that: In Step S4, traverse each foreground contour in the foreground contour set Lc, calculate the area of the minimum bounding rectangle of each foreground contour to obtain the foreground contour minimum bounding rectangle area set Larea. The specific steps are as follows: Step S41: Set the area lower limit area_min, set the first variable i; the initial value of the first variable i is set to 1; Step S42, taking the i-th foreground contour contour from the foreground contour set Lc i , where i is the first variable i, solve for the foreground contour contour i The minimum enclosing rectangle rect i , let rect h i Represents the minimum enclosing rectangle rect i The height of rect w i Represents the minimum enclosing rectangle rect i Width; Step S43, according to the minimum enclosing rectangle rect i , use the following formula to calculate the area of ​​the minimum enclosing rectangle area i : area i= rect h i ×rect w i ; Step S44, if area i >area_min, the minimum enclosing rectangle rect i Add to the foreground contour minimum bounding rectangle set Lrect, and set the area of ​​the minimum bounding rectangle area i Add to the foreground contour minimum circumscribed rectangle area set Larea; Step S45: Increase the value of the first variable i by 1. If the first variable i is less than or equal to the number of elements in the foreground contour set Lc, go to Step S42.

5. A method for identifying background interference of a seal image according to claim 4, characterized in that: In Step S5, traverse each foreground contour minimum bounding rectangle area in the foreground contour minimum bounding rectangle area set Larea, count the number of foreground contours whose foreground contour minimum bounding rectangle area is greater than the set area upper limit area_max to obtain the number of extra-large contours count_oversize. The specific steps are as follows: Step S511: Set the area upper limit area_max, set the second variable j; the initial value of the number of extra-large contours count_oversize is set to 0, and the initial value of the second variable j is set to 1; Step S512: Take the jth minimum bounding rectangle area from the foreground contour minimum bounding rectangle area set Larea. j , where j is the second variable j; Step S513, if area j >area_max, then increase the value of count_oversize, the number of oversized contours, by 1; Step S514: Increase the value of the second variable j by 1. If the second variable j is less than or equal to the number of elements in the foreground contour minimum bounding rectangle area set Larea, go to Step S512.

6. A method for identifying background interference of a seal image according to claim 5, characterized in that: In step S5, each foreground contour minimum bounding rectangle in the foreground contour minimum bounding rectangle set Lrect is traversed, and the number of non-adaptive brightness range pixels total_hsv_p whose pixels are not in the adaptive brightness value Va range in each foreground contour minimum bounding rectangle area is calculated in turn, and the number of foreground contours whose non-adaptive brightness range pixels total_hsv_p is greater than the set pixel number upper limit overhsv_max is counted to obtain the number of non-brightness range contours count_overhsv, and based on the number of extra-large contours count_oversize and the number of non-brightness range contours count_overhsv, the background interference of the seal image is identified, and the specific steps are as follows: Step S5201, setting the number of non-brightness range contours count_overhsv, setting the upper limit of the number of pixels overhsv_max, setting the upper limit of the number of extra-large contours threshold_1, setting the upper limit of the number of non-brightness range contours threshold_2, and setting a third variable k; the initial value of the number of non-brightness range contours count_overhsv is set to 0, and the initial value of the third variable k is set to 1; Step S5202: Take the kth minimum bounding rectangle rect from the foreground contour minimum bounding rectangle set Lrect k , where k is the third variable k, rect cx k Represents the minimum enclosing rectangle rect k The x coordinate of the geometric center point, let rect cy k Represents the minimum enclosing rectangle rect k The y coordinate of the geometric center point, let rect h k Represents the minimum enclosing rectangle rect k The height of rect w k Represents the minimum enclosing rectangle rect k The width of rect a k Represents the minimum enclosing rectangle rect k The angle with the horizontal direction; Step S5203: Create a first mask of the same size as the first image I. k , where the first mask k The initial value of all pixels in is set to 0, and the minimum enclosing rectangle rect k The rectangular area described by the first mask k In the minimum bounding rectangle rect k The geometric center coordinates are (rect cx k ,rect cy k ), minimum enclosing rectangle rect k The height of rect h k , the minimum enclosing rectangle rect k The width of rect w k , the minimum enclosing rectangle rect k The angle between the horizontal direction and the horizontal direction is rect a k The pixel values ​​in the area are set to 1, and the minimum bounding rectangle mask mask_rect of the kth contour is obtained. k , where k is the third variable k; Step S5204: copy the fourth image Irect based on the first image I k , set the minimum bounding rectangle mask_rect k As a mask, traverse the minimum enclosing rectangle mask_rect k For each pixel in rect Represents the minimum enclosing rectangle mask mask_rect k The x coordinate of rect Represents the minimum enclosing rectangle mask mask_rect k The y coordinate of the minimum bounding rectangle mask mask_rect k The coordinates in (x rect ,y rect ) is equal to 0, and the fourth image Irect k The median coordinate is (x rect ,y rect )’s pixel value is set to 255; Step S5205: convert the fourth image Irect k Convert to hue H, saturation S, brightness V color space to get the fifth image Irect_hsv k ; Step S5206, set the lower limit of hue H h_lower, set the upper limit of hue H h_upper, set the lower limit of saturation S s_lower, set the upper limit of saturation S s_upper, set the lower limit of brightness V v_lower, and create an image that is the same as the fifth image Irect_hsv k A second mask of the same size hsv_mask k , where the second mask hsv_mask k The initial value of all pixels in is set to 1; let x hsv k Represents the fifth image Irect_hsv k The x coordinate of hsv k Represents five images Irect_hsv k The y coordinate of the fifth image Irect_hsv k The coordinates in (x hsv k, y hsv k ) is within the range of hue H lower limit h_lower to hue H upper limit h_upper, saturation range is within the range of saturation S lower limit s_lower to saturation S upper limit s_upper, and brightness range is within the range of brightness V lower limit v_lower to adaptive brightness value Va, then the second mask hsv_mask k The median coordinate is (x hsv k, y hsv k )’s pixel value is set to 0; Step S5207, counting the second mask hsv_mask k The number of pixels with a pixel value of 1 in total_hsv_p k ; Step S5208, if total_hsv_p k >overhsv_max, then increase the value of count_overhsv, the number of contours in the non-brightness range, by 1; Step S5209, increase the value of the third variable k by 1. If the third variable k is less than or equal to the number of elements in the minimum bounding rectangle set Lrect of the foreground contour, go to step S5202; Step S5210: If count_oversize>threshold_1 or count_overhsv>threshold_2, it is determined that the seal image contains background interference; otherwise, it is determined that the seal image does not contain background interference.

Citation Information

Patent Citations

  • A method and apparatus for identifying image background interference.

    CN109410169B