A gray code binarization method based on boundary line detection technology

CN118229970BActive Publication Date: 2026-10-16HARBIN INST OF TECH +1
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202410253359.3
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2024-03-06
Publication Date
2026-10-16
Estimated Expiration
2044-03-06

AI Technical Summary

Technical Problem

[0006]本发明目的在于克服现有格雷码图像二值化方法噪声多、对光照敏感、鲁棒性不强的不足,提出了一种基于边界线检测技术的格雷码二值化方法

Benefits of technology

[0033] Most existing Gray code binarization methods employ threshold-based approaches, which suffer from poor robustness and are highly sensitive to illumination and light sources. When ambient light changes drastically, the binarized image often exhibits significant noise. The method of this invention performs binarization by detecting the boundaries of the Gray code image, fully utilizing the semantic information within the image. It has fewer restrictions on ambient light, exhibits strong robustness and generalization, and produces a more accurate and noise-free binarized image.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN118229970B_ABST
    Figure CN118229970B_ABST
Patent Text Reader

Abstract

The application provides a Gray code binarization method based on a boundary line detection technology. The method first down-samples a photographed Gray code image along a code value transformation direction and detects edges of the down-sampled image by using a Canny operator; then performs connected domain analysis on the detected binarized edge image, removes regions with a connected area less than a certain threshold, and further designs a filter to remove false boundaries and noises; then maps the edges to the original image, calculates gradient values of the edge points at corresponding positions of the original image along a Gray code code value change direction, and selects positions with maximum gradient amplitude as boundary points; finally connects and completes the boundary lines, and assigns areas between the boundary lines with black and white colors in sequence to complete the binarization of the image. The method of the application performs binarization by detecting boundaries of a Gray code image, fully utilizes semantic information in the image, has relatively small requirements for environmental light, has relatively strong robustness and generalization, and the binarized image is more accurate and free of noises.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of automotive paint defect detection technology, and in particular to a Gray code binarization method based on boundary line detection technology. Background Technology

[0002] Phase deflection measurement is a method capable of detecting minute defects on the surface of an object. This method projects structured light onto the surface of the object, then acquires deformed fringes modulated by the surface. A computer unwraps the fringes to obtain an absolute phase map. By analyzing the absolute phase map, defects on the object's surface can be identified. This method is highly sensitive to defects in automotive paint, capable of detecting defects down to the sub-millimeter level.

[0003] Currently, phase unwrapping mainly falls into two categories: spatial phase expansion and temporal phase expansion. The latter offers higher accuracy, with the Gray code-level subphase shift method being the most representative. This method primarily involves two steps: first, projecting a set of sinusoidal phase shift maps; and second, decoding the phase shift maps to obtain the folded phase. The distribution map is obtained, and then a set of Gray code images is projected. The stripe series K(x,y) is obtained by binarizing and decoding the Gray code images. The two are then combined to obtain the absolute phase. Throughout the process, the folded phase is less affected by the environment, so the most critical factor affecting the absolute phase map is the binarization of the Gray code.

[0004] Current Gray code image binarization methods mostly employ thresholding, setting a threshold for the acquired Gray code image, classifying pixels below the threshold as black and pixels above the threshold as white. While this method is easy to implement, it suffers from poor robustness. In actual industrial production, ambient lighting inevitably fluctuates, causing the binarized image obtained by thresholding to often contain numerous noise points. The resulting absolute phase image is also prone to noise, interfering with subsequent defect detection and severely impacting the defect detection results.

[0005] In fact, Gray code image binarization can be viewed as a segmentation task, and more insights can be gained from the perspective of image segmentation. Existing image segmentation methods can be broadly categorized into threshold-based segmentation methods, region-based segmentation methods, and boundary-based segmentation methods. For thresholding methods, neither global nor local thresholding fully utilizes the semantic information between image regions; while region segmentation methods require enormous computational resources, which cannot meet the real-time requirements of industrial production. Considering that Gray code images modulated by automotive paint still possess strong boundary information, this invention develops a boundary line detection method from the perspective of boundary detection. This method detects the boundary lines (hereinafter referred to as boundary lines) where black and white regions of the Gray code image intersect, and then assigns black and white colors to the regions between the boundary lines to achieve Gray code image binarization. Compared with existing methods, the binarization effect of this invention is clearer, less affected by external environmental factors, and more robust. Summary of the Invention

[0006] The purpose of this invention is to overcome the shortcomings of existing Gray code image binarization methods, such as high noise levels, sensitivity to illumination, and poor robustness. A Gray code binarization method based on boundary line detection technology is proposed. This method yields clearer Gray code binarized images with higher robustness. This lays the foundation for obtaining a good absolute phase image, which is beneficial for improving the accuracy of paint surface defect detection.

