CN-121998940-A - Blue film micro scratch detection method based on image enhancement
Abstract
The invention relates to the technical field of image processing and machine vision detection, and discloses a blue film micro scratch detection method based on image enhancement. Collecting blue film curved glass color image and graying to obtain gray image matrix, dividing gray image into subareas, setting gamma index according to the ratio of subarea to global average gray, making gamma mapping to pixels in the subarea to produce enhanced gray image, constructing neighborhood for every pixel in the enhanced gray image, producing differential image by using difference of neighborhood average gray and enhancement value of said pixel, making open operation and top cap operation on the differential image to inhibit background and retain fine linear trace, calculating brightness difference of left and right and upper and lower adjacent pixels in top cap image to form directional response matrix, taking larger value of every pixel to obtain comprehensive linear response matrix, making normalization and self-adaption threshold segmentation to obtain scratch binary image, and correspondent to original color image and using red mark scratch.
Inventors
- HE JICHAO
- ZHANG JIALEI
- SUN JUN
Assignees
- 江阴市江泰高分子新材料有限公司
Dates
- Publication Date
- 20260508
- Application Date
- 20260127
Claims (9)
- 1. The blue film micro scratch detection method based on image enhancement is characterized by comprising the following steps of: Performing image acquisition and graying processing, establishing a pixel-level two-dimensional coordinate system, acquiring an original color image matrix and generating a gray image matrix; Dividing a gray image matrix into a plurality of subareas in the horizontal direction and the vertical direction, acquiring an average gray brightness value of each subarea and a global average gray brightness value of the whole gray image matrix, and setting a gamma conversion index for each subarea according to the ratio of the average gray brightness value and the global average gray brightness value; Performing nonlinear brightness mapping on each pixel in the gray image matrix according to the gamma conversion index of the subarea where the pixel is positioned to obtain an enhanced gray image matrix; in the enhanced gray image matrix, constructing a neighborhood with limited size around each pixel, acquiring a neighborhood average gray brightness value, and generating a differential image matrix according to the difference between the enhanced gray brightness value and the neighborhood average gray brightness value; Introducing structural element open operation on the differential image matrix, obtaining a corrosion result image matrix and an open operation result image matrix, and constructing a top hat image matrix according to the difference value of the corrosion result image matrix and the open operation result image matrix; The top hat image matrix is used as input to obtain top hat brightness difference between the left and right adjacent pixels and the upper and lower adjacent pixels to form a horizontal direction response matrix and a vertical direction response matrix; Based on the horizontal direction response matrix and the vertical direction response matrix, selecting a larger response value in each pixel position to form a comprehensive linear response matrix, acquiring a maximum response value in the comprehensive linear response matrix, executing normalization processing on each pixel response value, and setting a normalization response threshold according to the normalization response value distribution so as to obtain a scratch binary image matrix; And (3) corresponding the scratch binary image matrix with the original color image matrix pixel by pixel, constructing an output color image matrix, and marking the positions of the scratch pixels with red to obtain the output color image matrix.
- 2. The method for detecting the fine scratches of the blue film based on image enhancement according to claim 1, wherein said performing image acquisition and graying processes establishes a pixel-level two-dimensional coordinate system, acquires an original color image matrix and generates a gray image matrix, and specifically comprises: establishing a two-dimensional discrete pixel coordinate system, selecting the pixel center of the upper left corner of an original color image matrix as a coordinate origin, setting the horizontal direction as a column index, setting the positive direction towards the right side of the image, setting the vertical direction as a row index, and setting the positive direction towards the lower side of the image; acquiring the total number of rows of the original color image matrix as a row number parameter, and acquiring the total number of columns of the original color image matrix as a column number parameter; Converting and storing an original color image acquired by a handheld detection device into an original color image matrix, wherein the original color image matrix comprises three channel data of a red channel, a green channel and a blue channel, and the channel data are arranged according to a row index and a column index; And for each pixel position in the original color image matrix, reading the brightness values of the current pixel in the red channel, the green channel and the blue channel from the original color image matrix, dividing the three channel brightness by the channel number after adding, obtaining the gray brightness value of the current pixel, and organizing the gray brightness values of all the pixels into a gray image matrix according to the corresponding row index and the column index.
- 3. The method for detecting the fine scratches of the blue film based on image enhancement according to claim 2, wherein the dividing the gray image matrix into a plurality of sub-areas in the horizontal direction and the vertical direction, obtaining the average gray brightness value of the sub-areas of each sub-area and the global average gray brightness value of the whole gray image matrix, and setting a gamma conversion index for each sub-area according to the ratio of the average gray brightness value and the global average gray brightness value of the whole gray image matrix, specifically comprising: Setting the number of subareas divided by a gray image matrix in the horizontal direction, setting the number of subareas divided by the gray image matrix in the vertical direction, dividing the gray image matrix into a plurality of non-overlapped rectangular subareas according to the line number parameter and the column number parameter and the equal interval dividing mode of the line index and the column index, and marking each subarea by the numbers in the vertical direction and the horizontal direction; setting a start index and an end index for each sub-region in the row index direction and the column index direction according to the serial numbers, forming an index range of a continuous pixel row and a continuous pixel column covered by the corresponding sub-region, collecting all pixel positions in the index range limited by the start index and the end index, and constructing a pixel index set in the sub-region; for each sub-region, traversing pixel positions one by one in a pixel index set, reading corresponding gray brightness values from a gray image matrix, accumulating the gray brightness values of all pixels in the corresponding sub-region, dividing the accumulated gray brightness values by the number of pixels, and obtaining a sub-region average gray brightness value of the corresponding sub-region; Traversing all pixel positions in all line index and column index ranges for the whole gray image matrix, reading corresponding gray brightness values, accumulating the gray brightness values of all pixels, dividing the accumulated gray brightness values by the total pixel number, and obtaining a global average gray brightness value of the whole gray image matrix; And for each sub-region, calculating a gamma conversion index according to the proportional relation between the sub-region average gray brightness value of the corresponding sub-region and the global average gray brightness value of the whole gray image matrix, and storing the gamma conversion index in association with the corresponding sub-region number.
- 4. The method for detecting blue film micro scratches based on image enhancement according to claim 3, wherein each pixel in the gray scale image matrix performs nonlinear brightness mapping according to a gamma transformation index of a sub-region where the pixel is located, to obtain an enhanced gray scale image matrix, specifically comprising: Establishing an enhanced gray image matrix which is the same as the gray image matrix in the number of rows and columns; Reading a corresponding gamma conversion index from the gamma conversion index records stored in an associated manner according to the number of the sub-region where the pixel is located for each pixel position in the gray image matrix; And normalizing the gray brightness value of each pixel according to a preset gray range, performing power operation mapping on the normalized value according to a gamma transformation exponent, performing inverse normalization according to the preset gray range to obtain the enhanced gray brightness value of the current pixel, and writing the enhanced gray brightness values of all pixels into an enhanced gray image matrix according to an original row index and a column index.
- 5. The method for detecting blue film micro scratches based on image enhancement according to claim 4, wherein in the enhanced gray image matrix, a neighborhood of a defined size is constructed around each pixel, a neighborhood average gray luminance value is obtained, and a differential image matrix is generated according to a difference between the enhanced gray luminance value and the neighborhood average gray luminance value, and the method specifically comprises: For each pixel position in the enhanced gray image matrix, respectively expanding a pixel step length forwards and backwards in the row index direction and the column index direction, and cutting off at a position exceeding the boundary of the enhanced gray image matrix to obtain a neighborhood pixel coordinate set which surrounds the current pixel and is respectively expanded by one pixel in the row direction and the column direction; The pixel positions are traversed one by one in a neighborhood pixel coordinate set, the enhanced gray scale brightness values of corresponding pixels are read from the enhanced gray scale image matrix, the enhanced gray scale brightness values of all pixels in the neighborhood are accumulated and divided by the number of the neighborhood pixels, the neighborhood average gray scale brightness value of the current pixel neighborhood is obtained, and the neighborhood average gray scale brightness value is written into the position corresponding to the current pixel position in the local average image matrix; For each pixel position, reading an enhanced gray brightness value from the enhanced gray image matrix, reading a neighborhood average gray brightness value from the local average image matrix, calculating a difference value between the two gray brightness values and taking an absolute value to obtain a differential brightness value, and organizing the differential brightness values of all pixels into a differential image matrix according to a row index and a column index.
- 6. The method for detecting the micro scratches on the blue film based on the image enhancement according to claim 5, wherein the step of introducing a structural element on operation to the differential image matrix to obtain an image matrix of a corrosion result and an image matrix of an on operation result, and constructing a top hat image matrix according to the difference value of the two image matrices, comprises the following steps: establishing a structural element offset set, wherein the structural element adopts a circular structural element with pixels as units and two radiuses as pixels, and each element in the set comprises a row direction offset and a column direction offset which are integers; For each pixel position in the differential image matrix, screening offset which does not exceed the range of the row number and the column number of the differential image matrix on the row index and the column index according to the structure element offset set and the boundary position of the differential image matrix, and generating a structure element offset subset corresponding to the current pixel position; For each pixel position, reading the corresponding differential brightness value from the differential image matrix in all pixel positions covered by the structural element offset subset, and selecting the minimum value as the pixel value of the corrosion result image matrix at the current pixel position; Performing expansion operation on the corrosion result image matrix, and for each pixel position, reading pixel values of all covered pixel positions from the corrosion result image matrix according to the structure element offset sub-set, and selecting the maximum value as the pixel value of the open operation result image matrix at the current pixel position; For each pixel position, reading differential brightness values from the differential image matrix, reading corresponding pixel values from the open operation result image matrix, subtracting the open operation result pixel values from the differential brightness values to obtain top cap brightness values, and organizing all the top cap brightness values into a top cap image matrix according to row indexes and column indexes.
- 7. The method for detecting the fine scratches of the blue film based on image enhancement according to claim 6, wherein the method for obtaining the top hat brightness difference between the left and right adjacent pixels and the upper and lower adjacent pixels by using the top hat image matrix as input to form a horizontal direction response matrix and a vertical direction response matrix comprises the following steps: Establishing a horizontal response matrix based on the top hat image matrix, and setting the horizontal response value of all pixels in a single column to be zero when the top hat image matrix only comprises one column of pixels; when the top hat image matrix comprises a plurality of columns of pixels, calculating the absolute value of the top hat brightness difference between the current pixel and the right adjacent pixel as the horizontal direction response value of the current pixel for each pixel in each column except the last column; Establishing a vertical response matrix based on the top hat image matrix, and setting the vertical response value of all pixels in a single row to be zero when the top hat image matrix only comprises one row of pixels; when the top hat image matrix comprises a plurality of rows of pixels, calculating the absolute value of the top hat brightness difference between the current pixel and the pixels in the same column in the next row for each pixel except the last row to be used as the vertical direction response value of the current pixel; and reading corresponding response values from the horizontal response matrix and the vertical response matrix at each pixel position, and selecting the larger response value of the horizontal response matrix and the vertical response matrix as the response value of the comprehensive linear response matrix at the current pixel position to construct the comprehensive linear response matrix.
- 8. The method for detecting blue film micro scratches based on image enhancement according to claim 7, wherein the method for detecting blue film micro scratches based on horizontal and vertical response matrices comprises selecting a larger response value from each pixel position to form a comprehensive linear response matrix, obtaining a maximum response value from the comprehensive linear response matrix, performing normalization processing on each pixel response value, and setting a normalization response threshold according to a normalization response value distribution, thereby obtaining a scratch binary image matrix, and the method comprises the following steps: Traversing all pixel positions in the comprehensive linear response matrix, reading the comprehensive linear response value of each pixel, and obtaining the maximum response value; Dividing the integrated linear response value by the maximum response value to obtain a normalized response value for each pixel when the maximum response value is greater than zero, setting the normalized response value of all pixels to zero when the maximum response value is equal to zero, and constructing a normalized response matrix which is the same as the integrated linear response matrix in size; the normalized response values of all pixel positions in the normalized response matrix form a finite real number set, elements in the finite real number set are ordered from small to large according to the values, and the elements positioned in the middle position after the ordering are obtained to serve as normalized response thresholds; Comparing the normalized response value with the normalized response threshold value for each pixel position, setting the value of the scratch binary image matrix at the current pixel position as one when the normalized response value is larger than the threshold value, and setting the value of the scratch binary image matrix at the current pixel position as zero when the normalized response value is smaller than or equal to the threshold value, so as to construct the scratch binary image matrix.
- 9. The method for detecting the fine scratches of the blue film based on image enhancement according to claim 8, wherein the step of constructing an output color image matrix by pixel-wise correspondence between the scratch binary image matrix and the original color image matrix, and marking the positions of the scratch pixels with red color to obtain the output color image matrix comprises the following steps: establishing an output color image matrix with the same row number and column number as the original color image matrix, and setting a brightness storage unit of a red channel, a green channel and a blue channel at each pixel position; Reading the value of the current pixel position from the scratch binary image matrix for each pixel position, setting the brightness of a red channel of the output color image matrix at the current pixel position to be a preset maximum brightness, setting the brightness of a green channel to be a preset minimum brightness and setting the brightness of a blue channel to be a preset minimum brightness when the value is one; when the value of the scratch binary image matrix is zero, reading the red channel brightness, the green channel brightness and the blue channel brightness of the current pixel position from the original color image matrix, and setting three channel brightness of the output color image matrix at the current pixel position as corresponding original brightness values respectively; And taking the output color image matrix as a blue film micro scratch detection result image matrix, and forming a red scratch mark area at a pixel position with a value of one in the scratch binary image matrix.
Description
Blue film micro scratch detection method based on image enhancement Technical Field The invention relates to the technical field of image processing and machine vision detection, in particular to a blue film micro scratch detection method based on image enhancement. Background With the large number of applications of intelligent terminals, vehicle-mounted displays and precision optical devices, the surface of curved glass is usually covered with a layer of blue protective film before delivery for preventing scratches during assembly and transportation. In order to ensure the appearance quality and optical performance of the product, the blue film covered curved glass needs to be subjected to fine scratch detection on a production line. Currently, the industrial site generally adopts modes such as manual visual inspection, image detection of simple threshold segmentation, defect identification based on deep learning and the like. The manual visual detection relies on experience of operators, fatigue and subjective deviation are easy to generate under the conditions of blue film color interference, complex reflected light and long working time, micro scratches with extremely small width and extremely low contrast are often difficult to discover in time, and the consistency and repeatability of detection results are poor. In the traditional digital image processing method, means such as global gray linear transformation, fixed threshold segmentation or simple edge operators are mostly adopted, the method is generally established on the premise of supposing that illumination is uniform and background is simple, when the method is applied to a curved glass blue film scene, the method is easily influenced by non-uniform incident light, local anti-light spots and self-textures of the blue film caused by curvature, and the problems that the contrast between scratches and background is insufficient, noise points are misjudged to be defects, local regions are overexposed or underexposed and the like occur. In recent years, surface defect detection schemes based on deep neural networks have also appeared, and defects are classified or segmented end to end through a convolutional network. Such methods generally require a large number of labeled samples for training, have complex network structures and parameters, have high requirements on computing resources and storage space, and are unfavorable for deployment on handheld detection devices or embedded terminals. In addition, the internal feature extraction process of the deep learning model is difficult to directly describe in an explicit mathematical form, the suitability of the deep learning model to a specific blue film curved surface scene depends on a large number of experimental parameters, and when imaging conditions or product models change, the problem of unstable detection performance is easy to occur. Therefore, the scheme aims to provide an image enhancement-based blue film micro scratch detection method, which is characterized in that firstly, gray scale contrast is enhanced through partition gamma transformation and nonlinear mapping, secondly, a local neighborhood difference and morphological top hat operation are utilized to highlight a weak scratch trace, then, contour information is extracted through horizontal and vertical direction response, a binarization scratch graph is obtained through normalization and threshold segmentation, and finally, a detection result is overlapped with a red mark to a color image, so that high-sensitivity and low-error detection of scratch pixels is realized. Disclosure of Invention The invention provides a blue film micro scratch detection method based on image enhancement, which facilitates solving the problems mentioned in the background art. The invention provides a blue film micro scratch detection method based on image enhancement, which comprises the following steps: Performing image acquisition and graying processing, establishing a pixel-level two-dimensional coordinate system, acquiring an original color image matrix and generating a gray image matrix; Dividing a gray image matrix into a plurality of subareas in the horizontal direction and the vertical direction, acquiring an average gray brightness value of each subarea and a global average gray brightness value of the whole gray image matrix, and setting a gamma conversion index for each subarea according to the ratio of the average gray brightness value and the global average gray brightness value; Performing nonlinear brightness mapping on each pixel in the gray image matrix according to the gamma conversion index of the subarea where the pixel is positioned to obtain an enhanced gray image matrix; in the enhanced gray image matrix, constructing a neighborhood with limited size around each pixel, acquiring a neighborhood average gray brightness value, and generating a differential image matrix according to the difference between the enhanced gray brightne