A screen defect detection method, device, equipment and storage medium
By acquiring grayscale images of the screen and using gradient image and window filtering techniques for foreground-background segmentation, screen defects are automatically identified, solving the problem of missed or false detections that are easy to occur during manual inspection, and achieving high-precision defect detection.
Patent Information
- Application Number
- CN202311127297.3
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2023-09-01
- Publication Date
- 2026-03-03
- Estimated Expiration
- 2043-09-01
AI Technical Summary
Current technologies rely on manual inspection for screen defect detection, which is prone to missed detections and false detections, and it is difficult to maintain high accuracy under different lighting conditions.
By acquiring grayscale images of the screen, gradient image and window filtering techniques, combined with foreground and background segmentation methods, the screen defect areas are automatically identified.
It improves the accuracy and robustness of screen defect detection and reduces the impact of lighting changes on the detection results.
Smart Images

Figure CN117078655B_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of image processing, and more particularly to a method, apparatus, device, and storage medium for detecting screen defects. Background Technology
[0002] The screen is one of the main components of electronic devices, and its quality is closely related to the user experience, especially for devices that rely on the screen for user interaction. In the screen manufacturing industry, screens typically undergo defect testing before leaving the factory, such as checking for dead pixels, scratches, etc., to determine whether the screen is a good product. Currently, this mainly relies on manual inspection, but because screens have a certain degree of transparency and reflectivity, manual defect inspection is prone to missed or false positives. Summary of the Invention
[0003] This invention provides a screen defect detection method, apparatus, device, and storage medium to address the shortcomings of related technologies.
[0004] According to a first aspect of the present invention, a screen defect detection method is provided, comprising:
[0005] Obtain a grayscale image of the screen to be inspected;
[0006] Based on each pixel in the grayscale image and its surrounding pixels, determine the gradient image corresponding to the grayscale image;
[0007] In the gradient direction of the gradient image, a window of a set length is moved with a preset step size. The window includes an odd number of gradient values. If the middle gradient value in the window belongs to the minimum gradient value in the window, the pixel corresponding to the minimum gradient value is set as a background pixel to obtain the target image.
[0008] The target image is segmented into foreground and background, and the segmented target foreground region is determined as the defect region on the screen to be detected.
[0009] In some embodiments, acquiring the grayscale image of the screen to be detected includes:
[0010] Acquire a color image of the screen to be inspected;
[0011] The color image is converted to grayscale to obtain a grayscale image of the screen to be detected.
[0012] In some embodiments, converting the color image to grayscale to obtain a grayscale image of the screen to be detected includes:
[0013] For each pixel in the color image, the brightness value of each channel in the pixel is obtained, and the channels include the R channel, G channel and B channel;
[0014] The brightness values of each channel are weighted and summed according to their respective weights to obtain the grayscale value of the pixel. The weight of the R channel is greater than that of the G and B channels.
[0015] In some embodiments, determining the gradient image corresponding to the grayscale image based on each pixel in the grayscale image and its surrounding pixels includes:
[0016] The grayscale image is weighted and summed by a convolution kernel of a preset size for each pixel and its surrounding neighboring pixels to obtain a gradient image corresponding to the grayscale image.
[0017] In some embodiments, the gradient direction is perpendicular to the long side of the screen to be detected, and the set length is 3;
[0018] If the intermediate gradient value in the window belongs to the minimum gradient value within the window, then the pixel corresponding to the minimum gradient value is set as the background pixel, including:
[0019] The first gradient value, the second gradient value, and the third gradient value within the window are obtained respectively, wherein the second gradient value is located in the middle of the window;
[0020] If the second gradient value is less than the first gradient value and the second gradient value is less than the third gradient value, then the pixel corresponding to the second gradient value is set as the background pixel.
[0021] In some embodiments, the step of performing foreground-background segmentation on the target image and determining the segmented target foreground region as the defect region on the screen to be detected includes:
[0022] The target image is segmented into candidate foreground regions and candidate background regions based on an initial threshold.
[0023] Based on the number of pixels at each gray level, determine the number of first pixels in the candidate foreground region and the number of second pixels in the candidate background region;
[0024] The average grayscale value of the candidate foreground region is determined based on the number of pixels in each grayscale level of the candidate foreground region and the number of the first pixels; and the average grayscale value of the candidate background region is determined based on the number of pixels in each grayscale level of the candidate background region and the number of the second pixels.
[0025] The average grayscale value of the target image is determined based on the first number of pixels and the average grayscale value of the candidate foreground region, and the second number of pixels and the average grayscale value of the candidate background region.
[0026] Based on the average grayscale value of the target image, determine the inter-class variance between the candidate background region and the candidate foreground region;
[0027] The target image is segmented into foreground and background based on the inter-class variance value, and the segmented target foreground region is determined as the defect region on the screen to be detected.
[0028] In some embodiments, after obtaining the grayscale image, the method further includes:
[0029] Obtain the gradient of each pixel in the grayscale image;
[0030] If the gradient of the pixel is less than or equal to the gradient threshold, the pixel value of the pixel is determined by the first diffusion function;
[0031] If the gradient of the pixel is greater than the gradient threshold, the second diffusion function is used to determine the pixel value.
[0032] According to a second aspect of the present invention, a screen defect detection device is provided, the device comprising:
[0033] The acquisition unit is used to acquire a grayscale image of the screen to be detected;
[0034] The filtering unit is used to determine the gradient image corresponding to the grayscale image based on each pixel in the grayscale image and its surrounding pixels, and to move a window of a set length in the gradient direction of the gradient image with a preset step size. The window includes an odd number of gradient values. If the middle gradient value in the window is the smallest gradient value in the window, the middle pixel is set as the background pixel to obtain the target image.
[0035] The segmentation unit is used to perform foreground and background segmentation on the target image, and to determine the segmented target foreground region as the defect region on the screen to be detected.
[0036] In some embodiments, the acquisition unit is specifically used to: acquire a color image of the screen to be detected; and perform grayscale processing on the color image to obtain a grayscale image of the screen to be detected.
[0037] In some embodiments, the acquisition unit is specifically used to: for each pixel in the color image, acquire the brightness value of each channel in the pixel, the channel including the R channel, the G channel and the B channel; according to the weight of each channel, perform a weighted summation of the brightness values of each channel to obtain the gray value corresponding to the pixel, wherein the weight of the R channel is greater than the weight of the G channel and the B channel.
[0038] In some embodiments, the gradient direction is vertical, and the set length is 3; the filtering unit is specifically used to: obtain a first gradient value, a second gradient value, and a third gradient value within the window, wherein the second gradient value is located in the middle of the window; if the second gradient value is less than the first gradient value and the second gradient value is less than the third gradient value, then the pixel corresponding to the second gradient value is set as a background pixel.
[0039] In some embodiments, the segmentation unit is specifically used to: segment the target image into candidate foreground regions and candidate background regions according to an initial threshold;
[0040] Based on the number of pixels at each gray level, determine the number of first pixels in the candidate foreground region and the number of second pixels in the candidate background region;
[0041] The average grayscale value of the candidate foreground region is determined based on the number of pixels in each grayscale level of the candidate foreground region and the number of the first pixels; and the average grayscale value of the candidate background region is determined based on the number of pixels in each grayscale level of the candidate background region and the number of the second pixels.
[0042] The average grayscale value of the target image is determined based on the first number of pixels and the average grayscale value of the candidate foreground region, and the second number of pixels and the average grayscale value of the candidate background region.
[0043] Based on the average grayscale value of the target image, determine the inter-class variance between the candidate background region and the candidate foreground region;
[0044] The target image is segmented into foreground and background based on the inter-class variance value, and the segmented target foreground region is determined as the defect region on the screen to be detected.
[0045] According to a third aspect of the present invention, a computing device is provided, comprising:
[0046] Processor; memory used to store processor-executable instructions;
[0047] The processor implements the method described above by running the executable instructions.
[0048] According to a fourth aspect of the present invention, a computer-readable storage medium is provided having computer instructions stored thereon, which, when executed by a processor, implement the method described in any of the preceding embodiments.
[0049] As can be seen from the above embodiments, the present invention acquires a grayscale image of the screen to be inspected, determines a gradient image corresponding to the grayscale image based on each pixel in the grayscale image and its surrounding pixels, and moves a window of a set length with a preset step size along the gradient direction of the gradient image. The window includes an odd number of gradient values. If the middle gradient value in the window belongs to the minimum gradient value within the window, the pixel corresponding to the minimum gradient value is set as a background pixel to obtain a target image. The target image is then segmented into foreground and background, and the segmented target foreground region is determined as the defect region on the screen to be inspected. The present invention improves the accuracy and robustness of defect detection by determining normal pixels based on the gradient of pixels along the gradient direction of the gradient image and setting normal pixels as background pixels.
[0050] It should be understood that the above general description and the following detailed description are exemplary and explanatory only, and are not intended to limit the invention. Attached Figure Description
[0051] The accompanying drawings, which are incorporated in and form part of this specification, illustrate embodiments consistent with the invention and, together with the description, serve to explain the principles of the invention.
[0052] Figure 1 This is a flowchart illustrating a screen defect detection method according to an embodiment of the present invention.
[0053] Figure 2 This is a schematic diagram of a vertically segmented screen to be detected, as shown in an embodiment of the present invention.
[0054] Figure 3 This is a schematic diagram of a horizontally segmented screen to be detected, according to an embodiment of the present invention.
[0055] Figure 4 This is a schematic diagram illustrating the movement of a window with a length of 3 according to an embodiment of the present invention.
[0056] Figure 5 This is a flowchart illustrating foreground and background segmentation of a target image according to an embodiment of the present invention.
[0057] Figure 6 This is a schematic diagram of a screen defect detection device according to an embodiment of the present invention. Detailed Implementation
[0058] Exemplary embodiments will now be described in detail, examples of which are illustrated in the accompanying drawings. When the following description relates to the drawings, unless otherwise indicated, the same numerals in different drawings denote the same or similar elements. The embodiments described in the following exemplary embodiments do not represent all embodiments consistent with the present invention. Rather, they are merely examples of apparatuses and methods consistent with some aspects of the invention as detailed in the appended claims.
[0059] During screen defect detection, changes in lighting may alter the visibility of defects or flaws on the screen under different lighting conditions, thereby increasing the probability of missed or false detections during the screen defect detection process.
[0060] Therefore, this invention provides a screen defect detection method, which involves acquiring a grayscale image of the screen to be detected, performing non-uniform filtering on the grayscale image, performing non-linear filtering on the non-uniformly filtered image, and then performing adaptive threshold segmentation on the non-linearly filtered image to obtain the defect region, such as a scratch region. Through the above image transformation, this invention can effectively enhance adaptability to changes in illumination, and improve detection accuracy and robustness.
[0061] The following embodiments will describe the screen defect detection method provided by the present invention in conjunction with the accompanying drawings.
[0062] Figure 1 This is a flowchart illustrating a screen defect detection method according to an embodiment of the present invention, such as... Figure 1 As shown, the screen defect detection method may include the following steps 101 to 104.
[0063] In step 101, a grayscale image of the screen to be detected is acquired.
[0064] This embodiment can acquire a color image of the screen to be tested and perform grayscale processing on the color image to obtain a grayscale image of the screen to be tested.
[0065] A color image of the screen to be inspected is obtained by photographing it. For example, the screen to be inspected can be placed on the inspection station, the screen can be turned on, and a camera can be used to take a picture of the screen to acquire a color image. The acquired color image is then uploaded to a processor, which is used to execute the screen defect detection method.
[0066] In one implementation, to improve detection efficiency, the entire original image of the screen to be detected can be divided into multiple sub-images of the screen to be detected at a preset size along a specified segmentation direction. The specified segmentation direction may include a horizontal direction and a vertical direction. Figure 2This is a schematic diagram of a vertically segmented screen to be detected according to an embodiment of the present invention. Figure 3 This is a schematic diagram of a horizontally segmented screen to be tested according to an embodiment of the present invention. Therefore, the color image of the screen to be tested can be 201 or 301.
[0067] Those skilled in the art should understand that this invention can be used to detect defects in the entire image of the screen to be inspected, or it can be used to divide the entire image of the screen to be inspected into multiple sub-images of the screen to be inspected for defect detection. In the following embodiments, the entire image of the screen to be inspected and the sub-images of the screen to be inspected are collectively referred to as the image of the screen to be inspected. Furthermore, it should be noted that the screen to be inspected includes a long side and a short side. With the upper left corner of the image as the origin and the x-axis as the reference, the long side of the screen to be inspected in the image can be parallel to or perpendicular to the x-axis direction. Generally, the long side of the image is consistent with the long side of the screen to be inspected in the image. Subsequent embodiments will use two directions as examples to describe the invention when explaining the gradient direction. In implementation, images in different directions can be rotated to a specified direction through rotation operations, for example, rotating a horizontal screen to be inspected to a vertical direction.
[0068] In one embodiment, the screen defect detection method further includes: acquiring an original color image of the screen to be detected; detecting an effective region corresponding to the screen to be detected from the original color image; and cropping the original color image based on the effective region to obtain a color image of the screen to be detected. Cropping can reduce the amount of subsequent processing and improve processing efficiency.
[0069] In some embodiments, performing grayscale processing on the color image to obtain a grayscale image of the screen to be detected may include: for each pixel in the color image, obtaining the brightness value of each channel in the pixel, the channels including the R channel, G channel and B channel; and performing a weighted summation of the brightness values of each channel according to the weight of each channel to obtain the grayscale value corresponding to the pixel, thereby obtaining a grayscale image.
[0070] Considering that the defects contain some red information, in order to highlight the characteristics of the defects, the weight of the R channel is set to be greater than that of the G and B channels.
[0071] For each pixel in the color image, the brightness values of the R / G / B channels in the pixel are obtained and denoted as R(x,y), G(x,y), and B(x,y) respectively. The gray value of the pixel can be calculated according to the weighted formula (1).
[0072] Gray(x,y)=αR(x,y)+βG(x,y)+γB(x,y) Formula (1)
[0073] In formula (1), Gray(x,y) is the gray value of the pixel in the x-th row and y-th column, R(x,y) is the luminance value of the R channel in the pixel in the x-th row and y-th column, G(x,y) is the luminance value of the G channel in the pixel in the x-th row and y-th column, B(x,y) is the luminance value of the B channel in the pixel in the x-th row and y-th column, α is the weight corresponding to the R channel, β is the weight corresponding to the R channel, and γ is the weight corresponding to the R channel. For example, α can be 0.523, β can be 0.224, and γ can be 0.253. In this case, the above formula (1) can be expressed by the following formula (2).
[0074] Gray(x,y)=0.523R(x,y)+0.224G(x,y)+0.253B(x,y) Formula (2)
[0075] If the grayscale value corresponding to each pixel in the color image is obtained, the grayscale image 202 or 302 of the screen to be detected can be obtained.
[0076] In step 102, a gradient image corresponding to the grayscale image is determined based on each pixel in the grayscale image and its surrounding pixels.
[0077] The gradient operator is used to traverse the grayscale image to determine the gradient estimate of each pixel, thereby obtaining the gradient image corresponding to the grayscale image. This embodiment, by using gradient edge searching, can effectively filter interference, enhance the features of defect edges, and make defect features more prominent in areas with large gradients.
[0078] In step 103, a window of a predetermined length is moved along the gradient direction of the gradient image with a preset step size. The window includes an odd number of gradient values. If the middle gradient value in the window belongs to the minimum gradient value within the window, the pixel corresponding to the minimum gradient value is set as a background pixel to obtain the target image.
[0079] Given the gradient image corresponding to the grayscale image, the pixel value of each pixel can be reset based on its gradient value. For example, assuming the gradient direction is vertical, if the gradient value of the middle pixel within the specified window is the minimum gradient value within that window, then this pixel is not a defective pixel. Therefore, the pixel value of the middle pixel is set to the background pixel value, i.e., set to 0. The window is scrolled in increments until the entire grayscale image has been traversed to obtain the target image.
[0080] In step 104, the target image is segmented into foreground and background, and the segmented target foreground region is determined as the defect region on the screen to be detected.
[0081] In this embodiment, the target image can be segmented by a preset threshold, and the segmented target foreground region can be determined as the defect region on the screen to be detected.
[0082] This invention acquires a grayscale image of the screen to be inspected, determines a gradient image corresponding to each pixel in the grayscale image and its surrounding pixels, and moves a window of a predetermined length along the gradient direction of the gradient image with a preset step size. The window includes an odd number of gradient values. If the middle gradient value in the window is the minimum gradient value within the window, the pixel corresponding to the minimum gradient value is set as a background pixel to obtain a target image. The target image is then segmented into foreground and background, and the segmented target foreground region is determined as the defect region on the screen to be inspected. This invention improves the accuracy and robustness of defect detection by determining normal pixels based on the pixel gradient along the gradient direction of the gradient image and setting normal pixels as background pixels.
[0083] In this embodiment, after obtaining the grayscale image, noise is removed using non-uniform filtering. That is, the method further includes: obtaining the gradient of each pixel in the grayscale image; if the gradient of the pixel is less than or equal to a gradient threshold, then a first diffusion function is used to determine the pixel value of the pixel; if the gradient of the pixel is greater than the gradient threshold, then a second diffusion function is used to determine the pixel value of the pixel.
[0084] In an R*R grayscale image, a diffusion function with a range of [0,1] is known. In areas with smaller gradients, the image is expected to be smoother, while in areas with larger gradients, the grayscale values of the image change more significantly. To suppress this change, this embodiment introduces a coefficient k. When the gradient is less than or equal to k, the first diffusion function is used to encourage diffusion, and the image is smoothed. When the gradient is greater than k, the second diffusion function is used to suppress diffusion, and the edges are enhanced.
[0085] In other words, during defect detection, it is desired that the diffusion coefficient causes the diffusion function to produce strong diffusion in smooth regions to facilitate noise elimination, while diffusion stops in edge regions (i.e., defect areas in the image) to facilitate edge sharpening. This embodiment uses the following diffusion function to implement filtering:
[0086]
[0087]
[0088] in: is the diffusion function, which is a monotonically decreasing function of the gradient strength of the diffused image, with a range of [0,1]. The coefficient k is the gradient threshold that prevents diffusion. When the gradient is less than or equal to k, the diffusion function g1 is used, diffusion is encouraged, and the image is smoothed. When the gradient is greater than k, the diffusion function g2 is used, diffusion is suppressed, and the edges are enhanced.
[0089] The above non-uniform filtering can smooth the image, resulting in image 204 or 304, thereby highlighting shallower defect features.
[0090] In some embodiments, a weighted summation can be performed on each pixel in the grayscale image and its surrounding neighboring pixels according to a gradient operator of a preset size to obtain the convolution result corresponding to each pixel; and a gradient image corresponding to the grayscale image can be obtained by squared the convolution result corresponding to each pixel in the grayscale image.
[0091] In implementation, gradient operators of 3*3, 5*5 or 7*7 can be used. This invention does not limit the specific gradient operator used. The following embodiments will use the 5*5 gradient operator as an example to illustrate the process of determining the gradient image.
[0092] For images where the longer side is perpendicular to the horizontal direction (i.e., the x-axis direction) (e.g., image 203), the 5*5 gradient operator is shown in formula (3-1). The first row is (1,1,1,1,1), the second row is (1,1,2,1,1), the third row is all 0, the fourth row is (1,-1,-2,-1,1), and the fifth row is all 1. Using the gradient operator shown in formula (3-1), the gradient component in the vertical direction can be calculated, which is beneficial for enhancing the characteristics of scratch defects.
[0093]
[0094] The gradient magnitude of a pixel is determined by using the gradient function formula (3-2) after convolution based on formula (3-1).
[0095] G = |K*f(x,y)|^2 (Formula 3-2)
[0096] Where G represents the gradient value, K is the gradient operator, and f(x,y) is the pixel value at position (x,y) in the image.
[0097] When the longer side of an image is perpendicular to the horizontal direction, setting the gradient direction to 180 degrees (horizontal) normalizes the gradient angle. For example, in image 203, using a 180-degree direction effectively highlights 0-degree scratch defects, making them easier to detect.
[0098] For each pixel f(x,y) in the grayscale image 203, the 5x5 gradient operator described above can be weighted and summed with that pixel and its surrounding neighboring pixels. The square of the sum is then taken as the vertical gradient component of that pixel. By traversing the entire image, the vertical gradient components of the entire image can be calculated, thus obtaining the gradient image corresponding to the grayscale image 203.
[0099] In this embodiment, squaring the convolution result can enhance the gradient change rate, making it easier to perform gradient comparison within the window later.
[0100] For the case where the long side of the image is parallel to the horizontal direction (e.g., image 303), the 5*5 gradient operator is shown in formula (3-3).
[0101]
[0102] The gradient magnitude of a pixel is determined by using the gradient function formula (3-2) after convolution based on formula (3-3).
[0103] In this case, setting the gradient direction to 90 degrees can effectively highlight 0-degree scratch defects for image 303, making it easier to detect.
[0104] In other words, in this embodiment, the gradient direction is perpendicular to the long side of the screen to be detected. For image 203, the gradient direction is the horizontal direction, and for image 303, the gradient direction is the vertical direction.
[0105] Assuming the window has a set length of 3, the window is moved in unit steps. If the middle gradient value in the window is the minimum gradient value within the window, then the pixel corresponding to the minimum gradient value is set as a background pixel. That is, setting the pixel corresponding to the minimum gradient value as a background pixel if the middle gradient value in the window is the minimum gradient value within the window can include: obtaining a first gradient value, a second gradient value, and a third gradient value within the window, where the second gradient value is located in the middle of the window; if the second gradient value is less than the first gradient value and less than the third gradient value, then the pixel corresponding to the second gradient value is set as a background pixel.
[0106] Figure 4 This is a schematic diagram illustrating the movement of a window with a length of 3 according to an embodiment of the present invention, as shown below. Figure 4 As shown, when the gradient direction is horizontal, if the gradient value b of the middle pixel of window 401 is the smallest compared with the gradient values a and c of the two pixels before and after it in the gradient direction, it means that the pixel is not a defect, so the pixel at this position can be set to 0.
[0107] Assuming the window's set length is 5, and the window moves in unit steps, if the middle gradient value within the window is the smallest gradient value within the window, then the pixel corresponding to the smallest gradient value is set as the background pixel. That is, if the gradient value of the middle pixel is the smallest compared to the gradient values of the pixels before and after it along its gradient direction, then the pixel is not a defect and can be set to 0.
[0108] The above-mentioned nonlinear filtering edge detection on image 203 can yield image 204, and the above-mentioned nonlinear filtering edge detection on image 303 can yield image 304. Comparing images 203 and 204, as well as images 303 and 304, it can be seen that the above-mentioned nonlinear filtering edge detection can further enhance the defect features.
[0109] Figure 5 This is a flowchart illustrating foreground and background segmentation of a target image according to an embodiment of the present invention, such as... Figure 5 As shown, the step of performing foreground-background segmentation on the target image and determining the segmented target foreground region as the defect region on the screen to be detected may include:
[0110] In step 501, the target image is segmented into candidate foreground regions and candidate background regions according to an initial threshold;
[0111] In step 502, the number of first pixels in the candidate foreground region and the number of second pixels in the candidate background region are determined based on the number of pixels at each gray level.
[0112] In step 503, the average gray level of the candidate foreground region is determined based on the number of pixels in each gray level of the candidate foreground region and the number of the first pixels, and the average gray level of the candidate background region is determined based on the number of pixels in each gray level of the candidate background region and the number of the second pixels;
[0113] In step 504, the average grayscale value of the target image is determined based on the first number of pixels and the average grayscale value of the candidate foreground region, and the second number of pixels and the average grayscale value of the candidate background region.
[0114] In step 505, the inter-class variance value between the candidate background region and the candidate foreground region is determined based on the average grayscale value of the target image;
[0115] In step 506, the target image is segmented into foreground and background based on the inter-class variance value, and the segmented target foreground region is determined as the defect region on the screen to be detected.
[0116] For example, the initial threshold can be denoted as T0. Based on the initial threshold, the target image is divided into candidate foreground region f and candidate background region b. Assuming that the total number of pixels in the target image is N and the total gray level of the target image is L-1, the number of foreground pixels is calculated using formula (4) and the number of background pixels is calculated using formula (5).
[0117]
[0118]
[0119] In the above formula, P f P represents the number of foreground pixels. b N represents the number of background pixels. i Let i be the number of pixels at the i-th gray level, where i ranges from 0 to L-1.
[0120] The average grayscale value in the candidate foreground region is calculated using formula (6), and the average grayscale value in the candidate background region is calculated using formula (7).
[0121]
[0122]
[0123] In the above formula, M f M represents the average gray level in the candidate foreground region. b P represents the average gray level in the candidate background region. i Let be the number of pixels at the i-th gray level.
[0124] The average grayscale value of the entire target image is calculated using formula (8).
[0125] M = P f ×M f +P b ×M b Formula (8)
[0126] In formula (8), M is the average gray level of the entire target image.
[0127] The inter-class variance between candidate foreground regions and candidate background regions is calculated using formula (9).
[0128] σ 2 =P f ×(M f -M) 2 +P b ×(M b -M) 2 Formula (9)
[0129] In formula (9), σ is the inter-class variance between the candidate foreground region and the candidate background region.
[0130] The inter-class variance is used as a binarization threshold for threshold segmentation, and the segmented target foreground region is determined as the defect region on the screen to be detected.
[0131] After performing foreground and background segmentation on image 204, a binary image 205 is obtained. After performing foreground and background segmentation on image 304, a binary image 305 is obtained. Comparing images 204 and 205, as well as images 304 and 305, it can be seen that the defect area can be highlighted by adaptive threshold segmentation.
[0132] Figure 6 This is a schematic diagram of a screen defect detection device according to an embodiment of the present invention, such as... Figure 6 As shown, the screen defect detection device includes:
[0133] The acquisition unit 601 is used to acquire a grayscale image of the screen to be detected;
[0134] The filtering unit 602 is used to determine a gradient image corresponding to the grayscale image based on each pixel in the grayscale image and its surrounding pixels, and to move a window of a set length in the gradient direction of the gradient image with a preset step size. The window includes an odd number of gradient values. If the middle gradient value in the window belongs to the minimum gradient value in the window, the middle pixel is set as a background pixel to obtain the target image.
[0135] The segmentation unit 603 is used to perform foreground and background segmentation on the target image and determine the segmented target foreground region as the defect region on the screen to be detected.
[0136] In some embodiments, the acquisition unit 601 is specifically used to: acquire a color image of the screen to be detected; and perform grayscale processing on the color image to obtain a grayscale image of the screen to be detected.
[0137] In some embodiments, the acquisition unit 601 is specifically configured to: for each pixel in the color image, acquire the brightness value of each channel in the pixel, the channel including the R channel, the G channel and the B channel; according to the weight of each channel, perform a weighted summation of the brightness values of each channel to obtain the gray value corresponding to the pixel, wherein the weight of the R channel is greater than the weight of the G channel and the B channel.
[0138] In some embodiments, the gradient direction is perpendicular to the long side of the screen to be detected, and the set length is 3; the filtering unit 602 is specifically used to: obtain a first gradient value, a second gradient value and a third gradient value in the window respectively, wherein the second gradient value is located in the middle of the window; if the second gradient value is less than the first gradient value and the second gradient value is less than the third gradient value, then the pixel corresponding to the second gradient value is set as a background pixel.
[0139] In some embodiments, the segmentation unit 603 is specifically used to: segment the target image into candidate foreground regions and candidate background regions according to an initial threshold;
[0140] Based on the number of pixels at each gray level, determine the number of first pixels in the candidate foreground region and the number of second pixels in the candidate background region;
[0141] The average grayscale value of the candidate foreground region is determined based on the number of pixels in each grayscale level of the candidate foreground region and the number of the first pixels; and the average grayscale value of the candidate background region is determined based on the number of pixels in each grayscale level of the candidate background region and the number of the second pixels.
[0142] The average grayscale value of the target image is determined based on the first number of pixels and the average grayscale value of the candidate foreground region, and the second number of pixels and the average grayscale value of the candidate background region.
[0143] Based on the average grayscale value of the target image, determine the inter-class variance between the candidate background region and the candidate foreground region;
[0144] The target image is segmented into foreground and background based on the inter-class variance value, and the segmented target foreground region is determined as the defect region on the screen to be detected.
[0145] The specific implementation process of each of the above units can be found in the aforementioned embodiments, and will not be repeated here.
[0146] This embodiment may also include the display device of the aforementioned display screen. The display device in this embodiment can be any product or component with display function, such as electronic paper, mobile phone, tablet computer, television, laptop computer, digital photo frame, or navigator.
[0147] It should be noted that the dimensions of layers and regions may be exaggerated in the accompanying drawings for clarity. Furthermore, it is understood that when an element or layer is referred to as being "on" another element or layer, it can be directly on the other element, or there may be intermediate layers. Additionally, it is understood that when an element or layer is referred to as being "below" another element or layer, it can be directly below the other element, or there may be more than one intermediate layer or element. Furthermore, it is also understood that when a layer or element is referred to as being "between" two layers or two elements, it can be the only layer between the two layers or two elements, or there may be more than one intermediate layer or element. Similar reference numerals throughout indicate similar elements.
[0148] In this invention, the terms "first" and "second" are used for descriptive purposes only and should not be construed as indicating or implying relative importance. The term "multiple" refers to two or more unless otherwise expressly defined.
[0149] Other embodiments of the invention will readily occur to those skilled in the art upon consideration of the specification and practice of the disclosure herein. The invention is intended to cover any variations, uses, or adaptations of the invention that follow the general principles of the invention and include common knowledge or customary techniques in the art not disclosed herein. The specification and examples are to be considered exemplary only, and the true scope and spirit of the invention are indicated by the following claims.
[0150] It should be understood that the present invention is not limited to the precise structure described above and shown in the accompanying drawings, and various modifications and changes can be made without departing from its scope. The scope of the invention is limited only by the appended claims.
Claims
1. A method for detecting screen defects, characterized in that, include: Obtain a grayscale image of the screen to be inspected; Based on each pixel in the grayscale image and its surrounding pixels, determine the gradient image corresponding to the grayscale image; In the gradient direction of the gradient image, a window of a set length is moved with a preset step size. The window includes an odd number of gradient values. If the middle gradient value in the window belongs to the minimum gradient value in the window, the pixel corresponding to the minimum gradient value is set as a background pixel to obtain the target image. The target image is segmented into foreground and background, and the segmented target foreground region is determined as the defect region on the screen to be detected. The step of determining the gradient image corresponding to the grayscale image based on each pixel in the grayscale image and its surrounding pixels includes: The grayscale image is weighted and summed for each pixel and its surrounding neighboring pixels according to a gradient operator of a preset size to obtain the convolution result corresponding to each pixel. The gradient image corresponding to the grayscale image is obtained by squared the convolution result corresponding to each pixel in the grayscale image.
2. The method according to claim 1, characterized in that, The step of acquiring the grayscale image of the screen to be detected includes: Acquire a color image of the screen to be inspected; The color image is processed to obtain a grayscale image of the screen to be detected.
3. The method according to claim 2, characterized in that, The step of performing grayscale processing on the color image to obtain a grayscale image of the screen to be detected includes: For each pixel in the color image, the brightness value of each channel in the pixel is obtained, and the channels include the R channel, G channel and B channel; The brightness values of each channel are weighted and summed according to their respective weights to obtain the grayscale value of the pixel. The weight of the R channel is greater than that of the G and B channels.
4. The method according to claim 1, characterized in that, The gradient direction is perpendicular to the long side of the screen to be detected, and the set length is 3. If the intermediate gradient value in the window belongs to the minimum gradient value within the window, then the pixel corresponding to the minimum gradient value is set as the background pixel, including: The first gradient value, the second gradient value, and the third gradient value within the window are obtained respectively, wherein the second gradient value is located in the middle of the window; If the second gradient value is less than the first gradient value and the second gradient value is less than the third gradient value, then the pixel corresponding to the second gradient value is set as the background pixel.
5. The method according to claim 1, characterized in that, The step of performing foreground-background segmentation on the target image and determining the segmented target foreground region as the defect region on the screen to be detected includes: The target image is segmented into candidate foreground regions and candidate background regions based on an initial threshold. Based on the number of pixels at each gray level, determine the number of first pixels in the candidate foreground region and the number of second pixels in the candidate background region; The average grayscale value of the candidate foreground region is determined based on the number of pixels in each grayscale level of the candidate foreground region and the number of the first pixels; and the average grayscale value of the candidate background region is determined based on the number of pixels in each grayscale level of the candidate background region and the number of the second pixels. The average grayscale value of the target image is determined based on the first number of pixels and the average grayscale value of the candidate foreground region, and the second number of pixels and the average grayscale value of the candidate background region. Based on the average grayscale value of the target image, determine the inter-class variance between the candidate background region and the candidate foreground region; The target image is segmented into foreground and background based on the inter-class variance value, and the segmented target foreground region is determined as the defect region on the screen to be detected.
6. The method according to any one of claims 1-5, characterized in that, After obtaining the grayscale image, the method further includes: Obtain the gradient of each pixel in the grayscale image; If the gradient of the pixel is less than or equal to the gradient threshold, the pixel value of the pixel is determined by the first diffusion function; If the gradient of the pixel is greater than the gradient threshold, the second diffusion function is used to determine the pixel value.
7. A screen defect detection device, characterized in that, The device includes: The acquisition unit is used to acquire a grayscale image of the screen to be detected; The filtering unit is used to determine the gradient image corresponding to the grayscale image based on each pixel in the grayscale image and its surrounding pixels, and to move a window of a set length in the gradient direction of the gradient image with a preset step size. The window includes an odd number of gradient values. If the middle gradient value in the window is the smallest gradient value in the window, the middle pixel is set as the background pixel to obtain the target image. The segmentation unit is used to perform foreground and background segmentation on the target image, and to determine the segmented target foreground region as the defect region on the screen to be detected; Specifically, the filtering unit is used to: perform a weighted summation on each pixel in the grayscale image and its surrounding neighboring pixels according to a gradient operator of a preset size to obtain the convolution result corresponding to each pixel; and obtain the gradient image corresponding to the grayscale image based on the square of the convolution result corresponding to each pixel in the grayscale image.
8. A computing device, characterized in that, include: processor; Memory used to store processor-executable instructions; The processor implements the method as described in any one of claims 1 to 4 by executing the executable instructions.
9. A computer-readable storage medium storing computer instructions thereon, characterized in that, When the instructions are executed by the processor, they implement the method as described in any one of claims 1 to 4.
Citation Information
Patent Citations
Defective product identification method for heat-shrinkable tube expanding process
CN114972326A