[0007] This invention is achieved through the following technical solution: First, the captured Gray code image is downsampled along the code value transformation direction and the edges of the downsampled image are detected using the Canny operator; then, connected component analysis is performed on the detected binarized edge image to remove regions with connected areas less than a certain threshold; next, a filter is designed to remove false boundaries and noise; then, the current edge image is upsampled to the original image size, and edge points are accurately located to obtain boundary lines; finally, the boundary lines are connected and completed, and the regions between the boundary lines are sequentially assigned black and white colors to complete the binarization of the image.

[0008] Specifically, this invention proposes a Gray code binarization method based on boundary line detection technology, the method comprising the following steps:

[0009] S1: Downsample the captured Gray code image and use the Canny operator to detect image edges;

[0010] S2: The binarized image I obtained from S1 D_edge1 Perform connected component analysis and remove edge points whose connected component area is less than a threshold.

[0011] S3: Design a filter to remove pseudo-boundaries;

[0012] S4: Upsample the edge image to the original image size and accurately locate the edge points to obtain the boundary line;

[0013] S5: Connect and complete the boundary lines, and fill the areas between the boundary lines with black and white to complete the binarization.

[0014] Further, step S1 specifically includes:

[0015] S101: First, fill the original image. Let the size of the original image be M*N. Fill the top, bottom, left and right directions of the image with pixels of width p and gray value of 0, so that the image size is (M+2p)*(N+2p).

[0016] S102: Downsample the captured Gray code along the direction of code value change;

[0017] S103: Edge detection is performed on the downsampled image using the Canny operator. Detected edges are represented by white pixels, and other points are represented by black pixels, resulting in a binarized edge image I. D_edge1 The set of pixels representing edges is represented as E = {(x,y)|I}. D_edge1 (x,y)=255}.

[0018] Furthermore, the downsampling principle is as follows: Where I and I D Let (k,j) and (l,j) represent the original Gray code image and the downsampled Gray code image, respectively. Let (k,j) and (l,j) represent the pixel coordinates of any point in the original image and the corresponding pixel coordinates after sampling, respectively. Let p indicate that the downsampling step size is odd, and the size of the sampled image is [value missing].

[0019] Further, in step S2, the number and area of ​​connected components formed by edge points are obtained using OpenCV's connectedComponentsWithStats function. Each connected component is traversed, and connected regions with areas less than the threshold area_threshold are filtered out to obtain I. D_edge2 .

[0020] Further, step S3 specifically includes:

[0021] S301: For I D_edge2 Any white edge point I D_edge2 (x0,y0) represents the coordinates of any edge point in the image. Taking this point as the center, count the number of edge points in its left and right neighborhoods. If all of them are less than the threshold edge_threshold, then the point is considered a pseudo-boundary point and is set to black. Otherwise, the point is considered a boundary point and remains unchanged.

[0022] S302: Decrease the neighborhood length i, and repeat S301 one or two times until all pseudo-edges are eliminated, to obtain a new edge image I D_edge3 .

[0023] Further, the left and right neighborhoods are defined as follows: for any edge point I D_edge2 (x0,y0), the left neighborhood is defined as I region_left (u,v)={I(u,v)|x0-i≤u<x0,y0-1≤v≤y0+1}, and the right neighborhood is defined as I region_right (u,v)={I(u,v)|x0≤u<x0+i,y0-1≤v≤y0+1}, where (u,v) represents the coordinates in the left and right neighborhoods, (x0,y0) represents any edge point, and i represents the neighborhood length; the numbers of edge points in the left and right neighborhoods are counted respectively as EdgeCount_left and EdgeCount_right, then for each point on the image I D_edge2 , the gray value

[0024] Further, the step S4 is specifically as follows:

[0025] S401: Upsample the edge points in the current edge image I D_edge3 to the corresponding positions in the original image; first create a pure black image with the size of the original padded image of (M+2p)*(N+2p), then obtain the coordinates (x,y) of the edge points in I D_edge3 , keep the abscissa of the edge points unchanged, multiply the ordinate by p, where p is the downsampling step size, to obtain the corresponding positions (x,py) of the edge points in the original image, and set them to white, so as to obtain the edge point image I of size (M+2p)*(N+2p) edge ;

[0026] S402: Perform precise positioning of boundary points; through the above steps, the boundary points are positioned within p pixels centered on each edge point in the direction of image code value change; let the coordinates of any edge point be I edge (x0,y0), and in the direction of image code value change, use the gradient operator (1,0,-1) T to calculate the gradient Gy of the original Gray code image I in the to interval, let the point with the maximum amplitude be I(x m ,y m ), then I(x m ,y m ) is the precisely positioned boundary point, the straight line formed by connecting several boundary points is the boundary line to be detected, and the boundary image I is composed of several boundary lines boundary .

