Machine vision-based color printed matter defect automatic detection system and method
Through Canny edge detection and subpixel recovery technology, combined with multi-scale Gaussian pyramid decomposition and edge refinement, the lack of organic integration of edge detection and regional feature analysis is solved, the accuracy and positioning capabilities of color print defect detection are improved, and a detailed detection report is generated.
Patent Information
- Application Number
- CN202510576899.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-05-06
- Publication Date
- 2025-08-15
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
In the prior art, there is a lack of organic integration between edge detection and region feature analysis, resulting in systematic deviations in the calculation of subpixel-level offsets, especially statistical distortion of pixel proportion in high-density edge regions, and geometric constraints of region amplification tracking are not considered when multiple subpixel edge offsets are superimposed, resulting in nonlinear cumulative errors.
The Canny edge detection algorithm is used combined with subpixel recovery technology to extract the edge pixel ratio through sub-region division tables, and the multi-scale Gaussian pyramid decomposition and edge refinement technology are used to optimize edge accuracy and generate detection reports based on defect threshold classification and boundary conditions.
The edge extraction accuracy and positioning capability of color print defect detection is improved, the edge positioning accuracy at the subpixel level is achieved, and a detailed detection report is generated.
Smart Images

Figure CN120495223A_ABST
Abstract
Description
Technical Field
[0001] The present invention relates to the technical field of computer vision, and in particular to a system and method for automatically detecting defects in color printed matter based on machine vision. Background Art
[0002] The intelligent transformation of printed product quality inspection has progressed from manual visual inspection to automated recognition. The current mainstream technology still adheres to the classic image processing paradigm, relying primarily on image grayscale preprocessing combined with classic edge detection algorithms and multi-channel color analysis to build defect discrimination models. Gradient threshold-based edge detection methods, with their ability to capture contours, play a key role in image feature extraction. Some inspection systems utilize color space conversion techniques to identify chromaticity deviations. With the development of multi-scale feature analysis technology, hierarchical image parsing methods are also being applied to complex texture processing, enhancing feature representation through spatial frequency separation.
[0003] However, existing methods still have some troubling problems: the most prominent is the lack of organic integration between edge detection and regional feature analysis. Specifically, when calculating sub-pixel offsets, the sub-region division features are not integrated into the calculation model, resulting in systematic deviations in defect assessments in high-density edge areas. Although sub-pixel recovery technology can improve the accuracy of single edge positioning, the offset calculation is based solely on local pixel gradient information and fails to establish an associated mapping with the pre-defined sub-region spatial distribution characteristics. This distorts the actual pixel ratio statistics of high-density edge areas such as fine text and dots in printed materials. When multiple sub-pixel edge offsets are superimposed within a sub-region, the geometric constraints of regional magnification tracking are not considered, resulting in nonlinear cumulative errors in the calculation of the total number of edge pixels. Summary of the Invention
[0004] In view of the above existing problems, the present invention is proposed.
[0005] Therefore, the present invention provides a method for automatically detecting defects in color printed products based on machine vision to solve the problem of lack of organic integration between edge detection and regional feature analysis.
[0006] In order to solve the above technical problems, the present invention provides the following technical solutions: In a first aspect, the present invention provides a method for automatic detection of defects in color printed products based on machine vision, which includes collecting printing data, wherein the printing data includes a color image and a sub-region division table; converting the color image into a grayscale image and applying Gaussian blur to obtain a smoothed grayscale image, generating a boundary-enhanced grayscale image through a Canny edge detection algorithm, calculating the offset of edge pixels using sub-pixel recovery, extracting the edge pixel ratio based on the sub-region division table, zooming in and tracking the edge-dense sub-region to obtain the total number of edge pixels, and analyzing the RGB color deviation at the same time; analyzing the multi-scale features of the boundary-enhanced grayscale image and optimizing the edge accuracy through multi-scale Gaussian pyramid decomposition and edge refinement technology; classifying the edge defects and color defects of each sub-region using a defect threshold, verifying the boundary consistency, and if inconsistent, backtracking the Canny edge detection algorithm and sub-pixel restoration to regenerate the boundary-enhanced grayscale image, calculating a comprehensive risk value to evaluate color printed product defects, and raising the risk level according to the boundary conditions to generate a detection report.
[0007] As a preferred embodiment of the method for automatic detection of color printed product defects based on machine vision according to the present invention, the Canny edge detection algorithm for obtaining a boundary-enhanced grayscale image comprises enhancing the boundary of the grayscale image through gradient calculation, non-maximum suppression, dual threshold detection, and weak edge neighborhood connection to generate a boundary-enhanced grayscale image. The method of calculating the offset of edge pixels using sub-pixel restoration comprises selecting edge pixels from the boundary enhanced grayscale image, obtaining the gradient direction based on the gradient magnitude image, extracting the gradient magnitudes of adjacent pixels in the gradient magnitude image, calculating the sub-pixel offset, and calculating the average offset of each sub-region. The gradient magnitude image is obtained based on the horizontal gradient and vertical gradient of each pixel in the smoothed grayscale image.
[0008] As a preferred embodiment of the method for automatically detecting defects in color printed products based on machine vision according to the present invention, the method of enlarging and tracking edge-dense subregions to obtain the total number of edge pixels comprises: identifying a subregion having an edge pixel ratio greater than an empirical threshold as an edge-dense subregion, locally enlarging the edge-dense subregion, reapplying the Canny edge detection algorithm to generate an enlarged boundary-enhanced grayscale image, and counting the number of edge pixels based on the enlarged boundary-enhanced grayscale image to obtain the total number of edge pixels; The RGB color deviation analysis refers to calculating the color deviation between the RGB mean value of the sub-region and the standard template based on the color image, and quantifying the color anomaly.
[0009] As a preferred solution of the method for automatic color print defect detection based on machine vision described in the present invention, the multi-scale Gaussian pyramid decomposition refers to performing layer-by-layer Gaussian blurring and downsampling processing on the boundary-enhanced grayscale image to generate image layers of different resolutions, output multi-layer multi-scale images, and record the edge distribution at different scales.
[0010] As a preferred solution of the automatic detection method of color printed defects based on machine vision described in the present invention, the edge refinement refers to applying a morphological refinement algorithm to the boundary enhanced grayscale image, removing redundant points in the edge pixels, and generating a refined boundary image with an edge width of a single pixel and maintaining a single connected domain.
[0011] As a preferred solution of the method for automatic detection of color printed defects based on machine vision described in the present invention, the method of using a defect threshold to classify edge defects and color defects in each sub-area refers to setting a defect threshold range based on the average offset and color deviation, classifying the defect characteristics of each sub-area, determining whether edge defects and color defects exist, generating a comprehensive risk value through risk assessment, and adjusting the risk level according to boundary conditions.
[0012] As a preferred solution of the automatic detection method of color printed defects based on machine vision described in the present invention, the backtracking of the Canny edge detection algorithm and sub-pixel recovery to regenerate the boundary-enhanced grayscale image means that when a boundary consistency anomaly is detected, the Canny edge detection algorithm and sub-pixel recovery are returned, the parameters are readjusted to generate a new boundary-enhanced grayscale image, the edge detection result is optimized, and the number of backtracking times is set. After the number of backtracking times is exceeded, it is marked as a difficult area.
[0013] In a second aspect, the present invention provides a color printed product defect automatic detection system based on machine vision, comprising: An acquisition module, configured to acquire printing data, wherein the printing data includes a color image and a sub-region division table; The extraction module converts the color image into a grayscale image and applies Gaussian blur to obtain a smoothed grayscale image. It then generates a boundary-enhanced grayscale image using the Canny edge detection algorithm. It calculates the offset of edge pixels using sub-pixel recovery, extracts the edge pixel ratio based on the sub-region partitioning table, zooms in on edge-dense sub-regions to obtain the total number of edge pixels, and analyzes RGB color deviation. An optimization module is used to analyze the multi-scale features of the boundary-enhanced grayscale image and optimize the edge accuracy through multi-scale Gaussian pyramid decomposition and edge refinement technology; The risk module is used to classify edge defects and color defects in each sub-area using defect thresholds, verify boundary consistency, and if inconsistent, backtrack the Canny edge detection algorithm and sub-pixel recovery to regenerate the boundary-enhanced grayscale image. It then calculates a comprehensive risk value to assess defects in color prints, adjusts the risk level based on boundary conditions, and generates an inspection report.
[0014] In a third aspect, the present invention provides a computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: when the computer program is executed by the processor, any step of the method for automatic detection of color printed product defects based on machine vision as described in the first aspect of the present invention is implemented.
[0015] In a fourth aspect, the present invention provides a computer-readable storage medium having a computer program stored thereon, wherein: when the computer program is executed by a processor, it implements any step of the method for automatic detection of color printed product defects based on machine vision as described in the first aspect of the present invention.
[0016] The beneficial effects of the present invention are as follows: the present invention improves the edge extraction accuracy and positioning capability of color print defect detection by combining the Canny edge detection algorithm with sub-pixel restoration; the Canny edge detection algorithm calculates the gradient amplitude and direction through the Sobel operator, removes redundant edges through non-maximum suppression, and classifies strong and weak edges and connects the edges through dual threshold detection, thereby realizing the extraction of clear and continuous boundary-enhanced images from high-noise grayscale images; on this basis, sub-pixel restoration calculates the sub-pixel offset by linearly interpolating the edge pixels along the gradient direction, thereby improving the edge positioning accuracy from the pixel level to the sub-pixel level. BRIEF DESCRIPTION OF THE DRAWINGS
[0017] In order to more clearly illustrate the technical solutions of the embodiments of the present invention, the following briefly introduces the drawings required for use in the description of the embodiments. Obviously, the drawings described below are only some embodiments of the present invention. For ordinary technicians in this field, other drawings can be obtained based on these drawings without paying any creative work.
[0018] Figure 1 This is a flow chart of the method for automatically detecting defects in color printed products based on machine vision in Example 1.
[0019] Figure 2 Schematic diagram of the automatic color print defect detection system based on machine vision in Example 1.
[0020] Figure 3 This is a schematic diagram of the sub-pixel restoration principle in Example 1.
[0021] Figure 4 This is a diagram of the multi-scale decomposition process in Example 1. DETAILED DESCRIPTION
[0022] In order to make the above-mentioned objects, features and advantages of the present invention more obvious and easy to understand, the specific embodiments of the present invention are described in detail below with reference to the accompanying drawings.
[0023] In the following description, many specific details are set forth to facilitate a full understanding of the present invention. However, the present invention may also be implemented in other ways different from those described herein. Those skilled in the art may make similar generalizations without violating the connotation of the present invention. Therefore, the present invention is not limited to the specific embodiments disclosed below.
[0024] Secondly, the term "one embodiment" or "embodiment" herein refers to a specific feature, structure, or characteristic that may be included in at least one implementation of the present invention. The phrase "in one embodiment" appearing in various places throughout this specification does not necessarily refer to the same embodiment, nor does it refer to a separate or selective embodiment that is mutually exclusive of other embodiments.
[0025] In this embodiment, refer to Figures 1 to 4 This embodiment provides a method for automatically detecting defects in color printed products based on machine vision, comprising the following steps: S1. Collect printing data.
[0026] Use industrial cameras to capture color images; During acquisition, the edge sharpness value of the color image is calculated using the Sobel operator to monitor the color image quality in real time; Apply Sobel convolution kernels in the horizontal and vertical directions. For example, the horizontal kernel is [-1, 0, 1; -2, 0, 2; -1, 0, 1] to calculate the horizontal gradient Gx, and the vertical kernel is [-1, -2, -1; 0, 0, 0; 1, 2, 1] to calculate the vertical gradient Gy. Both the vertical and horizontal kernels are standard Sobel kernels. Based on the horizontal gradient and vertical gradient, the gradient amplitude is calculated as follows: ; in, Indicates the grayscale change of the image in the vertical direction (ordinate); The average gradient amplitude of the entire color image is taken as the color image edge sharpness value. If the color image edge sharpness value is lower than the preset value of 50 (the preset value is based on the print quality standard), the production line is suspended and the operator is prompted to manually adjust the lens focal length of the industrial camera and re-collect the data.
[0027] After the color image acquisition is completed, the color image is divided into sub-regions according to the width of the color print; The number of sub-regions is calculated based on the width of the color print. For example, a color print with a width of 30 cm is divided into 15 sub-regions. Each sub-region is 128 pixels wide and 1080 pixels high, with an area of approximately 138,240 pixels. The color print is 20 cm wide and divided into 10 sub-areas. Each sub-area is 192 pixels wide and 1080 pixels high, with an area of approximately 207,360 pixels. The sub-region width is calculated by the formula: ; in, is the sub-region width, is the number of sub-regions, 1920 is the fixed total image width, and the resolution of the boundary-enhanced grayscale image is 1920×1080; Sub-areas are numbered from left to right and from top to bottom. For example, when the width of a color print is 30 cm, the sub-area coordinates are A1 to A15. The sub-area coordinates are A1 (0, 0, 128, 1080), A2 (128, 0, 256, 1080) to A15 (1792, 0, 1920, 1080). When the width of the color print is 20 cm, it is A1 to A10, and the sub-area coordinates are A1 (0, 0, 192, 1080), A2 (192, 0, 384, 1080) to A10 (1728, 0, 1920, 1080).
[0028] After the sub-region division is completed, the number, coordinates and numbers of the sub-regions are organized into a sub-region division table. The collected color image and the generated sub-region division table are directly packaged into a printing data packet. The printing data includes the color image and the sub-region division table. The color image is 1920×1080 pixels, RGB format, and records the color print information; the sub-region division table lists the number of sub-regions; The collected printing data packets are directly passed to the next step for boundary enhancement and preliminary defect feature extraction.
[0029] S2. Convert the color image to a grayscale image and apply Gaussian blur to obtain a smoothed grayscale image. Generate a boundary-enhanced grayscale image using the Canny edge detection algorithm. Calculate the offset of edge pixels using sub-pixel recovery. Extract the edge pixel ratio based on the sub-region partitioning table. Zoom in and track the edge-dense sub-region to obtain the total number of edge pixels. Analyze the RGB color deviation.
[0030] Furthermore, a printing data packet is received, the printing data packet including a color image and a sub-region division table; Convert the color image to a grayscale image and calculate the grayscale value. The conversion formula is: ; Among them, this formula is the ITU-R BT.601 standard, is the grayscale value, is red, is green, For blue, R, G, B ranges from 0 to 255; Based on the grayscale value formula, the grayscale value of each pixel in the color image is calculated to generate a grayscale image with a resolution of 1920×1080 pixels, a pixel depth of 8 bits, and a range of 0 to 255 (standardized range, 8-bit image).
[0031] Apply Gaussian blur to the grayscale image to remove noise and output a smoothed grayscale image; Specifically, Gaussian blur is based on a two-dimensional Gaussian function, using a 5×5 Gaussian kernel (empirical value), with the standard deviation σ set to 1, and the expression is: ; in, is the output value of the two-dimensional Gaussian function, which represents the two-dimensional coordinates The function value at , in image processing, Determines the contribution of each pixel position in the kernel to the center pixel. The larger the weight value, the greater the influence of the pixel position on the center pixel smoothing result. The smaller the weight value, the smaller the influence of the pixel position on the center pixel smoothing result. is the horizontal coordinate (abscissa), positive value is to the right, negative value is to the left, is the vertical coordinate (ordinate), positive values are upward and negative values are downward. It is about twice the value of pi (3.14159), which is about 6.28318. It is part of the normalization constant and ensures that the sum of the kernel weights is normalized. is the standard deviation of the Gaussian distribution, which indicates the width or dispersion of the distribution. Is a mathematical constant, approximately equal to 2.71828, and is the base of the exponential function. From the center of the core (0, 0) to the point The square of the Euclidean distance; Among them, in the 5×5 Gaussian kernel, and The value range of is: , each pixel of the grayscale image is convolved with a 5×5 Gaussian kernel to generate a smoothed grayscale image with a resolution of 1920×1080 pixels and a pixel value range of 0 to 255, which is in line with image processing conventions.
[0032] The Canny edge detection algorithm is used to enhance the boundary of the smoothed grayscale image, and the sub-pixel restoration is combined to improve the accuracy of the grayscale image. The details are as follows: Based on the horizontal gradient and vertical gradient, the gradient magnitude and gradient direction are calculated for each pixel to generate a gradient magnitude image with a resolution of 1920×1080 pixels; The gradient direction of each pixel in the gradient magnitude image is discretized into four categories: 0° (horizontal), 45° (diagonal), 90° (vertical), and 135° (diagonal).
[0033] Perform non-maximum suppression on the gradient magnitude image to remove redundant edge responses and generate a gradient image after non-maximum suppression; For each pixel in the gradient magnitude image, determine a pair of adjacent pixels to be compared based on the gradient direction of each pixel in the gradient magnitude image; for example, if the gradient direction of a pixel in the gradient magnitude image is 0°, compare the gradient magnitude of the currently processed pixel with the gradient magnitudes of its left and right adjacent pixels in the gradient magnitude image; if the gradient direction of a pixel in the gradient magnitude image is 45°, compare the gradient magnitude of the currently processed pixel with the gradient magnitudes of its upper right and lower left adjacent pixels in the gradient magnitude image; If the gradient magnitude of a pixel in the gradient magnitude image is greater than or equal to the gradient magnitudes of the two adjacent pixels, the gradient magnitude of the currently processed pixel in the gradient magnitude image is retained as the edge candidate point; if the gradient magnitude of the currently processed pixel in the gradient magnitude image is less than the gradient magnitude of any of the two adjacent pixels in the gradient magnitude image, the gradient magnitude of the currently processed pixel in the gradient magnitude image is set to 0, and the non-edge point is excluded; After the processing is completed, a non-maximum suppressed gradient image is generated, and only pixels with local maximum gradient values are retained as edge candidate points; Apply dual threshold detection to the gradient image after non-maximum suppression, setting the low threshold to 50 and the high threshold to 150 (the low and high thresholds are empirical values based on printed product defect detection and are parameters of the common Canny edge detection algorithm, ranging from 0 to 255 and adjustable); Classify the gradient magnitude of each pixel in the gradient image after non-maximum suppression: if the gradient magnitude is greater than 150, mark it as a strong edge pixel; if the gradient magnitude is less than 50, mark it as a non-edge pixel and set the gradient value to 0; if the gradient magnitude is between 50 and 150, mark it as a weak edge pixel and temporarily retain the gradient magnitude; Generate a preliminary edge image, mark strong edge pixels as confirmed edges, mark weak edge pixels for further processing, and exclude non-edge pixels; For each weak edge pixel in the preliminary edge image, check whether there is a strong edge pixel in the 8-neighborhood (i.e., the surrounding 8 pixel positions) of the currently processed weak edge pixel in the preliminary edge image; if so, mark the currently processed weak edge pixel in the preliminary edge image as an edge pixel; if not, mark it as a non-edge pixel and set the currently processed weak edge pixel to 0; All weak edge pixels in the preliminary edge image are traversed and connected to generate the final boundary-enhanced grayscale image with a resolution of 1920×1080 pixels and pixel values of 0 (indicating non-edge pixels) or 255 (confirmed edge pixels). Pixel values 0 and 255 are the standardized outputs of the Canny edge detection algorithm, representing a binary edge image, where 255 indicates a detected edge point and 0 indicates a non-edge area. The boundary-enhanced grayscale image records the edge information of the color print.
[0034] For edge pixels (255) in the boundary-enhanced grayscale image, the sub-pixel offset is calculated based on the gradient magnitude image as follows: Select edge pixels from the boundary-enhanced grayscale image. For example, in subregion A1 (0, 0, 128, 1080), an edge pixel is detected at coordinates (x=100, y=50) with a pixel value of 255. Obtaining the gradient direction of the edge pixel currently being processed in the boundary enhanced grayscale image from the gradient magnitude image; Extract the gradient magnitudes of adjacent pixels in the gradient magnitude image along the horizontal direction. For example, at x=99, the gradient magnitude is 10, at x=100, the gradient magnitude is 50, and at x=101, the gradient magnitude is 20 (this simulates the typical distribution near the edge of the gradient magnitude image. The gradient magnitude reflects the intensity of change in the grayscale image). Calculate the sub-pixel offset using the following formula: ; in, is the sub-pixel offset, is the current amplitude, is the previous value, is the latter value; For each sub-region, the sub-pixel offsets of all edge pixels (pixel value 255) in the boundary-enhanced grayscale image are counted, and the average offset is calculated and counted as the edge position accuracy feature of the sub-region. For example, assuming there are 27,648 edge pixels in A1 and the total offset is 5,529.6, the average offset is 5,529.6 ÷ 27,648 ≈ 0.2 pixels, which is used to determine edge positioning deviation in subsequent defect detection.
[0035] Based on the sub-region division table, the boundary enhanced grayscale image is divided into sub-regions to extract defect features. The specific steps are as follows: The number and coordinates of sub-regions are directly obtained from the sub-region division table. For example, when the width of a color print is 30 cm, there are 15 sub-regions with coordinates A1 (0, 0, 128, 1080) to A15 (1792, 0, 1920, 1080). Coordinates are attributes of the sub-region. Each coordinate corresponds to a specific sub-region (such as A1, A2, etc.) and is used to define the position and range of the sub-region in the image. When the color print is 20 cm wide, it has 10 sub-areas with coordinates A1 to A10; The edge pixel ratio is calculated for each sub-region. The number of pixel values 255 in the sub-region is counted and divided by the total number of pixels in the sub-region to obtain the edge pixel ratio. The edge pixel ratio is used as a preliminary defect feature to reflect the edge image intensity of each sub-region.
[0036] For sub-regions with an edge pixel ratio greater than 0.3 (0.3 is an empirical threshold indicating a sub-region with dense edges and defects in the boundary-enhanced grayscale image), sub-region enlargement tracking is performed as follows: The sub-region is locally enlarged by 2 times, for example, A1 is enlarged from 128×1080 pixels to 256×2160 pixels, and the Canny edge detection algorithm (low threshold 50, high threshold 150) is re-applied to the enlarged sub-region to generate an enlarged boundary-enhanced grayscale image; Based on the amplified boundary-enhanced grayscale image, the total number of pixel values 255 in the sub-region is calculated as the total number of edge pixels. For example, the total number of pixels in A1 after amplification is 256×2160=552960, and the number of pixel values 255 is counted as 27648, so the total number of edge pixels is 27648 pixels. The total number of edge pixels is used as the edge scale feature to reflect the scale of potential defects in the sub-region. A larger value indicates a larger edge area.
[0037] For each sub-region in the color image, extract the color features and compare them with the standard template as follows: Based on the original color image, calculate the RGB mean of all pixels in the sub-region. For example, the mean of A1 is R=150, G=120, B=100. Based on the comparison of the sub-region RGB mean value with the standard template (such as R=145, G=125, B=105, which are preset values derived from the industry standard for printed materials (such as ISO 12647-2)), the color deviation is calculated using the Euclidean distance formula, for example, The Euclidean distance formula is: ; in, is the color deviation, is the red mean of the sub-region, Standard template red value, is the green mean of the sub-region, is the green value of the standard template, is the blue mean of the sub-region, is the standard template blue value, is the sub-region mean, It is the default value of the standard template; Substituting this into the formula, we get the color deviation of A1: ; Color deviation is a quantitative color feature that reflects the degree of color abnormality in the sub-region image and is used in subsequent defect detection to determine whether the color deviates from expectations.
[0038] The edge pixel ratio, total number of edge pixels, color deviation and average offset of each sub-region are sorted into an edge and color feature table. The edge and color feature table contains the sub-region number and the corresponding feature value. The feature table records the specific quantitative values of the edge feature and color feature. After defect feature extraction is completed, the boundary-enhanced grayscale image and edge and color feature table are directly packaged as processing data. The processing data includes the boundary-enhanced grayscale image (1920×1080 pixels, single channel) and the edge and color feature table. The edge and color feature table lists the sub-region number and the corresponding feature value (edge pixel ratio, total number of edge pixels, color deviation and average offset).
[0039] S3. Through multi-scale Gaussian pyramid decomposition and edge refinement technology, the multi-scale features of the boundary enhanced grayscale image are analyzed and the edge accuracy is optimized.
[0040] Furthermore, the processed data is received and multi-scale Gaussian pyramid decomposition is applied to the edge-enhanced grayscale image to generate image layers of different resolutions and analyze the multi-scale characteristics of the edge, as follows: Starting from the boundary-enhanced grayscale image, Gaussian blur is applied layer by layer, and the previous layer multi-scale image is downsampled (i.e., the width and height (resolution) of the previous layer multi-scale image are reduced by half); Layer 0: 1920 × 1080 pixels (original edge-enhanced grayscale image); Layer 1: 960×540 pixels; Layer 2: 480×270 pixels; Layer 3: 240×135 pixels (stop here to avoid going too small); The output generates a 4-layer multi-scale image, with each layer having a pixel value of 0 or 255, recording the edge distribution at different scales. Through multi-scale decomposition, it captures multi-level information from coarse edges to subtle edges, improving the comprehensiveness of subsequent analysis.
[0041] For each layer of multi-scale image, the multi-scale edge strength of the sub-region is calculated to extract the cross-scale edge changes, as follows: According to the sub-region partitioning table (such as A1 (0, 0, 128, 1080)), the corresponding sub-region is determined in each layer of the multi-scale image. For example, A1 is 128×1080 in the 0th layer, 64×540 in the 1st layer, 32×270 in the 2nd layer, and 16×135 in the 3rd layer; For each layer sub-region, count the number of pixel values 255 and divide it by the total number of pixels in the current layer sub-region to obtain the multi-scale edge strength; Calculate the rate of change of edge strength of adjacent layers. The formula is: ; in, is the rate of change of edge strength of adjacent layers, which is used to quantify the sub-region from the first To The degree of change in the edge strength of the layer, For the The edge strength of a sub-region in the multi-scale image layer. A sub-region refers to a sub-region specifically selected in the k-th layer, such as A1, which represents the object currently being analyzed and has an edge strength of 600. For the The edge strength of the same sub-region in the k-th layer multi-scale image and the k-th layer multi-scale image. The same sub-region refers to the sub-region with the same position and range as A1 in the k-th layer. It is still A1, which means the same region corresponding to the cross-layer. The edge strength is 500. Indicates the number of layers of the multi-scale image, which is an integer index; For example, the rate of change from layer 1 to layer 0 of A1 is: ; The rate of change from layer 2 to layer 1 is: ; The output generates a multi-scale edge feature table, which records the multi-scale edge strength and change rate of each sub-region.
[0042] Apply the morphological thinning algorithm to the 0th layer boundary enhanced grayscale image to remove redundant points in the edge pixels and generate a thinned boundary image as follows: Using a 3×3 cross-shaped structure element, check the 8-neighborhood of each 255-pixel in the edge-enhanced grayscale image. If the refinement condition is met (i.e., the number of 255 pixels in the 8-neighborhood is ≥3 and the remaining 255 pixels after removal maintain a single 8-connected domain), then set the 255 pixel to 0. If neither condition is met (i.e., the number of 255 pixels in the 8-neighborhood is <3 or the 255 pixels after removal split into multiple connected domains), then keep the 255 pixel unchanged. The template of the 3×3 cross-shaped structural element is [0 1 0]; [1 1 1]; [0 1 0], where 1 represents the center and the top, bottom, left, and right, and the rest are 0; An 8-connected domain refers to the 8 adjacent locations around a pixel (up, down, left, right, upper left, upper right, lower left, and lower right). A connected domain refers to a group of pixels in an edge-enhanced grayscale image whose values are all 255 and are interconnected through adjacency relationships (e.g., an 8-neighborhood). The final output is a refined boundary image with a resolution of 1920×1080 pixels, pixel values of 0 or 255, and edge width reduced from multiple pixels to single pixel while maintaining an uninterrupted single connected domain.
[0043] Compare the refined boundary image with the multi-scale image to check edge consistency. Specifically, recalculate the sub-region edge strength of the refined boundary image. Compare the refined boundary image with the multi-scale edge feature table and calculate the deviation (i.e., the absolute difference between the two). If the intensity deviation of a sub-region in any layer of the multi-scale image is greater than 0.1 (which is an empirical threshold in the field of image processing and is set to 0.1), it is marked as a sub-region to be adjusted. For example, the deviation between the refined boundary image intensity of 0.199 in the A1 sub-region and the third-layer multi-scale image intensity of 0.21 in the multi-scale edge feature table is 0.011 (calculated as |0.199-0.21|), which is less than the empirical threshold of 0.1 and is considered consistent; the deviation between the refined boundary image intensity of 0.06 in the A2 sub-region and the second-layer multi-scale image intensity of 0.21 in the multi-scale edge feature table is 0.15 (calculated as |0.06-0.21|), which is greater than the empirical threshold of 0.1 and is considered too large and marked as a sub-region to be adjusted.
[0044] If there is a sub-region to be adjusted (e.g., the deviation of the second layer of A2 is 0.15), an adjustment request is generated, including the sub-region number and recommended parameters (e.g., lowering the lower threshold of the Canny edge detection algorithm to 40). The Canny edge detection algorithm and sub-pixel restoration steps are then returned to regenerate the boundary-enhanced grayscale image. For the refined boundary image, the edge pixel ratio, total number of edge pixels and average offset are recalculated and directly integrated with the multi-scale edge intensity and change rate to generate an intermediate feature dataset. Among them, the edge pixel ratio, total number of edge pixels, average offset, multi-scale edge intensity and change rate are all numerical values, so they can be directly integrated.
[0045] Calculate the edge pixel ratio of the refined boundary image, for example, the A1 edge pixel ratio, and the expression is: ; Perform zoom tracking on sub-regions with edge pixel ratios greater than 0.3 (enlarge to 256×2160 pixels and reapply the Canny edge detection algorithm) and calculate the total number of edge pixels. For example, if the edge pixel ratio of A1 is greater than 0.3, the total number may be 27,400 after triggering zoom tracking; The actual A1 edge pixel ratio is expressed as: ; Through calculation, the actual edge pixel ratio does not reach 0.3, and the zoom tracking is not triggered. Therefore, the total number of edge pixels is 27,500; Calculate the average offset of the refined boundary image and the gradient magnitude image, for example, A1 is 0.19; Based on the intermediate feature dataset, we further integrate the color deviation, multi-scale edge intensity, and the rate of change of edge intensity of adjacent layers to generate a comprehensive feature table. If there is no sub-region to be adjusted, the refined boundary image and the comprehensive feature table are packaged as refined data and passed to the next step; if there is a sub-region to be adjusted, a feedback request is generated and returned to the previous step.
[0046] S4. Use the defect threshold to classify the edge defects and color defects of each sub-region, verify the boundary consistency, and if inconsistent, backtrack the Canny edge detection algorithm and sub-pixel recovery to regenerate the boundary enhanced grayscale image, calculate the comprehensive risk value to evaluate the defects of color prints, and increase the risk level according to the boundary conditions to generate a test report.
[0047] Furthermore, the refined data is received and the average offset and color deviation of each sub-region are extracted; Set defect thresholds based on average offset and color deviation; When the average offset of the sub-region is less than 0.3 pixels, it is judged as having no edge defect; When the average offset of the sub-region is between 0.3 and 0.6 pixels, it is determined to be an edge defect; When the average offset of the sub-region is greater than 0.6 pixels, it is judged as a serious edge defect; When the color deviation of the sub-area is less than 10, it is judged as having no color defect; When the color deviation of a sub-area is between 10-20, it is determined to be a color defect; When the color deviation of a sub-area is greater than 20, it is judged as a serious color defect; For each sub-region of the refined boundary image, the defect boundary coordinates are extracted using the boundary tracing algorithm. Starting from the first 255 pixels, the 8-neighborhood is searched for 255 consecutive pixels clockwise and the defect boundary coordinates are recorded. Calculate the boundary length and shape based on the defect boundary coordinates; Verify that the boundary length and shape are consistent with the average offset and color deviation of the comprehensive feature table. The defect threshold verification is as follows: if the average offset is <0.3 pixels and the color deviation is <10 (minor defect), the expected boundary length is <10 pixels and the boundary shape is simple (straight line or simple curve); if the average offset is ≥0.3 pixels or the color deviation is ≥10 (more obvious defect), the boundary length is ≥10 pixels or the boundary shape is complex (multi-fold curve). If they are consistent, a preliminary defect classification table is generated, which includes the defect type (e.g., A1 has no edge defects and no color defects), location (e.g., x=100, y=50, determined by the sub-region center coordinates), quantitative value (e.g., average offset 0.19, color deviation 8.66), and boundary information (e.g., boundary length 7 pixels, boundary shape is curved); Perform a risk assessment on the sub-areas of the preliminary defect classification table as follows: Set the level threshold based on the average offset and color deviation; The edge defect grade is assessed as follows: if the average deviation is <0.3, it is a minor defect; if the average deviation is between 0.3-0.6, it is a moderate defect; if the average deviation is >0.6, it is a severe defect; The color defect level is assessed as follows: if the color deviation is less than 10, it is a minor defect; if the color deviation is between 10-20, it is a moderate defect; if the color deviation is greater than 20, it is a severe defect; Based on the edge defect level and color defect level, a comprehensive risk value is generated, and the formula is: ; in is the marginal defect grade value (no defect = 0, slight risk = 1, medium risk = 2, severe risk = 3), is the color defect grade value (no defect = 0, slight = 1, medium = 2, severe = 3); example: A1 =0, indicating no edge defects, =0 means there is no color defect, and the formula is: ; If the color deviation of A1 is 10 (belonging to the color defect level assessment range of 10-20, corresponding to a medium color defect, the color defect level value =2), and substitute the formula into: ; Through calculation, it can be seen that <1, judged as slight risk; If the boundary length is greater than 10 pixels or the boundary shape is complex (e.g., multi-fold curve), the risk level is raised by one level, i.e., the comprehensive risk value (based on For example, if the A1 boundary length is 15 pixels and the comprehensive risk value is a slight risk, it will be a medium risk after the adjustment. If the sub-region has no edge defects (average offset < 0.3 pixels), no color defects (color deviation < 10), and no boundary anomalies, it is marked as normal; If a sub-region has an abnormal boundary (the boundary length or boundary shape is inconsistent with the expected average offset and color deviation), the Canny edge detection algorithm and sub-pixel restoration are used to regenerate the boundary-enhanced grayscale image. If the verification fails after more than two backtrackings, it is marked as a difficult area and awaits manual re-inspection; Integrate all sub-area results to generate an inspection report that lists defect type, location, quantitative value, boundary information, and risk level.
[0048] This embodiment further provides a color printed product defect automatic detection system based on machine vision, comprising: An acquisition module, used for acquiring printing data, the printing data including a color image and a sub-region division table; The extraction module converts the color image into a grayscale image and applies Gaussian blur to obtain a smoothed grayscale image. It then generates a boundary-enhanced grayscale image using the Canny edge detection algorithm. It calculates the offset of edge pixels using sub-pixel recovery, extracts the edge pixel ratio based on the sub-region partitioning table, zooms in on edge-dense sub-regions to obtain the total number of edge pixels, and analyzes RGB color deviation. An optimization module is used to analyze the multi-scale features of the boundary-enhanced grayscale image and optimize the edge accuracy through multi-scale Gaussian pyramid decomposition and edge refinement technology; The risk module is used to classify edge defects and color defects in each sub-area using defect thresholds, verify boundary consistency, and if inconsistent, backtrack the Canny edge detection algorithm and sub-pixel recovery to regenerate the boundary-enhanced grayscale image. It then calculates a comprehensive risk value to assess defects in color prints, adjusts the risk level based on boundary conditions, and generates an inspection report.
[0049] This embodiment also provides a computer device, which is suitable for the case of an automatic detection method for color printed defects based on machine vision, including: a memory and a processor; the memory is used to store computer-executable instructions, and the processor is used to execute computer-executable instructions to implement the automatic detection method for color printed defects based on machine vision proposed in the above embodiment.
[0050] The computer device may be a terminal, comprising a processor, memory, a communication interface, a display, and an input device connected via a system bus. The processor provides computing and control capabilities. The memory includes non-volatile storage media and internal memory. The non-volatile storage media stores an operating system and computer programs. The internal memory provides an environment for the operating system and computer programs stored in the non-volatile storage media. The communication interface of the computer device is used to communicate with external terminals via wired or wireless communication. Wireless communication may be achieved via Wi-Fi, a carrier network, NFC (near-field communication), or other technologies. The display of the computer device may be a liquid crystal display or an electronic ink display. The input device may be a touchscreen overlay on the display, buttons, a trackball, or a touchpad on the computer device housing, or an external keyboard, touchpad, or mouse.
[0051] This embodiment further provides a storage medium having a computer program stored thereon. When the program is executed by a processor, the program implements the method for automatically detecting color printed product defects based on machine vision as proposed in the above embodiment. The storage medium can be implemented by any type of volatile or non-volatile storage device or a combination thereof, such as static random access memory (SRAM), electrically erasable programmable read-only memory (EEPROM), erasable programmable read-only memory (EPROM), programmable read-only memory (PROM), read-only memory (ROM), magnetic storage, flash memory, magnetic disk, or optical disk.
[0052] In summary, the present invention improves the edge extraction accuracy and positioning capability of color print defect detection by combining the Canny edge detection algorithm with sub-pixel restoration. The Canny edge detection algorithm calculates the gradient amplitude and direction through the Sobel operator, removes redundant edges through non-maximum suppression, and classifies strong and weak edges and connects the edges through dual threshold detection, thereby realizing the extraction of clear and continuous boundary-enhanced images from high-noise grayscale images. On this basis, sub-pixel restoration improves the edge positioning accuracy from the pixel level to the sub-pixel level by linearly interpolating the edge pixels along the gradient direction and calculating the sub-pixel offset.
[0053] It should be noted that the above embodiments are only used to illustrate the technical solutions of the present invention and are not intended to limit the present invention. Although the present invention has been described in detail with reference to the preferred embodiments, those skilled in the art should understand that the technical solutions of the present invention may be modified or replaced by equivalents without departing from the spirit and scope of the technical solutions of the present invention, which should all be included in the scope of the claims of the present invention.
Claims
1. A method for automatically detecting defects in color printed products based on machine vision, characterized by: include, Collecting printing data, wherein the printing data includes a color image and a sub-region division table; The color image is converted to a grayscale image and Gaussian blur is applied to obtain a smoothed grayscale image. The Canny edge detection algorithm is used to generate a boundary-enhanced grayscale image. Sub-pixel recovery is used to calculate the offset of edge pixels. The edge pixel ratio is extracted based on the sub-region partitioning table. The edge-dense sub-region is zoomed in and tracked to obtain the total number of edge pixels. The RGB color deviation is also analyzed. Through multi-scale Gaussian pyramid decomposition and edge refinement technology, the multi-scale features of the boundary-enhanced grayscale image are analyzed and the edge accuracy is optimized; Defect thresholds are used to classify edge defects and color defects in each sub-area, and boundary consistency is verified. If there is inconsistency, the Canny edge detection algorithm and sub-pixel recovery are backtracked to regenerate the boundary-enhanced grayscale image. The comprehensive risk value is calculated to evaluate color print defects, and the risk level is increased according to the boundary conditions to generate an inspection report.
2. The method for automatically detecting defects in color printed matter based on machine vision according to claim 1, wherein: The Canny edge detection algorithm obtains a boundary-enhanced grayscale image by enhancing the boundary of the grayscale image through gradient calculation, non-maximum suppression, double threshold detection and weak edge neighborhood connection to generate a boundary-enhanced grayscale image; The method of calculating the offset of edge pixels using sub-pixel restoration comprises selecting edge pixels from the boundary enhanced grayscale image, obtaining the gradient direction based on the gradient magnitude image, extracting the gradient magnitudes of adjacent pixels in the gradient magnitude image, calculating the sub-pixel offset, and calculating the average offset of each sub-region. The gradient magnitude image is obtained based on the horizontal gradient and vertical gradient of each pixel in the smoothed grayscale image.
3. The method for automatically detecting defects in color printed matter based on machine vision according to claim 1, wherein: The method of enlarging and tracking the edge-dense sub-region to obtain the total number of edge pixels is to identify a sub-region with an edge pixel ratio greater than an empirical threshold as an edge-dense sub-region, locally enlarge the edge-dense sub-region, re-apply the Canny edge detection algorithm to generate an enlarged boundary-enhanced grayscale image, and count the number of edge pixels based on the enlarged boundary-enhanced grayscale image as the total number of edge pixels; The RGB color deviation analysis refers to calculating the color deviation between the RGB mean value of the sub-region and the standard template based on the color image, and quantifying the color anomaly.
4. The method for automatically detecting defects in color printed matter based on machine vision according to claim 1, wherein: The multi-scale Gaussian pyramid decomposition refers to performing layer-by-layer Gaussian blurring and downsampling processing on the edge-enhanced grayscale image to generate image layers with different resolutions, output multi-layer multi-scale images, and record edge distribution at different scales.
5. The method for automatically detecting defects in color printed matter based on machine vision according to claim 1, wherein: The edge thinning refers to applying a morphological thinning algorithm to the boundary enhanced grayscale image to remove redundant points in the edge pixels and generate a thinned boundary image with an edge width of a single pixel and maintaining a single connected domain.
6. The method for automatically detecting defects in color printed matter based on machine vision according to claim 1, wherein: The method of using defect thresholds to classify edge defects and color defects in each sub-area refers to setting a defect threshold range based on the average offset and color deviation, classifying the defect characteristics of each sub-area, determining whether edge defects and color defects exist, generating a comprehensive risk value through risk assessment, and increasing the risk level based on boundary conditions.
7. The method for automatically detecting defects in color printed matter based on machine vision according to claim 1, wherein: The backtracking Canny edge detection algorithm and sub-pixel restoration to regenerate the boundary enhanced grayscale image means that when a boundary consistency anomaly is detected, the Canny edge detection algorithm and sub-pixel restoration are returned to, the parameters are readjusted to generate a new boundary enhanced grayscale image, the edge detection result is optimized, and the number of backtracking times is set. After the number of backtracking times is exceeded, it is marked as a difficult area.
8. A system for automatically detecting defects in color printed products based on machine vision, based on the method for automatically detecting defects in color printed products based on machine vision according to any one of claims 1 to 7, characterized in that: include, An acquisition module, configured to acquire printing data, wherein the printing data includes a color image and a sub-region division table; The extraction module converts the color image into a grayscale image and applies Gaussian blur to obtain a smoothed grayscale image. It then generates a boundary-enhanced grayscale image using the Canny edge detection algorithm. It calculates the offset of edge pixels using sub-pixel recovery, extracts the edge pixel ratio based on the sub-region partitioning table, zooms in on edge-dense sub-regions to obtain the total number of edge pixels, and analyzes RGB color deviation. An optimization module is used to analyze the multi-scale features of the boundary-enhanced grayscale image and optimize the edge accuracy through multi-scale Gaussian pyramid decomposition and edge refinement technology; The risk module is used to classify edge defects and color defects in each sub-area using defect thresholds, verify boundary consistency, and if inconsistent, backtrack the Canny edge detection algorithm and sub-pixel recovery to regenerate the boundary-enhanced grayscale image. It then calculates a comprehensive risk value to assess defects in color prints, adjusts the risk level based on boundary conditions, and generates an inspection report.
9. A computer device comprising a memory and a processor, wherein the memory stores a computer program, wherein: When the processor executes the computer program, the steps of the method for automatic detection of color printed product defects based on machine vision according to any one of claims 1 to 7 are implemented.
10. A computer-readable storage medium having a computer program stored thereon, characterized in that: When the computer program is executed by a processor, the steps of the method for automatic detection of color printed product defects based on machine vision according to any one of claims 1 to 7 are implemented.
Citation Information
Cited By
Cigarette paper steel seal printing position online deviation rectifying method and device and storage medium
CN121010587A
Machine vision-based color difference defect detection method for color presswork
CN121904012A
Visual detection method and system for printing defects and number of circular self-adhesive labels
CN122115489A
Method and system for visually detecting printing defects and quantity of round adhesive labels
CN122115489B