Background
In the prior art, a plurality of defect detection methods for a display screen exist, most of the defects in the display screen are mainly detected, and the edge defects of the display screen are less concerned, but the edge defects also can actually affect the quality of a product. In addition, edge defects have many small defects which are not obvious, and the defects have two characteristics, namely the defects are positioned at the edge of the screen, and the difference between the defects and the background is smaller. The defects are not easy to detect by adopting the traditional image enhancement algorithm and the threshold value division algorithm to position the defects.
Disclosure of Invention
To solve at least one of the above-mentioned technical problems, the present invention is directed to: a method and a device for detecting edge defects of a display screen are provided to improve the accuracy of detection.
In a first aspect, an embodiment of the present invention provides:
a display screen edge defect detection algorithm comprises the following steps:
acquiring an image to be detected;
performing line-direction dislocation subtraction on the image to be detected and the image to be detected to obtain a first image;
performing column-wise dislocation subtraction on the image to be detected and the image to be detected to obtain a second image;
obtaining an edge image of a display screen in the image to be detected according to the first image and the second image;
filtering the edge image by adopting a plurality of rectangular filtering cores with different angles to obtain a plurality of filtering images;
performing classification marking on each target pixel point according to the maximum value of the target pixel point in the edge image in each filtering image;
selecting one of rectangular expansion structural elements with different directions to perform expansion processing on the target pixel points according to the mark of each target pixel point to obtain an expanded image;
comparing all pixel points in the expansion image and the edge image, and taking out pixel points with the same gray value and the same position in the expansion image and the edge image to form a single-edge pixel defect map;
sequentially performing element expansion and element corrosion treatment on the single-edge pixel defect image, and performing difference on the single-edge pixel defect image and the edge image to obtain a third image;
and obtaining the defect position from the third image.
In some embodiments, the obtaining of the defect position from the third image specifically includes:
performing binary segmentation on the third image according to a segmentation threshold value to obtain a binary image;
and obtaining the defect position according to the position of the pixel point with the numerical value of 255 in the binary image.
In some embodiments, obtaining an edge image of a display screen in the image to be detected according to the first image and the second image specifically includes:
and calculating each pixel point value in the edge image according to the first image and the second image, wherein each pixel point value in the edge image is equal to the square root of the sum of the squares of the gray value of the pixel point in the first image and the gray value in the second image.
In some embodiments, the subtraction of the line-wise misalignment between the image to be measured and the image to be measured is performed to obtain a first image, specifically:
subtracting the gray value of the pixel point in the nth row in the image to be detected from the gray value of the pixel point in the same row in the (n + r) th row to be used as the gray value of the pixel point in the nth row in the first image;
and the image to be detected are subjected to longitudinal dislocation subtraction to obtain a second image, which specifically comprises the following steps:
subtracting the gray value of the nth row of pixel points in the image to be detected from the gray value of the n + r row of pixel points in the same row to be used as the gray value of the nth row of pixel points in the second image;
wherein n and r are positive integers.
In some embodiments, the filtering the edge image by using a plurality of rectangular filtering kernels with different angles to obtain a plurality of filtered images includes:
the edge images are filtered by 12 rectangular filter kernels with directions of 0 °,15 °, 30 °, 45 °,60 °, 75 °,90 °,105 °,120 °, 135 °,150 °,165 °, to obtain 12 filtered images.
In some embodiments, the classifying and marking each target pixel point according to a maximum value of the target pixel point in the edge image in each filtered image specifically includes:
establishing a mark bitmap with the same size as the image to be detected;
searching the maximum value of each pixel point in 12 filtered images;
when the maximum value of the pixel point appears in a filtering picture with the filtering direction of 0 degrees, 15 degrees or 165 degrees, marking the pixel point as a first value in the mark bitmap;
when the maximum value of the pixel point appears in a filtering picture with the filtering direction of 30 degrees, 45 degrees or 60 degrees, marking the pixel point as a second value in the mark bitmap;
when the maximum value of the pixel point appears in a filtering picture with the filtering direction of 75 degrees, 90 degrees or 105 degrees, marking the pixel point as a third value in the mark bitmap;
and when the maximum value of the pixel point appears in the filtering picture with the filtering direction of 120 degrees, 135 degrees or 150 degrees, marking the pixel point as a fourth value in the mark bitmap.
In some embodiments, the target pixel point is a pixel point forming an edge in the edge image;
the selecting one of rectangular expansion structural elements with different directions to perform expansion processing on the target pixel points according to the mark of each target pixel point to obtain an expanded image includes:
performing expansion processing on all the target pixel points to obtain an expanded image, wherein:
when the mark of the target pixel is a first value, selecting a rectangular expansion structural element with the direction of 90 degrees to perform expansion processing on the target pixel point;
when the mark of the target pixel is a second value, selecting a rectangular expansion structural element with the direction of 45 degrees to perform expansion processing on the target pixel point;
when the mark of the target pixel is a third value, selecting a rectangular expansion structural element with the direction of 0 degree to perform expansion processing on the target pixel point;
and when the mark of the target pixel is a fourth value, selecting a rectangular expansion structural element with the direction of 135 degrees to perform expansion processing on the target pixel.
In some embodiments, the sequentially performing the element expansion and the element corrosion on the single-edge pixel defect map includes:
and performing element expansion on the single-edge pixel defect map by using the structural elements with the size of 3 x 3, and then performing corrosion treatment on the single-edge pixel defect map subjected to element expansion treatment by using the structural elements with the size of 9 x 9.
In some embodiments, after the single-edge pixel defect map is sequentially subjected to element expansion and element corrosion, performing a difference between the single-edge pixel defect map and the edge image to obtain a third image, including:
sequentially carrying out element expansion and element corrosion treatment on the single-edge pixel defect map to obtain a fourth image;
carrying out gray value replacement on pixel points in the fourth image according to the mark bitmap to obtain a fifth image;
obtaining a third image by subtracting the fifth image from the edge image;
wherein the gray value replacement specifically comprises:
when the mark of the pixel point (x, y) in the mark bitmap is a first value, the gray level of the grey (x, y) is equal to MAX (grey (x + a, y), grey (x-a, y));
when the mark of the pixel point (x, y) in the mark bitmap is a second value, the gray level of the grey (x, y) is equal to MAX (grey (x + a, y + a), grey (x-a, y-a));
when the mark of the pixel point (x, y) in the mark bitmap is a third value, the gray level of the grey (x, y) is equal to MAX (grey (x, y + a), grey (x, y-a));
when the mark of the pixel point (x, y) in the mark bitmap is a fourth value, the gray level of the grey (x, y) is equal to MAX (grey (x + a, y-a), grey (x-a, y + a)).
Wherein, the grey () represents the gray value of the pixel point.
In a second aspect, an embodiment of the present invention provides:
a display screen edge defect detection, comprising:
carrying out a procedure;
a memory for storing the program;
and the processor is used for loading the program to execute the display screen edge defect detection method.
The embodiment of the invention has the beneficial effects that: the method comprises the steps of determining an edge image through a first image and a second image obtained by staggered subtraction, rapidly extracting edge defects in the image, carrying out multidirectional filtering through a rectangular filtering kernel, carrying out classification marking on pixel points according to a plurality of filtering results, carrying out expansion processing on the edge image through the pixel points based on the classification marking, comparing the edge image with an original image, extracting a single-edge pixel defect image with the maximum value by utilizing the characteristic that only the maximum value point can be the same as the original image during expansion processing, carrying out expansion and corrosion processing on the single-edge pixel defect image, then subtracting the single-edge pixel defect image from the edge image, and obtaining the response of the defect, namely a third image.
Detailed Description
In order to make the purpose, technical solutions and advantages of the present application clearer, the technical solutions of the present application will be clearly and completely described below through embodiments with reference to the accompanying drawings in the embodiments of the present application, and it is obvious that the described embodiments are some embodiments of the present application, but not all embodiments. All other embodiments, which can be derived by a person skilled in the art from the embodiments given herein without making any creative effort, shall fall within the protection scope of the present application.
Referring to fig. 1, the embodiment discloses a display screen edge defect detection algorithm, which includes the following steps:
step 101, obtaining an image to be detected.
The image to be detected is an image of a display screen, and is generally obtained by photographing a mobile phone screen placed in a predetermined direction, wherein the image to be detected may be a gray scale image. As shown in fig. 2, in the present embodiment, the image to be measured includes a background 100 and a mobile phone screen 200, wherein a defect 201 exists at an edge of the mobile phone screen 200. This type of defect is characterized by a small degree of difference from background.
And 102, performing line-direction dislocation subtraction on the image to be detected and the image to be detected to obtain a first image.
And 103, performing column-wise dislocation subtraction on the image to be detected and the image to be detected to obtain a second image.
And 104, obtaining an edge image of the display screen in the image to be detected according to the first image and the second image.
In the region of interest detected in this embodiment, it is observed that the periphery of the screen is a black background and has a large difference from the edge gray level of the screen, so that the column pixels of the picture are subjected to offset subtraction, for example, the nth column of the picture is subtracted from the nth + r column of the picture to obtain a difference picture diffX, so that the vertical edge of the screen exists in a positive value or a negative value with a large absolute value on the obtained difference picture diffX. r can take a value according to practical conditions, such as an integer between 4 and 10.
Similarly, the same offset subtraction method as that for the columns is also adopted for the processing of the rows, and the edges of the rows are obtained. Thus, the horizontal edge of the screen exists as a positive or negative value having a large absolute value on the obtained difference picture diffY.
Considering that when the subtraction is performed in steps 102 and 103, one side of each row is a negative value, diffX and diffY are superimposed in the form of square and root, and finally the edge map of interest 0 of the product to be detected is obtained. The specific calculation formula is as follows:
where edge0 (U, V) is the value at the edge map of interest location (U, V) after the overlay. diffX (U, V) is the value at the location (U, V) of the diffX map after the column is differenced. diffY (U, V) is the value at the location (U, V) of the diffY plot after the column is differed. In the present embodiment, the edge image is as shown in fig. 3.
And 105, filtering the edge image by adopting a plurality of rectangular filtering cores with different angles to obtain a plurality of filtering images.
The rectangular filter kernel size selected in this embodiment is width =17 and height = 2. The filtering angle starts from 0 degrees to the end of 165 degrees, and the angle of filtering is 12 filtering angles of 0 degrees, 15 degrees, 30 degrees, 45 degrees, 60 degrees, 75 degrees, 90 degrees, 105 degrees, 120 degrees, 135 degrees, 150 degrees and 165 degrees at intervals of 15 degrees.
And 106, performing classification marking on each target pixel point according to the maximum value of the target pixel point in the edge image in each filtering image.
Referring to fig. 4, in order to simplify the mark positions on the picture, it is determined that the filtering angles are separated by angular distances of 0 ° (180 °), 45 °,90 °, and 135 °, respectively, and if the filtering angles are closest to 0 ° (180 °), the picture is marked with 1 °, if the filtering angles are closest to 45 °, the picture is marked with 2, and if the filtering angles are closest to 90 °, the picture is marked with 3. If it is closest to 135 deg., then 4 is subsequently marked on the picture. Therefore, the rule of the angle of the rotary filtering corresponding to the zone bit is 0 degrees, 15 degrees and the rule of the angle of the rotary filtering corresponding to the zone bit are 1; the flag digit numbers corresponding to 30 degrees, 45 degrees and 60 degrees are 2; the flag digit numbers corresponding to 75 degrees, 90 degrees and 105 degrees are 3; the flag digit numbers corresponding to 120 °, 135 °,150 ° are 4. The final tag matrix consists of 1, 2, 3, 4.
The rectangular filter kernels are rotated clockwise from 0 deg. to 165 deg. at 15 deg. intervals, and coexist in 12 directions. And comparing the sizes of the corresponding pixel positions of the 12 pictures after filtering at different angles in sequence. The marking step is specifically that firstly, a flag bit picture with the pixel position of 0 is established, wherein the pixel position of the flag bit picture has the same size as that of the filtering picture. Secondly, if the maximum value of the pixel position appears in three filtering pictures with angles of 0 degree/15 degrees/165 degrees in the comparison of 12 pictures, the pixel position is marked as 1, and the pixel point is filtered in the horizontal direction to obtain the maximum value; if the maximum value of the pixel position appears in the filtering pictures with three angles of 30 degrees/45 degrees/60 degrees, the pixel position is marked as 2, and the pixel point is shown to obtain the maximum value in the filtering in the 45-degree direction; if the maximum value of the pixel position appears in the filtering pictures with three angles of 75 degrees/90 degrees/105 degrees, the pixel position is marked as 3, and the maximum value of the pixel point in the filtering in the vertical direction is shown; if the maximum value of the pixel position appears in the three angle filtering pictures of 120 °/135 °/150 °, the pixel position is marked as 4, which indicates that the pixel point obtains the maximum value in the 135 ° direction filtering.
The resulting plot is plotted in the picture, see fig. 4, with the horizontal edge labeled 1, the vertical edge labeled 3, the upper left-right-bottom corner labeled 4, and the upper left-bottom-right-top corner labeled 2.
And 107, selecting one of the rectangular expansion structural elements with different directions to perform expansion processing on the target pixel points according to the mark of each target pixel point to obtain an expanded image.
What is obtained from step 104 is a multi-pixel edge containing a bright point defect, but the bright point defect should exist at the maximum value in the edge, so it is necessary to extract the single pixel edge where the bright point defect exists and remove other interference.
In this step, a single row or column of rectangular expansion structure elements in the horizontal direction, the vertical direction, the 45-degree direction, and the 135-degree direction are first constructed, respectively.
And (4) combining the multi-pixel image edge obtained in the step one with the marked image obtained in the step 106 to self-adaptively select structural elements of morphological expansion operation vertical to the edge. For example, if an edge marked as 1 is encountered, a vertical expansion structural element with a width of 1 and a height of 2 (2 × r + 1) +1 is selected; if an edge labeled 3 is encountered, then the horizontal expanded structural element is selected, with a width of 2 (2 x r + 1) +1 and a height of 1. r is selected from the previous steps.
And 108, comparing all pixel points in the expansion image and the edge image, and taking out pixel points with the same gray value and the same position in the expansion image and the edge image to form a single-edge pixel defect image.
Specifically, after the edges are dilated with the selected structuring element and compared to the original, the equal portions are extracted. Because only the maximum value in the pixel edge is equal to the original image after expansion, a single-edge pixel image is obtained at the moment, and the remaining pixel points are the maximum values in the edge, namely the edge of the pixel with the bright point defect exists.
Because some single miscellaneous points exist in the screen, the edge with the defect is extracted by using a method of finding the maximum outline, and the miscellaneous points in the screen are removed, so that a single-edge pixel defect map is finally obtained, as shown in fig. 5.
And step 109, performing element expansion and element corrosion treatment on the single-edge pixel defect map in sequence, and performing difference processing on the single-edge pixel defect map and the edge image to obtain a third image.
And expanding the single-edge pixel defect map obtained in the step 108 by 3 x 3 structural elements, removing noise points, and then etching by 9 x 9 structural elements.
And replacing the pixel gray value of each position with a larger value in two adjacent pixel positions in a given step length in the direction by combining the flag bit matrix, wherein the step length of the adjacent pixel positions can be half of the size of the corrosion structure element in the step, so as to remove noise possibly existing in the picture after corrosion.
For example, the replacement step in the horizontal direction is to replace the following formula when the value of the pixel (x, y) in the flag bit matrix is 1: grey (x, y) = Max (grey (x-4, y), grey (x +4, y)); grey (x +4, y) represents the pixel position value in the same row as but 4 columns after the grey (x, y), and Max () represents the larger of the two. When the mark of the pixel point (x, y) in the mark bitmap is 2, the gray level of the grey (x, y) is equal to MAX (grey (x + a, y + a), grey (x-a, y-a)); when the mark of the pixel point (x, y) in the mark bitmap is 3, the gray level of the grey (x, y) is equal to MAX (grey (x, y + a), grey (x, y-a)); when the mark of the pixel point (x, y) in the mark bitmap is 3, the gray level of the grey (x, y) is equal to MAX (grey (x + a, y-a), grey (x-a, y + a)). The noise point can be removed through the step, and the defect false detection caused by the noise point is avoided.
And (4) subtracting the graph obtained in the step (108) from the graph obtained in the step (so as to obtain a defect response graph, namely a third image. The defect response is shown in fig. 6, and the brightest point in fig. 6 is the defect.
And step 110, obtaining the defect position from the third image.
Only the white point needs to be identified in this step to locate the defect. After the location of the defect is determined, a mark may be made on the artwork.
It can be known from the above embodiments that the edge image is determined by the first image and the second image obtained by the offset subtraction, the edge defect in the image can be rapidly extracted, multi-directional filtering is performed by the rectangular filtering kernel, the pixel points are classified and labeled according to the filtering results, the edge image is expanded based on the classification labels, and then compared with the original image, the unilateral edge pixel defect image with the maximum value is extracted by utilizing the characteristic that only the maximum value point is the same as the original image during the expansion processing, the unilateral edge pixel defect image is expanded and corroded and then subtracted from the edge image, and the response of the defect, that is, the third image, can be obtained, the position of the defect can be obtained by analyzing the third image, and the scheme can accurately extract the tiny defect at the edge of the display screen.
In some embodiments, the obtaining of the defect position from the third image specifically includes:
performing binary segmentation on the third image according to a segmentation threshold value to obtain a binary image;
and obtaining the defect position according to the position of the pixel point with the numerical value of 255 in the binary image.
In the step, binary segmentation is performed through a certain threshold, most of noise can be eliminated, the position of the defect can be accurately positioned, and the detection precision is improved.
In some embodiments, obtaining an edge image of a display screen in the image to be detected according to the first image and the second image specifically includes:
and calculating each pixel point value in the edge image according to the first image and the second image, wherein each pixel point value in the edge image is equal to the square root of the sum of the squares of the gray value of the pixel point in the first image and the gray value in the second image.
It is understood that, in this embodiment, the corresponding points of the images obtained by subtracting the two misalignment values are squared and added to form root signs, so that negative numbers can be converted into positive numbers, and in other embodiments, absolute value operations can be performed and then the addition is performed. The embodiment utilizes the characteristic of dislocation subtraction, and can well extract the edge image.
In some embodiments, the subtraction of the line-wise misalignment between the image to be measured and the image to be measured is performed to obtain a first image, specifically:
subtracting the gray value of the pixel point in the nth row in the image to be detected from the gray value of the pixel point in the same row in the (n + r) th row to be used as the gray value of the pixel point in the nth row in the first image;
and the image to be detected are subjected to longitudinal dislocation subtraction to obtain a second image, which specifically comprises the following steps:
subtracting the gray value of the nth row of pixel points in the image to be detected from the gray value of the n + r row of pixel points in the same row to be used as the gray value of the nth row of pixel points in the second image;
wherein n and r are positive integers. Wherein r can be 4-10.
The embodiment utilizes the characteristic of similar pixel point approximation, so that for the pixel points close to the edge, the dislocation addition of the pixel points can obtain a larger value. Therefore, by such a misalignment subtraction method, an edge image in which an edge can be emphasized can be simply obtained.
In some embodiments, the filtering the edge image by using a plurality of rectangular filtering kernels with different angles to obtain a plurality of filtered images includes:
the edge images are filtered by 12 rectangular filter kernels with directions of 0 °,15 °, 30 °, 45 °,60 °, 75 °,90 °,105 °,120 °, 135 °,150 °,165 °, to obtain 12 filtered images.
The filter of limited a plurality of angles is adopted to carry out filtering to this embodiment, has catered for the shape characteristics of display screen in fact, and the main part of display screen is the rectangle, and the periphery is the fillet generally, therefore, above-mentioned angle just in time can filter out the edge betterly.
In some embodiments, the classifying and marking each target pixel point according to a maximum value of the target pixel point in the edge image in each filtered image specifically includes:
establishing a mark bitmap with the same size as the image to be detected;
searching the maximum value of each pixel point in 12 filtered images;
when the maximum value of the pixel point appears in a filtering picture with the filtering direction of 0 degrees, 15 degrees or 165 degrees, marking the pixel point as a first value in the mark bitmap;
when the maximum value of the pixel point appears in a filtering picture with the filtering direction of 30 degrees, 45 degrees or 60 degrees, marking the pixel point as a second value in the mark bitmap;
when the maximum value of the pixel point appears in a filtering picture with the filtering direction of 75 degrees, 90 degrees or 105 degrees, marking the pixel point as a third value in the mark bitmap;
and when the maximum value of the pixel point appears in the filtering picture with the filtering direction of 120 degrees, 135 degrees or 150 degrees, marking the pixel point as a fourth value in the mark bitmap.
In the step, the positions are marked based on the maximum values of the pixel points in the plurality of filtered images, so that the identification of the image edge can be greatly simplified, as shown in fig. 4, and a basis can be provided for the selection of a filter in the subsequent step. The marking method of the step is simple and easy to realize.
In some embodiments, the target pixel point is a pixel point forming an edge in the edge image;
the selecting one of rectangular expansion structural elements with different directions to perform expansion processing on the target pixel points according to the mark of each target pixel point to obtain an expanded image includes:
performing expansion processing on all the target pixel points to obtain an expanded image, wherein:
when the mark of the target pixel is a first value, selecting a rectangular expansion structural element with the direction of 90 degrees to perform expansion processing on the target pixel point;
when the mark of the target pixel is a second value, selecting a rectangular expansion structural element with the direction of 45 degrees to perform expansion processing on the target pixel point;
when the mark of the target pixel is a third value, selecting a rectangular expansion structural element with the direction of 0 degree to perform expansion processing on the target pixel point;
and when the mark of the target pixel is a fourth value, selecting a rectangular expansion structural element with the direction of 135 degrees to perform expansion processing on the target pixel.
In some embodiments, the sequentially performing the element expansion and the element corrosion on the single-edge pixel defect map includes:
and performing element expansion on the single-edge pixel defect map by using the structural elements with the size of 3 x 3, and then performing corrosion treatment on the single-edge pixel defect map subjected to element expansion treatment by using the structural elements with the size of 9 x 9.
In some embodiments, after the single-edge pixel defect map is sequentially subjected to element expansion and element corrosion, performing a difference between the single-edge pixel defect map and the edge image to obtain a third image, including:
sequentially carrying out element expansion and element corrosion treatment on the single-edge pixel defect map to obtain a fourth image;
carrying out gray value replacement on pixel points in the fourth image according to the mark bitmap to obtain a fifth image;
obtaining a third image by subtracting the fifth image from the edge image;
wherein the gray value replacement specifically comprises:
when the mark of the pixel point (x, y) in the mark bitmap is a first value, the gray level of the grey (x, y) is equal to MAX (grey (x + a, y), grey (x-a, y));
when the mark of the pixel point (x, y) in the mark bitmap is a second value, the gray level of the grey (x, y) is equal to MAX (grey (x + a, y + a), grey (x-a, y-a));
when the mark of the pixel point (x, y) in the mark bitmap is a third value, the gray level of the grey (x, y) is equal to MAX (grey (x, y + a), grey (x, y-a));
when the mark of the pixel point (x, y) in the mark bitmap is a fourth value, the gray level of the grey (x, y) is equal to MAX (grey (x + a, y-a), grey (x-a, y + a)).
Wherein, the grey () represents the gray value of the pixel point.
By the method, noise generated by expansion corrosion can be effectively removed, and defect false detection caused by the noise is avoided.
The embodiment discloses a display screen edge defect detection, include:
carrying out a procedure;
a memory for storing the program;
and the processor is used for loading the program to execute the display screen edge defect detection method.
It is understood that the embodiment and the method embodiment can achieve the same technical effects.
From the above description of the embodiments, it is obvious for those skilled in the art that the present application can be implemented by software and necessary general hardware, and certainly can be implemented by hardware, but the former is a better embodiment in many cases. Based on such understanding, the technical solutions of the present application may be embodied in the form of a software product, which may be stored in a computer-readable storage medium, such as a floppy disk, a Read-Only Memory (ROM), a Random Access Memory (RAM), a FLASH Memory (FLASH), a hard disk or an optical disk of a computer, and includes several instructions for enabling a computer device (which may be a personal computer, a server, or a network device) to execute the methods described in the embodiments of the present application.
It is to be noted that the foregoing is only illustrative of the preferred embodiments of the present application and the technical principles employed. It will be understood by those skilled in the art that the present application is not limited to the particular embodiments described herein, but is capable of various obvious changes, rearrangements and substitutions as will now become apparent to those skilled in the art without departing from the scope of the application. Therefore, although the present application has been described in more detail with reference to the above embodiments, the present application is not limited to the above embodiments, and may include other equivalent embodiments without departing from the spirit of the present application, and the scope of the present application is determined by the scope of the appended claims.