[0027] Further, step S5 specifically includes:

[0028] S501: I boundary The boundary lines in the code may be discontinuous and need to be connected and completed; first, find the discontinuity, and then... boundary Iterate through all boundary points, and let any boundary point I... boundary (x0, y0), detect its left side I boundary (x0-1, y0-2) to I boundary For a pixel (x0-1, y0+2), if there is no white boundary point, it indicates a discontinuity at that pixel. Find the nearest boundary point on the left and use the Bresenham algorithm to connect the current pixel to its nearest boundary point to complete the connection. The same method applies to the right side. The step of finding the distance I... boundary The method for finding the nearest boundary point (x0, y0) is as follows: Search for boundary points within a K*K square centered at the x0 point, incrementing K by 1 from 3 until a new boundary point I is found on either the left or right side. boundary (x i ,y i If the new boundary points are not unique, calculate the Euclidean distance from each boundary point to the new boundary point. By taking the boundary point corresponding to the minimum value of d as the connection point, a new boundary image I' is finally obtained. boundary ;

[0029] S502: Fill the area between the boundary lines with black and white to complete binarization; binarize I' in a top-down, left-to-right order. boundary Iterate through all pixels to find the first boundary point I'. boundary Detect I' downwards in sequence boundary (x0, y0 + h)h = 1, 2, 3, ... until the first boundary point I' is detected. boundary (x0, y1), using the detection methods described in S2 and S3, determine whether this pixel is a true boundary point. If it is, then set I' boundary (x0,y0) to I' boundary All pixels between (x0, y1) are set to either black or white; otherwise, the process continues traversing downwards. boundary (x0,y h ) and I' boundary (x0,y h+1 The color between (h+1)%2))*255 is calculated as ((h+1)%2))*255. If the result is 255, it is white; if it is 0, it is black.

[0030] This invention proposes an electronic device, including a memory and a processor. The memory stores a computer program, and the processor executes the computer program to implement the steps of the Gray code binarization method based on boundary line detection technology.

[0031] This invention proposes a computer-readable storage medium for storing computer instructions, which, when executed by a processor, implement the steps of the Gray code binarization method based on boundary line detection technology.

[0032] Compared with the prior art, the present invention has the following advantages:

[0033] Most existing Gray code binarization methods employ threshold-based approaches, which suffer from poor robustness and are highly sensitive to illumination and light sources. When ambient light changes drastically, the binarized image often exhibits significant noise. The method of this invention performs binarization by detecting the boundaries of the Gray code image, fully utilizing the semantic information within the image. It has fewer restrictions on ambient light, exhibits strong robustness and generalization, and produces a more accurate and noise-free binarized image.

[0034] In summary, this invention provides a robust method for Gray code binarization of projections onto automotive paint surfaces, laying the foundation for obtaining a good absolute phase map, thereby improving the accuracy of paint surface defect detection. This invention can be applied to various structured light measurement fields, including but not limited to structured light 3D reconstruction and high-reflectivity object surface defect detection, helping to improve reconstruction accuracy and detection accuracy. Attached Figure Description

[0035] To more clearly illustrate the technical solutions in the embodiments of the present invention or the prior art, the drawings used in the description of the embodiments or the prior art will be briefly introduced below. Obviously, the drawings described below are only embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on the provided drawings without creative effort.

[0036] Figure 1 This is a flowchart of the Gray code binarization method based on boundary enhancement detection technology.

[0037] Figure 2 A physical diagram of a system for acquiring Gray code images of car paint reflections.

[0038] Figure 3 The image shows the original Gray code image.

[0039] Figure 4 The image shows the Gray code after downsampling in the height direction and the boundary image after boundary extraction.

[0040] Figure 5 This is a boundary image after connected component analysis and filtering to remove noise and false boundaries.

[0041] Figure 6 This is the boundary image after sampling to the original image size and accurately locating it on the boundary.

[0042] Figure 7 This is the final image of the Gray code binarization.

[0043] Figure 8 This is the image of the result of thresholding binarization. Detailed Implementation

[0044] The technical solutions of the embodiments of the present invention will be clearly and completely described below with reference to the accompanying drawings. Obviously, the described embodiments are only some embodiments of the present invention, and not all embodiments. Based on the embodiments of the present invention, all other embodiments obtained by those skilled in the art without creative effort are within the scope of protection of the present invention.

[0045] This invention proposes a Gray code binarization method based on boundary line detection technology, the method comprising the following steps:

[0046] S1: Downsample the captured Gray code image and use the Canny operator to detect image edges;

[0047] S2: The binarized image I obtained from S1 D_edge1 Perform connected component analysis and remove edge points whose connected component area is less than a threshold.

[0048] S3: Design a filter to remove pseudo-boundaries;

[0049] S4: Upsample the edge image to the original image size and accurately locate the edge points to obtain the boundary line;

[0050] S5: Connect and complete the boundary lines, and fill the areas between the boundary lines with black and white to complete the binarization.

[0051] Step S1 specifically involves:

[0052] S101: First, fill the original image. Let the size of the original image be M*N. Fill the top, bottom, left and right directions of the image with pixels of width p and gray value of 0, so that the image size is (M+2p)*(N+2p).

[0053] S102: Downsample the captured Gray code along the direction of code value change. Due to the divergence of the light source and the material properties of the car paint, the transition between black and white areas when structured light hits the paint surface often has a long transition. Direct edge detection would result in wide and divergent edges. Therefore, the image is first downsampled along the direction of code value change to make the transition at the black and white boundary of the Gray code image more obvious, thus obtaining stronger edges. The downsampling principle is as follows: Where I and I D Let (k,j) and (l,j) represent the original Gray code image and the downsampled Gray code image, respectively. (k,j) and (l,j) represent the pixel coordinates of any point in the original image and the corresponding pixel coordinates after sampling, respectively. p indicates that the downsampling step size is odd and can be specified by the user. The size of the sampled image is [size missing].

[0054] S103: Perform edge detection on the downsampled image using the Canny operator. Detected edges are represented by white pixels (grayscale value 255), and other points are represented by black pixels (grayscale value 0), resulting in a binarized edge image I. D_edge1 The set of pixels representing edges (hereinafter referred to as edge points) is represented as E = {(x,y)|I}. D_edge1 (x,y)=255}.

[0055] In step S2, affected by lighting conditions and noise, I D_edge1 The edge point E contains both the expected detection boundary line and other noise and false boundaries. For noise, its area is small, and most can be removed using connected component analysis. The number and area of ​​the connected components formed by the edge points are obtained using OpenCV's `connectedComponentsWithStats` function. Each connected component is traversed, and connected regions with areas smaller than the threshold `area_threshold` are filtered out to obtain I. D_edge2 .

[0056] Due to uneven lighting and the fact that defects on the car paint, such as scratches, inherently possess "boundary" characteristics, some edges in the above image are not the expected boundaries of black and white areas. Therefore, filtering is required for these pseudo-boundaries. Step S3 specifically involves:

[0057] S301: For I D_edge2 Any white edge point I D_edge2 (x0,y0) represents the coordinates of any edge point in the image. Taking this point as the center, count the number of edge points in its left and right neighborhoods. If all of them are less than the threshold edge_threshold, then the point is considered a pseudo-boundary point and is set to black. Otherwise, the point is considered a boundary point and remains unchanged.

[0058] S302: Decrease the neighborhood length i, and repeatedly perform S301 one to two times until all pseudo-boundaries are eliminated, to obtain a new edge image I D_egge3 .

[0059] The left and right neighborhoods are defined as follows: for any edge point I D_egge2 (x0,y0), the left neighborhood is defined as I region_left (u,v)={I(u,v)|x0-i≤u<x0,y0-1≤v≤y0+1}, and the right neighborhood is defined as I region_right (u,v)={I(u,v)|x0≤u<x0+i,y0-1≤v≤y0+1}, where (u,v) represents the coordinates in the left and right neighborhoods, (x0,y0) represents any edge point, and i represents the neighborhood length; the number of edge points in the left neighborhood EdgeCount_left and the number of edge points in the right neighborhood EdgeCount_right are counted respectively, then

[0060] Step S4 is specifically:

[0061] S401: Upsample the edge points in the current edge image I D_edge3 to the corresponding positions in the original image; first create a pure black image with the size of the original padded image of (M+2p)*(N+2p), then obtain the coordinates (x,y) of the edge points in I D_edge3 , keep the abscissa of the edge points unchanged, multiply the ordinate by p, where p is the downsampling step size, to obtain the corresponding positions (x,py) of the edge points in the original image, and set them to white, to obtain the edge point image I with the size of (M+2p)*(N+2p) edge ;

[0062] S402: Perform precise positioning of boundary points; through the above steps, the boundary points are positioned within p pixels centered on each edge point in the direction of image code value change; let the coordinate of any edge point be L edge (x0,y0), and in the direction of image code value change, use the gradient operator (1,0,-1) T to calculate the gradient Gy of the original grayscale code image I in to , let the point with the maximum amplitude be I(x m ,y m ), then I(x m ,y m ) is the precisely positioned boundary point, the straight line formed by connecting several boundary points is the boundary line to be detected, and a boundary image I is composed of several boundary lines boundary .

[0063] Step S5 is specifically:

[0064] S501: I boundary The boundary lines in the code may be discontinuous and need to be connected and completed; first, find the discontinuity, and then... boundary Iterate through all boundary points, and let any boundary point I... boundary (x0, y0), detect its left side I boundary (x0-1, y0-2) to I boundary For a pixel (x0-1, y0+2), if there is no white boundary point, it indicates a discontinuity at that pixel. Find the nearest boundary point on the left and use the Bresenham algorithm to connect the current pixel to its nearest boundary point to complete the connection. The same method applies to the right side. The step of finding the distance I... boundary The method for finding the nearest boundary point (x0, y0) is as follows: Search for boundary points within a K*K square centered at the x0 point, incrementing K by 1 from 3 until a new boundary point I is found on either the left or right side. boundary (x i ,y i If the new boundary points are not unique, calculate the Euclidean distance from each boundary point to the new boundary point. By taking the boundary point corresponding to the minimum value of d as the connection point, a new boundary image I' is finally obtained. boundary ;

[0065] S502: Fill the area between the boundary lines with black and white to complete binarization; binarize I' in a top-down, left-to-right order. boundary Iterate through all pixels to find the first boundary point I'. boundary Detect I' downwards in sequence boundar (x0, y0 + h)h = 1, 2, 3, ... until the first boundary point I' is detected. boundary (x0, y1), using the detection methods described in S2 and S3, determine whether this pixel is a true boundary point. If it is, then set I' boundary (x0,y0) to I' boundary All pixels between (x0, y1) are set to either black or white; otherwise, the process continues traversing downwards. boundar (x0,y h ) and I'' boundary (x0,y h+1 The color between (h+1)%2))*255 is calculated as ((h+1)%2))*255. If the result is 255, it is white; if it is 0, it is black.

[0066] Example

[0067] The specific implementation of the present invention will now be described in conjunction with the embodiments and accompanying drawings.

[0068] In this embodiment, a computer monitor screen is used as a structured light source to project five Gray code images onto the car paint surface. The Gray code value changes in the height direction of the image. A black and white camera is used to acquire the Gray code images reflected from the car paint surface. The resolution is 2048*2432 and the depth is 8 bits. The images are then binarized using the method mentioned in this invention.

[0069] Step 1: Downsample the captured Gray code image in the height direction and use the Canny operator to detect image edges.

[0070] First, five Gray code images are projected sequentially onto a computer monitor. The Gray code images captured by the system and black-and-white camera used in this embodiment, as reflected from the car's paint surface, are shown below. Figure 2 and Figure 3 As shown, the five original images were filled with pixels of width 9 and grayscale value 0 in the top, bottom, left, and right directions, making the image size 2066*2450.

[0071] The captured Gray code was then downsampled along the height direction. The downsampling step size was set to p = 9, according to the sampling principle. Perform downsampling, where I and I D Let and represent the original Gray code image and the downsampled Gray code image, respectively. (k,j) and (l,j) represent the pixel coordinates of any point in the original image and the corresponding pixel coordinates after sampling, respectively. The sampled image has a size of 230*2450. Then, edge detection is performed on the downsampled image using the Canny operator. Detected edge points are represented by white pixels with a grayscale value of 255, and other points are represented by black pixels with a grayscale value of 0, resulting in a binarized image I. D_edge1 The downsampled Gray code image and the image after edge detection are as follows: Figure 4 As shown.

[0072] Step 2: Perform the binarization on the obtained image I D_edge1 Perform connected component analysis and remove edge points whose connected component area is less than a threshold.

[0073] Affected by lighting conditions and noise, I D_edge1 The edge point set E contains many pseudo-boundaries and noise points. For the noise points, their areas are small, and some can be removed using connected component analysis. The `connectedComponentsWithStats` function in OpenCV can be used to obtain I... D_edge1 The number and area of ​​connected components formed by edge points are calculated. For each connected component, a threshold area_threshold = 30 is defined, filtering out connected components with an area less than 30 pixels to obtain I. D_edge2 .

[0074] Perform step 3: remove false edges. For I D_edge2 any arbitrary white edge point I on D_edge2 (x0,y0), where (x0,y0) represents the coordinates of any edge point in the image, with this point as the center, count the number of edge points EdgeCount_left and EdgeCount_right in its left neighborhood I region_left (u,v)={I(u,v)|x0-32≤u<x0,y0-1≤v≤y0+1} and right neighborhood I region_right (u,v)={I(u,v)||x0≤u<x0+32,y0-1≤v≤y0+1} respectively, if both are less than the threshold 32, the point is considered a false edge, its grayscale value is set to 0, otherwise it remains 255 unchanged.

[0075] Next, reduce i to 16 and 8 in sequence, repeat the above steps, the false edges are almost completely eliminated, and the new edge image I after filtering out stray points and false edges D_edge3 is as Figure 5 shown.

[0076] Perform step 4: upsample the edge image to the size 2066*2450 of the original filled image, and accurately locate the edge points to obtain the boundary line.

[0077] The current edge image is I D_edge3 , upsample the currently detected edge points to the corresponding positions in the original image. First, create a pure black image with the size of 2066*2450, which is the size of the original filled image, then obtain the coordinates (x,y) of the edge points in I D_edge3 , keep the abscissa of the edge points unchanged, multiply the ordinate by the downsampling step size p=9 in step 1 to obtain the corresponding position (x,9y) of the edge point in the original image, set its grayscale value to 255, and obtain the edge point image I with the size of 2066*2450 edge .

[0078] Through the above steps, the boundary points are located within p pixels centered on each edge point in the vertical direction. Let the coordinates of any edge point be I edge (x0,y0), in the image height direction, use the gradient operator (1,0,-1) T to calculate the gradient Gy of the original gray code image I between I(x0,y0-4) and I(x0,y0+4), let the point with the maximum amplitude be I(x m ,y m ), then (x m ,y m ) is the precisely located boundary point, the straight line formed by several boundary points is the boundary line expected to be detected, and the boundary image I is composed of several boundary lines boundary , as shown in Figure 6 As shown.

[0079] Step 5: Connect and complete the boundary lines, then fill the areas between the boundary lines with black and white to complete binarization. boundary The boundary lines in the code may be discontinuous and need to be connected and completed. First, locate the discontinuities, and then... boundary Iterate through all boundary points, and let any boundary point I... boundary (x0, y0), detect its left side I boundary (x0-1, y0-2) to I boundary For a pixel (x0-1, y0+2), if there is no white boundary point, it indicates a discontinuity at that pixel. Find the nearest boundary point on the left and use the Bresenham algorithm to connect the current pixel to its nearest boundary point to complete the connection. The same method applies to the right side. Find the distance I... boundary The method for finding the nearest boundary point (x0, y0) is as follows: Search for boundary points within a K*K square centered at the x0 point, incrementing K by 1 from 3 until a new boundary point I is found on either the left or right side. boundary (x i ,y i If the new boundary points are not unique, calculate the Euclidean distance from each boundary point to the new boundary point. By taking the boundary point corresponding to the minimum value of d as the connection point, the final boundary image I' is obtained. boundary .

[0080] Next, proceed from top to bottom and from left to right to examine I'. boundary Iterate through all pixel values ​​to find the first boundary point I'. boundary (x0, y0), sequentially detect I' downwards. boundary (x0, y0 + h), h = 1, 2, 3, ... until the first boundary point I' is detected. boundary (x0, y1), using the detection methods described in steps two and three, determine whether this pixel is a true boundary point. If it is, then set I' boundary (x0,y0) to I' boundary The pixel grayscale values ​​between (x0, y1) are all set to 0 or 255; otherwise, the process continues to traverse the pixels downwards. boundary (x0,y h ) and I' boundary (x0,y h+1 The formula for calculating the grayscale value between (h+1) and (h+2) is ((h+1)%2))*255. A result of 0 represents black, and a result of 255 represents white. The final Gray code binarized image is shown below. Figure 7 As shown.

[0081] The binarization result obtained in this embodiment is compared with the binarization result obtained by the thresholding method. The Gray code image acquired in this embodiment is binarized using the thresholding method, and the binarization result is as follows: Figure 8 As shown, the binarized image contains a lot of noise, and even large areas of binarization errors occur. In contrast, the binarization result of the method of this invention is very clear, thus demonstrating the stability and robustness of this invention in Gray code image binarization.

[0082] This invention proposes an electronic device, including a memory and a processor. The memory stores a computer program, and the processor executes the computer program to implement the steps of the Gray code binarization method based on boundary line detection technology.

[0083] This invention proposes a computer-readable storage medium for storing computer instructions, which, when executed by a processor, implement the steps of the Gray code binarization method based on boundary line detection technology.

[0084] The memory in this application embodiment can be volatile memory or non-volatile memory, or it can include both volatile and non-volatile memory. The non-volatile memory can be read-only memory (ROM), programmable read-only memory (PROM), erasable programmable read-only memory (EPROM), electrically erasable programmable read-only memory (EEPROM), or flash memory. The volatile memory can be random access memory (RAM), which is used as an external cache. By way of example, but not limitation, many forms of RAM are available, such as static random access memory (SRAM), dynamic random access memory (DRAM), synchronous dynamic random access memory (SDRAM), double data rate synchronous dynamic random access memory (DDRSDRAM), enhanced synchronous dynamic random access memory (ESDRAM), synchronous linked dynamic random access memory (SLDRAM), and direct rambus RAM (DRRAM). It should be noted that the memory used in the methods described in this invention is intended to include, but is not limited to, these and any other suitable types of memory.

[0085] In the above embodiments, implementation can be achieved, in whole or in part, through software, hardware, firmware, or any combination thereof. When implemented in software, it can be implemented, in whole or in part, as a computer program product. The computer program product includes one or more computer instructions. When the computer instructions are loaded and executed on a computer, all or part of the processes or functions described in the embodiments of this application are generated. The computer can be a general-purpose computer, a special-purpose computer, a computer network, or other programmable device. The computer instructions can be stored in a computer-readable storage medium or transmitted from one computer-readable storage medium to another. For example, the computer instructions can be transmitted from one website, computer, server, or data center to another via wired (e.g., coaxial cable, fiber optic, digital subscriber line (DSL)) or wireless (e.g., infrared, wireless, microwave, etc.) means. The computer-readable storage medium can be any available medium accessible to a computer or a data storage device such as a server or data center that integrates one or more available media. The available media may be magnetic media (e.g., floppy disks, hard disks, magnetic tapes), optical media (e.g., high-density digital video discs (DVDs)), or semiconductor media (e.g., solid-state disks (SSDs)).

[0086] In implementation, each step of the above method can be completed by integrated logic circuits in the processor's hardware or by instructions in software. The steps of the method disclosed in the embodiments of this application can be directly implemented by a hardware processor, or by a combination of hardware and software modules in the processor. The software modules can reside in random access memory, flash memory, read-only memory, programmable read-only memory, electrically erasable programmable memory, registers, or other mature storage media in the art. This storage medium is located in memory, and the processor reads information from the memory and, in conjunction with its hardware, completes the steps of the above method. To avoid repetition, detailed descriptions are omitted here.

[0087] It should be noted that the processor in the embodiments of this application can be an integrated circuit chip with signal processing capabilities. During implementation, each step of the above method embodiments can be completed by the integrated logic circuitry in the processor's hardware or by instructions in software form. The processor can be a general-purpose processor, a digital signal processor (DSP), an application-specific integrated circuit (ASIC), a field-programmable gate array (FPGA), or other programmable logic devices, discrete gate or transistor logic devices, or discrete hardware components. It can implement or execute the methods, steps, and logic block diagrams disclosed in the embodiments of this application. The general-purpose processor can be a microprocessor or any conventional processor. The steps of the methods disclosed in the embodiments of this application can be directly embodied as being executed by a hardware decoding processor, or executed by a combination of hardware and software modules in the decoding processor. The software modules can be located in random access memory, flash memory, read-only memory, programmable read-only memory, electrically erasable programmable memory, registers, or other mature storage media in the art. This storage medium is located in memory, and the processor reads the information in the memory and, in conjunction with its hardware, completes the steps of the above methods.

[0088] The Gray code binarization method based on boundary line detection technology proposed in this invention has been described in detail above. Specific examples have been used to illustrate the principle and implementation of this invention. The description of the above embodiments is only for the purpose of helping to understand the method and core idea of ​​this invention. At the same time, for those skilled in the art, there will be changes in the specific implementation and application scope based on the idea of ​​this invention. Therefore, the content of this specification should not be construed as a limitation of this invention.

Claims

1. A Gray code binarization method based on boundary line detection technology, characterized in that, The method includes the following steps: S1: Downsample the captured Gray code image and use the Canny operator to detect image edges; S2: The binarized image obtained from S1 Perform connected component analysis and remove edge points whose connected component area is less than a threshold. S3: Design a filter to remove pseudo-boundaries; S4: Upsample the edge image to the original image size and accurately locate the edge points to obtain the boundary line; S5: Connect and complete the boundary lines, and fill the areas between the boundary lines with black and white to complete the binarization; Step S3 specifically involves: S301: Regarding Any white edge point , This represents the coordinates of any edge point in the image. Centered on this point, count the number of edge points in its left and right neighborhoods. If all of them are less than the threshold edge_threshold, then the point is considered a pseudo-boundary point and is set to black. Otherwise, the point is considered a boundary point and remains unchanged. S302: Reduce neighborhood length Repeat step S301 once or twice until all false boundaries are eliminated, resulting in a new edge image. ; The left and right neighborhoods are defined as follows: any edge point Left neighbor is defined as The right neighbor is defined as ,in Represents the coordinates in the left and right neighborhoods. Represents any edge point. Represents the neighborhood length; count the number of edge points in the left and right neighborhoods respectively (EdgeCount_left and EdgeCount_right), then the image... gray values ​​of each point .

2. The method according to claim 1, characterized in that, Step S1 specifically involves: S101: First, fill the original image. Let the size of the original image be M. N is the number of pixels with a width of p and a grayscale value of 0, placed in the top, bottom, left, and right directions of the image to make the image size (M+2p). (N+2p); S102: Downsample the captured Gray code along the direction of code value change; S103: Perform edge detection on the downsampled image using the Canny operator. Detected edges are represented by white pixels, and other points are represented by black pixels, resulting in a binarized edge image. The set of pixels representing the edges is represented as .

3. The method according to claim 2, characterized in that, The downsampling principle is ,in and These represent the original Gray code image and the downsampled Gray code image, respectively. and Let represent the pixel coordinates of any point in the original image and the corresponding pixel coordinates after sampling, respectively. Let p indicate that the downsampling step size is odd, and the size of the sampled image is . .

4. The method according to claim 3, characterized in that, In step S2, the number and area of ​​connected components formed by edge points are obtained using OpenCV's `connectedComponentsWithStats` function. Each connected component is then traversed, and connected regions with areas smaller than the threshold `area_threshold` are filtered out to obtain... .

5. The method according to claim 4, characterized in that, Step S4 specifically involves: S401: Convert the current edge image Edge points in the image are upsampled to their corresponding positions in the original image; first, a (M+2p) image is created. A pure black image of the original filled image size (N+2p) is then obtained. Coordinates of the middle edge point By keeping the x-coordinates of the edge points unchanged and multiplying their y-coordinates by p, where p is the downsampling step size, the corresponding positions of the edge points in the original image are obtained. Then set it to white, resulting in a size of (M+2p). (N+2p) edge point image ; S402: Perform precise location of boundary points; through the above steps, the boundary points are located within p pixels centered on each edge point in the direction of image code value change; let the coordinates of any edge point be... In the direction of image code value change, the gradient operator is used. Calculate the original Gray code image exist arrive The gradient Gy between points, let the point of maximum magnitude be... ,but These are the precisely located boundary points. The straight line connecting several boundary points is the boundary line to be detected, and the boundary image is composed of several boundary lines. .

6. The method according to claim 5, characterized in that, Step S5 specifically involves: S501: The boundary lines in the text may have gaps and need to be connected and completed; first, find the gaps, and then... Iterate through all boundary points, assuming any boundary point... Detect its left side arrive For a pixel, if there is no white boundary point, it indicates a discontinuity at that pixel. Find the nearest boundary point on the left and use the Bresenham algorithm to connect the current pixel to its nearest boundary point to complete the connection. The same method applies to the right side. The step of finding the distance... The method for finding the nearest boundary point is as follows: Using this point as the center, K... The search for boundary points within the square K is performed, with K increasing by 1 sequentially from 3 until new boundary points are found on both the left and right sides. If the new boundary points are not unique, calculate the Euclidean distance from each boundary point to the new boundary point. By taking the boundary point corresponding to the minimum value of d as the connection point, a new boundary image is finally obtained. ; S502: Fill the area between the boundary lines with black and white to complete binarization; perform binarization in a top-down, left-to-right order. Iterate through all pixels to find the first boundary point. Detect downwards sequentially Until the first boundary point is detected Using the detection methods described in S2 and S3, determine whether the pixel is a true boundary point; if so, then... arrive Set all pixels between them to black or white, otherwise continue traversing the pixels downwards; and The colors between are If the result is 255, it is white; if it is 0, it is black.

7. An electronic device comprising a memory and a processor, wherein the memory stores a computer program, characterized in that, When the processor executes the computer program, it implements the steps of the method according to any one of claims 1-6.

8. A computer-readable storage medium for storing computer instructions, characterized in that, When the computer instructions are executed by the processor, they implement the steps of the method according to any one of claims 1-6.

Citation Information

Patent Citations

  • Round Mark point positioning method based on connected region filtering

    CN103729632A

  • Mura defect detection method for edge blurring in LCD (Liquid Crystal Display) screen

    CN114792310A