Scratch detection method, device and equipment for transparent film and medium
By combining image multiplication processing and grayscale dynamic range mapping with Sobel edge detection, Gaussian filtering, and adaptive segmentation thresholding, the problems of low contrast and noise interference in transparent film scratch detection are solved, achieving efficient and accurate scratch detection.
Patent Information
- Application Number
- CN202511395411.X
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-09-28
- Publication Date
- 2025-11-04
- Estimated Expiration
- 2045-09-28
AI Technical Summary
Existing methods for detecting scratches on transparent films have shortcomings in terms of detection accuracy, adaptability, and reliability. In particular, they are difficult to effectively improve the contrast between scratched areas and normal areas, and are easily affected by noise interference and uneven lighting, leading to false detections and missed detections.
By employing image multiplication processing and grayscale dynamic range mapping techniques, combined with Sobel edge detection and Gaussian filtering, and through dual-path processing of linear and logarithmic transformations, the scratch region is accurately located using an adaptive segmentation threshold, reducing noise interference and adapting to different production conditions.
It significantly improves the accuracy and reliability of scratch detection on transparent films, enhances the contrast of scratch edges, reduces the false detection rate, improves detection efficiency, and adapts to the control needs under different production conditions.
Smart Images

Figure CN120894353A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of visual inspection technology, specifically to a method, apparatus, equipment, and medium for scratch detection of transparent films. Background Technology
[0002] Transparent films are widely used in many industries due to their lightweight, flexibility, and high light transmittance. They are a crucial component in the production of flexible screen protectors and are commonly used in foldable and curved screens. Scratches on the transparent film can affect the overall display quality, therefore scratch inspection of the transparent film is necessary.
[0003] Scratch detection of transparent films is a crucial step in quality control during the production process. Traditional detection methods primarily rely on manual visual inspection, which is inefficient, lacks precision, and is susceptible to subjective factors, failing to meet the demands of modern industrial production for efficient and high-precision testing. Currently, scratch detection of transparent films mainly faces the following technical challenges: (1) Low contrast problem: The scratches on the transparent film are close to the refractive index of the substrate, resulting in extremely low contrast under conventional optical imaging. Slight scratches are difficult to extract using traditional threshold segmentation methods. (2) Noise interference: Dust, ripples or uneven lighting on the surface of the thin film can produce false defect signals, which can easily lead to an increase in the false detection rate; (3) Insufficient adaptability: Existing methods are difficult to detect obvious scratches and fine scratches at the same time, and lack a defect enhancement mechanism for multi-feature fusion.
[0004] With the development of image processing technology, automated detection methods based on machine vision have gradually become a research hotspot. For example, Chinese patent document CN119273684A proposes a machine vision-based method for detecting defects on the surface of a covering film. This method gradually optimizes the segmentation threshold through iterative updates of the Otsu algorithm, calculates the scratch segmentation coefficient and the quantized value of the segmentation effect using fitting curves and clustering techniques, and selects the optimal segmentation threshold for image segmentation. However, this method mainly targets overall defects in the film and fails to specifically optimize for scratches, a common and important defect type.
[0005] Chinese patent document CN117218122B proposes a method for detecting the quality of watch cases based on image data. This method improves the nonmaximum suppression of the Canny operator, analyzes the gradient weights of each pixel in different directions, and adjusts the gradient magnitude by considering the degree of illumination influence. This improves the sensitivity of edge detection to scratched areas and reduces the sensitivity to reflective areas. However, this method is quite sensitive to image contrast and noise, and is prone to false positives and false negatives.
[0006] Chinese patent document CN117058137B describes a visual inspection method for the production quality of laminated glass. This method uses a sliding window technique to perform edge detection on the grayscale image of the laminated glass, obtains an initial gradient segmentation threshold for each pixel, and corrects the threshold based on the degree of difference in the gradient segmentation threshold. The corrected threshold is then used to identify the edge pixels of bubbles, thereby completing the inspection of the laminated glass production quality. However, the threshold selection in this method mainly relies on experience, lacks adaptability, and is difficult to adapt to the inspection needs under different production conditions.
[0007] In summary, existing scratch detection methods still have room for improvement in terms of detection accuracy, adaptability, and reliability. Especially for transparent films, which have low contrast and indistinct scratch features, effectively improving the contrast between the scratched area and the normal area, and reducing false positives and false negatives, is a pressing technical challenge that needs to be addressed. Summary of the Invention
[0008] The main objective of this invention is to provide a scratch detection method for transparent films, which can achieve accurate and efficient automatic detection of scratch defects of different degrees on the surface of transparent films during the manufacturing process, greatly improving the efficiency of scratch defect detection and the accuracy and reliability of the detection results.
[0009] This invention achieves the above objective through the following technical solution: a scratch detection method for transparent films, comprising the following steps: S1: Acquire several grayscale images of transparent films; S2: Perform image multiplication on the grayscale image of the transparent film to obtain the first target image. Map the minimum and maximum grayscale values of the pixels in the first target image to a new grayscale dynamic range to obtain the second target image. Perform threshold segmentation on the second target image to extract the effective product area and map it onto the grayscale image of the transparent film to obtain the target grayscale image. S3: Perform Sobel edge detection on the pixels in the target grayscale image, calculate the gradient magnitude in the horizontal and vertical directions respectively, and synthesize the gradient magnitudes in the two directions to obtain the edge gradient image; S4: After performing Gaussian filtering on the edge gradient image, calculate the overall image grayscale mean. Determine the first grayscale threshold and the second grayscale threshold based on the overall image grayscale mean. Use the first grayscale threshold and the second grayscale threshold to perform grayscale linear transformation on the edge gradient image to obtain the first salient image. S5: Based on the pixel grayscale values in the target grayscale image, perform a logarithmic transformation on the target grayscale image to obtain the second salient image; S6: Calculate the mean gray value of the first salient image and the second salient image respectively, and determine the adaptive segmentation threshold of the first salient image and the second salient image based on the mean gray value of the two images and the preset salient threshold. S7: The first salient image and the second salient image are subjected to threshold segmentation processing using the adaptive segmentation threshold. The intersection of the defect regions extracted from the two is processed to obtain the initial scratch region. The initial scratch region is then filtered according to the preset judgment conditions to obtain the final scratch region.
[0010] Preferably, in step S2, obtaining the first target image includes: Let any grayscale image of a transparent thin film be... The position of each pixel in the grayscale image of the transparent film The grayscale value is multiplied by itself, and the result is scaled and shifted to obtain the first target image. The calculation formula is: , In the formula This indicates that the output of the first target image is in pixels. The grayscale value at the location, This indicates that the grayscale image of the input transparent film is in pixels. The grayscale value at the location, Indicates the scaling factor. Indicates the offset; If the calculated grayscale value of a pixel in the first target image is lower or higher than the value range of the current image data type, then the grayscale value is the minimum or maximum value of that data type.
[0011] Preferably, in step S2, obtaining the second target image includes: For any first target image First, iterate through all pixels in the first target image to obtain the minimum and maximum grayscale values currently existing in the image. Then, map these minimum and maximum grayscale values to a new grayscale dynamic range. The new grayscale dynamic range is selected from the minimum value of 0 and the maximum value of 255 supported by the current image data type. Then, transform each pixel in the first target image to obtain the second target image. The calculation formula is: , , , In the formula Indicates the second target image in pixels grayscale value at the location, Indicates the first target image in pixels The grayscale value at the location, This represents the minimum grayscale value of a pixel in the first target image. This represents the maximum grayscale value of a pixel in the first target image.
[0012] Preferably, in step S3, obtaining the edge gradient image includes: For any second target image, threshold segmentation is performed to extract the effective product region, which is then mapped onto the grayscale image of the transparent film to obtain the target grayscale image. Based on the target grayscale image, a fixed-size convolution kernel is used to traverse the entire image region, and the Sobel operator is used for edge detection. The gradient magnitude of each pixel in the horizontal and vertical directions is calculated separately. The edge gradient image is obtained by weighting and summing the absolute values of the gradient magnitudes in the two directions. The synthesis method is as follows: , In the formula, Represents the edge gradient image at pixels The new gradient magnitude synthesized at the location, Indicates the weighting coefficient. Indicates the target grayscale image in pixels Calculate the gradient magnitude in the horizontal x-direction. Indicates the target grayscale image in pixels Calculate the gradient magnitude in the vertical direction y for the location.
[0013] Preferably, in step S4, obtaining the first salient image includes: For any edge gradient image, a Gaussian filter is applied to remove granular noise regions, resulting in a preprocessed image. The overall image grayscale mean (Mean) is calculated by iterating through all pixels of the preprocessed image. Based on this mean, a first grayscale threshold and a second grayscale threshold are determined. The first grayscale threshold, denoted as Mean-a, represents a number below the overall image grayscale mean by a constant 'a'. The second grayscale threshold, denoted as Mean+b, represents a number above the overall image grayscale mean by a constant 'b'. A linear grayscale transformation is then performed on the edge gradient image using these two thresholds, mapping it to the target grayscale range. The first salient image is obtained, and the calculation formula is: , In the formula This indicates that the first salient image is output in pixel grayscale values, Indicates the input edge gradient image in pixel grayscale values, This represents the first grayscale threshold. This indicates the second grayscale threshold. This represents the minimum grayscale value within the target grayscale range. This indicates the maximum grayscale value within the target grayscale range.
[0014] Preferably, in step S5, obtaining the second salient image includes: The second salient image is obtained by performing a logarithmic transformation on the grayscale values of all pixels in any of the target grayscale images. The calculation formula is as follows: , , In the formula, This indicates that the output of the second salient image is in The pixel grayscale value after logarithmic transformation Indicates the input target grayscale image in pixel grayscale values, This represents the maximum pixel grayscale value in the target grayscale image. Represents the normalization constant. Represents the base of the logarithm.
[0015] Preferably, in step S6, obtaining the adaptive segmentation threshold includes: Based on the first salient image and the second salient image, calculate the horizontal width of the first salient image, divide it into N image regions in the vertical direction, calculate the grayscale mean of each image region, and obtain the adaptive segmentation threshold of the current image region by adding the grayscale mean to the preset salient threshold. Iterate from the first image region to the Nth image region to obtain all the adaptive segmentation thresholds of the first salient image; similarly, obtain all the adaptive segmentation thresholds of the second salient image.
[0016] Preferably, in step S7, obtaining the final scratch area includes: Based on all adaptive segmentation thresholds of the first and second salient images obtained in step S6, threshold segmentation is performed on the image regions divided by the first and second salient images respectively. The intersection of all defect regions extracted from the first and second salient images is taken to obtain the initial scratch region. The initial scratch region is then filtered according to a preset judgment condition to obtain the final scratch region. The preset judgment condition is to judge by setting a scratch region area threshold. The area of all the obtained initial scratch regions is calculated in turn. If it is greater than or equal to the set scratch region area threshold, the scratch region is output; if it is lower than the set scratch region area threshold, the scratch region is not output.
[0017] Another object of the present invention is to provide a scratch detection device for transparent films, comprising: Image acquisition device, acquires several grayscale images of transparent thin films; The image multiplication processing module is configured to perform image multiplication processing on the acquired grayscale image of the transparent film to obtain a first target image, and to map the minimum and maximum grayscale values of the pixels in the first target image to a new grayscale dynamic range to obtain a second target image. The threshold segmentation extraction module is configured to perform threshold segmentation based on the second target image to extract the effective product area, and map it onto the grayscale image of the transparent film to obtain the target grayscale image. The edge detection module is configured to perform Sobel edge detection based on the pixels in the target grayscale image, calculate the gradient magnitude in the horizontal and vertical directions respectively, and synthesize the gradient magnitudes in the two directions to obtain the edge gradient image. The Gaussian filtering module is configured to perform Gaussian filtering on the edge gradient image, calculate the overall image grayscale mean, and determine the first grayscale threshold and the second grayscale threshold based on the overall image grayscale mean. The grayscale linear transformation processing module is configured to perform a grayscale linear transformation on the edge gradient image using the first grayscale threshold and the second grayscale threshold to obtain a first salient image; The logarithmic transformation processing module is configured to perform a logarithmic transformation on the target grayscale image based on the pixel grayscale values in the target grayscale image to obtain a second salient image; The adaptive segmentation threshold determination module is configured to calculate the gray-scale mean of the first salient image and the second salient image respectively, and determine the adaptive segmentation threshold of the first salient image and the second salient image based on the gray-scale mean of the two images and a preset salient threshold. The scratch extraction module is configured to perform threshold segmentation processing on the first salient image and the second salient image respectively using the adaptive segmentation threshold, and to obtain the initial scratch region by taking the intersection of the defect regions extracted from the two images. The final scratch region is obtained by filtering the initial scratch region according to the preset judgment conditions.
[0018] Another object of the present invention is to provide a scratch detection device for transparent films, comprising: Memory, used to store computer programs; A processor for executing a computer program to implement the scratch detection method for transparent films as described above.
[0019] Compared with existing technologies, the beneficial effects of the present invention—a method, apparatus, device, and medium for scratch detection of transparent films—are as follows: Different degrees of scratch defects on the surface of a transparent film will present different image features in an image. Obvious scratch areas have high contrast, while minor scratch defects have low contrast, making them difficult to segment effectively using traditional thresholding methods. The target grayscale image of the present invention is processed sequentially through two image processing methods to obtain a first salient image and a second salient image. This improves the contrast between scratch defect areas and normal areas in the corresponding images. The intersection of the defect areas extracted from the first and second salient images is taken as the scratch area, improving the accuracy and reliability of the scratch detection results for transparent films. Screening based on preset judgment conditions can meet the control requirements under different actual production conditions. Specifically: (1) Enhanced defect contrast: By using image multiplication processing and grayscale dynamic range mapping technology, the grayscale difference between the transparent film area and the background is effectively widened. Combined with Sobel edge detection and Gaussian filtering gradient enhancement, the contrast of scratch edges is significantly improved, solving the problem that traditional methods are not sensitive to low-contrast scratch detection. (2) Multimodal image fusion: The linear transformation and logarithmic transformation are used for dual-path processing, which respectively compresses the bright area and expands the details of the dark area. This overcomes the differences in image quality caused by uneven illumination and material warping, so that the scratch features of different brightness areas are enhanced and the detection robustness is significantly improved. (3) Adaptive threshold segmentation: By calculating the gray mean value by partitioning and combining it with dynamic threshold adjustment, false detection caused by uneven gray value in the direction of film movement is effectively suppressed. At the same time, by taking the intersection of the two significant image defect regions, noise interference is further eliminated, and the scratch positioning accuracy is improved. (4) Strong process compatibility: The preset judgment conditions support flexible configuration (such as area threshold), which can adapt to the different control needs of different production lines for slight / severe scratches. Its adaptability to actual application scenarios is better than the fixed threshold segmentation method. (5) Optimization of computational efficiency: By reducing redundant computation through background removal and partitioning, the algorithm execution efficiency is improved while ensuring detection accuracy, making it more suitable for industrial real-time detection scenarios. Attached Figure Description
[0020] Figure 1 This is a schematic flowchart of the scratch detection method for transparent films in Embodiment 1 of the present invention; Figure 2 This is a schematic diagram of the scratch detection device for transparent films in Embodiment 2 of the present invention. Detailed Implementation
[0021] To further illustrate the technical means and effects adopted by the present invention to achieve its intended purpose, the following, in conjunction with the accompanying drawings and preferred embodiments, details the specific implementation, structure, features, and effects of a scratch detection method for transparent films according to the present invention. In the following description, different "one embodiment" or "another embodiment" do not necessarily refer to the same embodiment. Furthermore, specific features, structures, or characteristics in one or more embodiments can be combined in any suitable form.
[0022] Unless otherwise defined, all technical and scientific terms used herein have the same meaning as commonly understood by one of ordinary skill in the art to which this invention pertains.
[0023] Example 1: The surface of transparent films may have scratches of varying degrees, resulting in different defect features in images. Slight scratches exhibit low contrast in images, and traditional methods using threshold segmentation to process transparent film images cannot effectively segment these minor scratches. Therefore, this embodiment proposes a scratch detection method for transparent films. The specific solution of the scratch detection method for transparent films provided by this invention is described below in detail with reference to the accompanying drawings.
[0024] Please see Figure 1 The diagram illustrates a flowchart of a scratch detection method for transparent films according to an embodiment of the present invention, the method comprising the following steps: Step S1: Acquire several grayscale images of the transparent film using a camera. The specific process is as follows: Several images of a transparent film are captured using an industrial camera. Each captured image is then converted to grayscale to obtain several grayscale images, which are denoted as the transparent film grayscale images. Grayscale conversion is a well-known technique and will not be described in detail in this embodiment.
[0025] Thus, the grayscale images of all transparent films have been obtained using the methods described above.
[0026] Step S2: Perform image multiplication processing on the acquired transparent film grayscale image to obtain a new image, which is denoted as the first target image. Map the minimum and maximum grayscale values of the pixels in the first target image to a new grayscale dynamic range to obtain a new image, which is denoted as the second target image. Perform threshold segmentation on the second target image to extract the effective product area and map it onto the transparent film grayscale image to obtain a new image, which is denoted as the target grayscale image.
[0027] It should be noted that the transparent film is made by laminating multiple layers of transparent optical films. In the grayscale image captured by the industrial camera, the grayscale difference between the actual product image area and the background area of the transparent film is very small. To effectively process the product area, it is necessary to remove the excess background area, increase the contrast difference between the two, reduce unnecessary data calculations, and use the target grayscale image obtained from image processing for subsequent analysis and processing.
[0028] Specifically, taking any grayscale image of a transparent film as an example, the grayscale value corresponding to each pixel in the grayscale image of the transparent film is multiplied by itself, and the result of the multiplication is scaled and shifted to obtain a new image, which is denoted as the first target image. The specific calculation formula is as follows: ; In the formula This indicates that the output of the first target image is in pixels. The grayscale value at the location, This indicates that the grayscale image of the input transparent film is in pixels. The grayscale value at the location, This represents the scaling factor, with a value range of -255 to 255. This embodiment uses... Let's take an example to illustrate. This represents the offset, with a value ranging from -512 to 512. This embodiment uses... Taking this example, if the calculated grayscale value of a pixel in the first target image is lower or higher than the value range of the current image data type, the grayscale value will be forced to the minimum or maximum value of that data type. In this embodiment, the acquired image data type is byte, and the corresponding value range is 0~255. The grayscale value of pixels in the background area is fixed, while the grayscale value of pixels in the transparent film is changing. The first target image can highlight the difference in grayscale values between the two, emphasizing the actual product area of the transparent film, facilitating further processing. It should be noted that image multiplication is a known technique and will not be elaborated upon in this embodiment.
[0029] Furthermore, after acquiring the first target image, all pixels in the first target image are traversed to obtain the minimum and maximum grayscale values that actually exist in the current image. These minimum and maximum grayscale values are then mapped to a new grayscale dynamic range. The new grayscale dynamic range is selected from the minimum value of 0 and the maximum value of 255 supported by the current image data type. The new image obtained by transforming each pixel in the first target image is denoted as the second target image. The specific calculation formula is as follows: , ; ; In the formula Indicates the second target image in pixels grayscale value at the location, Indicates the first target image in pixels The grayscale value at the location, This represents the minimum grayscale value of a pixel in the first target image. The first target image represents the maximum grayscale value of a pixel. The acquired second target image darkens the background area and brightens the transparent film area, further increasing the difference in grayscale between the two areas. Finally, based on the second target image, the effective product area of the transparent film is extracted through threshold segmentation, and mapped onto the transparent film grayscale image to obtain a new image, which is denoted as the target grayscale image. Threshold segmentation is a well-known technique and will not be described in detail in this embodiment.
[0030] Thus, the target grayscale image of the transparent film is obtained through the above method.
[0031] Step S3: Perform Sobel edge detection based on the pixels in the target grayscale image, calculate the gradient magnitude in the horizontal and vertical directions respectively, and synthesize the gradient magnitudes in the two directions to obtain a new image, which is called the edge gradient image.
[0032] It should be noted that the transparent film surface may have scratches of varying degrees of severity, and the defect features will differ in the acquired target grayscale image. The common feature of these scratches is that the pixel grayscale changes significantly at the edges. This commonality is used to calculate the edge gradient of the pixel in the horizontal and vertical directions of the image, and the gradient magnitudes in these two directions are combined to obtain a value that measures the degree of grayscale change of the pixel. This value is used to locate the scratched areas on the target grayscale image.
[0033] Specifically, taking any grayscale image of a transparent film as an example, a convolution kernel of a fixed size is used to traverse the entire image region. This embodiment uses a 3*3 convolution kernel as an example. The Sobel operator is used for edge detection, and the gradient magnitude of each pixel in the horizontal and vertical directions is calculated. The new image obtained by synthesizing the gradient magnitudes in the two directions is called the edge gradient image. The specific synthesis method is as follows: ; In the formula, Represents the edge gradient image at pixels The new gradient magnitude synthesized at the location, This represents the weighting coefficient, which is set to 0.5 in this implementation. Indicates the target grayscale image in pixels Calculate the gradient magnitude in the horizontal x-direction. Indicates the target grayscale image in pixels The gradient magnitude in the vertical direction (y) is calculated. The composite gradient magnitude is obtained by weighted summation of the absolute values of the gradient magnitudes in the horizontal and vertical directions. A larger composite gradient magnitude indicates a more pronounced scratch edge. The Sobel operator edge detection is a well-known technique and will not be described further in this embodiment.
[0034] Thus, the edge gradient image of the transparent film is obtained using the above method.
[0035] Step S4: After performing Gaussian filtering on the edge gradient image, calculate the overall image grayscale mean. Determine the first grayscale threshold and the second grayscale threshold based on the overall image grayscale mean. Use the first grayscale threshold and the second grayscale threshold to perform grayscale linear transformation on the edge gradient image to obtain the first salient image.
[0036] It should be noted that, on the one hand, the transparent film, due to the properties of its internal material, will introduce granular point interference in the acquired images. These interference points need to be filtered out during subsequent image processing, while preserving as much of the edge details of the scratch defects as possible. On the other hand, based on the characteristics of scratch defects of different degrees in the acquired edge gradient image, the grayscale value changes in some scratch defect areas will be distributed within a relatively small range, resulting in unclear details and making it difficult to extract the scratch defect areas. To further expand the grayscale variation range and make the defect information in the image more obvious, a linear grayscale transformation is used to amplify the grayscale difference between the normal product area and the defect area, making subsequent defect area segmentation more accurate.
[0037] Specifically, taking the edge gradient image of any transparent film as an example, Gaussian filtering is used to process it, filtering out some granular scattered points. The resulting new image is denoted as the preprocessed image. The overall image grayscale mean (Mean) is calculated by traversing all pixels based on the preprocessed image. First and second grayscale thresholds are determined based on the overall image grayscale mean. The first grayscale threshold is denoted as Mean-a, representing a number lower than the overall image grayscale mean by a constant a. In this embodiment, a=10 is used as an example. The second grayscale threshold is denoted as Mean+b, representing a number higher than the overall image grayscale mean by a constant b. In this embodiment, b=15 is used as an example. The first and second grayscale thresholds are used for grayscale linear transformation, mapping to the target grayscale range. The resulting new image is denoted as the first salient image, and the specific calculation formula is as follows: ; In the formula This indicates that the first salient image is output in pixel grayscale values, Indicates the input edge gradient image in pixel grayscale values, This represents the first grayscale threshold. This indicates the second grayscale threshold. This represents the minimum grayscale value within the target grayscale range. This represents the maximum grayscale value within the target grayscale range. In this embodiment, it is used as... , Taking the image as an example, by using the overall image grayscale mean as a benchmark to determine the first and second grayscale thresholds, the grayscale values within the range of the first and second grayscale thresholds are evenly distributed. This makes the originally subtle grayscale differences in the image larger and more obvious, thereby significantly improving the visual contrast of the image. It should be noted that Gaussian filtering is a well-known technique, and will not be described in detail in this embodiment.
[0038] Thus, the first significant image of the transparent film is obtained through the above method.
[0039] Step S5: Based on the pixel grayscale values in the target grayscale image, perform a logarithmic transformation on the target grayscale image, and the resulting new image is denoted as the second salient image.
[0040] It should be noted that when using an industrial camera to capture images, the amount of light entering the center and edge areas of the lens differs. Additionally, the transparent film material is relatively soft and its surface may warp, resulting in an uneven image. The areas on the sides of the image will be darker than the center. While linear grayscale transformation can change the grayscale value of each pixel, linearly mapping the original grayscale range to a new specified grayscale range, this method strictly maintains the relative grayscale relationship between pixels and does not significantly enhance the detail in dark areas of the image. To balance the presence of both bright and dark areas in the image, logarithmic transformation is used to compress the grayscale values of bright areas while expanding the dynamic range of grayscale in dark areas under low brightness, thereby significantly enhancing the detail and contrast of dark areas in the image.
[0041] Specifically, taking any grayscale image of a transparent film as an example, the grayscale values of all pixels in the target grayscale image are logarithmically transformed, and the resulting image is denoted as the second salient image. The specific calculation formula is as follows: ; ; In the formula, This indicates that the output of the second salient image is in The pixel grayscale value after logarithmic transformation Indicates the input target grayscale image in pixel grayscale values, This represents the maximum pixel grayscale value in the target grayscale image. Represents the normalization constant. To represent the base of the logarithm, this embodiment uses... The example given is the natural logarithm e; +1 is to avoid taking the logarithm with respect to zero, by normalizing the constant. This is to map the new grayscale value after logarithmic transformation of each pixel's grayscale value to the current image data type within the range of 0~255.
[0042] Thus, the second significant image of the transparent film is obtained through the above method.
[0043] Step S6: Calculate the mean gray value of the two images based on the first salient image and the second salient image respectively, and determine the adaptive segmentation threshold of the first salient image and the second salient image based on the mean gray value of the two images and the preset salient threshold.
[0044] It should be noted that there will be uneven grayscale in the grayscale image of the transparent film captured by the camera. Direct thresholding on the first and second salient images will result in the extraction of some unnecessary areas. The direction of this uneven grayscale change is along the direction of movement of the transparent film. Therefore, the entire image area is divided into multiple regions for analysis according to this direction.
[0045] Specifically, based on the first salient image and the second salient image, taking the first salient image as an example, the horizontal width of the first salient image is calculated, and it is divided into N image regions in the vertical direction on an average basis. In this embodiment, N=10 is used as an example. The grayscale mean of each image region is calculated, and the adaptive segmentation threshold of the current image region is obtained by adding the calculated grayscale mean to a preset salient threshold. In this embodiment, the preset salient threshold is set to 60. All adaptive segmentation thresholds under the first salient image are obtained by traversing from the first image region to the 10th image region. Similarly, all adaptive segmentation thresholds under the second salient image are obtained.
[0046] Thus, all adaptive segmentation thresholds for the first and second salient images are obtained using the above method.
[0047] Step S7: The adaptive segmentation threshold is used to perform threshold segmentation processing on the first salient image and the second salient image respectively. The intersection of the defect regions extracted from the two images is processed to obtain the initial scratch region. The initial scratch region is then filtered according to the preset judgment conditions to obtain the final scratch region.
[0048] Specifically, based on all adaptive segmentation thresholds of the first and second salient images obtained in step S6, threshold segmentation is performed on the image regions divided by the first and second salient images respectively. The intersection of all defect regions extracted from the first salient image and all defect regions extracted from the second salient image is taken to obtain the scratch region. The scratch region is then filtered according to a preset judgment condition to obtain the final scratch region. In this embodiment, the preset judgment condition is to set a scratch region area threshold. The area of all obtained scratch regions is calculated sequentially. If it is greater than or equal to the set scratch region area threshold, the scratch region is output; if it is lower than the set scratch region area threshold, the scratch region is not output.
[0049] Thus, the scratch defects in the grayscale image of the transparent film were obtained using the above method.
[0050] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the principles of the present invention should be included within the protection scope of the present invention.
[0051] Example 2: Please refer to Figure 2 This embodiment provides a scratch detection device for transparent films, which includes: Image acquisition device, acquires several grayscale images of transparent thin films; The image multiplication processing module is configured to perform image multiplication processing on the acquired grayscale image of the transparent film to obtain a first target image, and to map the minimum and maximum grayscale values of the pixels in the first target image to a new grayscale dynamic range to obtain a second target image. The threshold segmentation extraction module is configured to perform threshold segmentation based on the second target image to extract the effective product area, and map it onto the grayscale image of the transparent film to obtain the target grayscale image. The edge detection module is configured to perform Sobel edge detection based on the pixels in the target grayscale image, calculate the gradient magnitude in the horizontal and vertical directions respectively, and synthesize the gradient magnitudes in the two directions to obtain the edge gradient image. The Gaussian filtering module is configured to perform Gaussian filtering on the edge gradient image, calculate the overall image grayscale mean, and determine the first grayscale threshold and the second grayscale threshold based on the overall image grayscale mean. The grayscale linear transformation processing module is configured to perform a grayscale linear transformation on the edge gradient image using the first grayscale threshold and the second grayscale threshold to obtain a first salient image; The logarithmic transformation processing module is configured to perform a logarithmic transformation on the target grayscale image based on the pixel grayscale values in the target grayscale image to obtain a second salient image; The adaptive segmentation threshold determination module is configured to calculate the gray-scale mean of the first salient image and the second salient image respectively, and determine the adaptive segmentation threshold of the first salient image and the second salient image based on the gray-scale mean of the two images and a preset salient threshold. The scratch extraction module is configured to perform threshold segmentation processing on the first salient image and the second salient image respectively using the adaptive segmentation threshold, and to obtain the initial scratch region by taking the intersection of the defect regions extracted from the two images. The final scratch region is obtained by filtering the initial scratch region according to the preset judgment conditions.
[0052] Example 3: This embodiment provides a scratch detection device for transparent films, which includes: Memory, used to store computer programs; A processor is used to execute a computer program to implement a scratch detection method for transparent films, wherein the scratch detection method for transparent films has the same steps as the method described in Embodiment 1.
[0053] Example 4: This embodiment provides a computer-readable storage medium on which a computer program is stored. When the computer program is executed by a processor, it implements a scratch detection method for a transparent film. The scratch detection method for the transparent film has the same steps as the method described in Embodiment 1.
[0054] The above description is only a preferred embodiment of the present invention and is not intended to limit the present invention. Any modifications, equivalent substitutions, improvements, etc., made within the principles of the present invention should be included within the protection scope of the present invention.
Claims
1. A method for detecting scratches on transparent films, characterized in that, Includes the following steps: S1: Acquire several grayscale images of transparent films; S2: Perform image multiplication on the grayscale image of the transparent film to obtain the first target image. Map the minimum and maximum grayscale values of the pixels in the first target image to a new grayscale dynamic range to obtain the second target image. Perform threshold segmentation on the second target image to extract the effective product area and map it onto the grayscale image of the transparent film to obtain the target grayscale image. S3: Perform Sobel edge detection on the pixels in the target grayscale image, calculate the gradient magnitude in the horizontal and vertical directions respectively, and synthesize the gradient magnitudes in the two directions to obtain the edge gradient image; S4: After performing Gaussian filtering on the edge gradient image, calculate the overall image grayscale mean. Determine the first grayscale threshold and the second grayscale threshold based on the overall image grayscale mean. Use the first grayscale threshold and the second grayscale threshold to perform grayscale linear transformation on the edge gradient image to obtain the first salient image. S5: Based on the pixel grayscale values in the target grayscale image, perform a logarithmic transformation on the target grayscale image to obtain the second salient image; S6: Calculate the mean gray value of the first salient image and the second salient image respectively, and determine the adaptive segmentation threshold of the first salient image and the second salient image based on the mean gray value of the two images and the preset salient threshold. S7: The first salient image and the second salient image are subjected to threshold segmentation processing using the adaptive segmentation threshold. The intersection of the defect regions extracted from the two is processed to obtain the initial scratch region. The initial scratch region is then filtered according to the preset judgment conditions to obtain the final scratch region.
2. The scratch detection method for transparent films according to claim 1, characterized in that, In step S2, obtaining the first target image includes: Let any grayscale image of a transparent thin film be... The position of each pixel in the grayscale image of the transparent film The grayscale value is multiplied by itself, and the result is scaled and shifted to obtain the first target image. The calculation formula is: , In the formula This indicates that the output of the first target image is in pixels. The grayscale value at the location, This indicates that the grayscale image of the input transparent film is in pixels. The grayscale value at the location, Indicates the scaling factor. Indicates the offset; If the calculated grayscale value of a pixel in the first target image is lower or higher than the value range of the current image data type, then the grayscale value is the minimum or maximum value of that data type.
3. The scratch detection method for transparent films according to claim 2, characterized in that, In step S2, obtaining the second target image includes: For any first target image First, iterate through all pixels in the first target image to obtain the minimum and maximum grayscale values currently existing in the image. Then, map these minimum and maximum grayscale values to a new grayscale dynamic range. The new grayscale dynamic range is selected from the minimum value of 0 and the maximum value of 255 supported by the current image data type. Then, transform each pixel in the first target image to obtain the second target image. The calculation formula is: , , , In the formula Indicates the second target image in pixels grayscale value at the location, Indicates the first target image in pixels The grayscale value at the location, This represents the minimum grayscale value of a pixel in the first target image. This represents the maximum grayscale value of a pixel in the first target image.
4. The scratch detection method for transparent films according to claim 1, characterized in that, In step S3, obtaining the edge gradient image includes: For any second target image, threshold segmentation is performed to extract the effective product region, which is then mapped onto the grayscale image of the transparent film to obtain the target grayscale image. Based on the target grayscale image, a fixed-size convolution kernel is used to traverse the entire image region, and the Sobel operator is used for edge detection. The gradient magnitude of each pixel in the horizontal and vertical directions is calculated separately. The edge gradient image is obtained by weighting and summing the absolute values of the gradient magnitudes in the two directions. The synthesis method is as follows: , In the formula, Represents the edge gradient image at pixels The new gradient magnitude synthesized at the location, Indicates the weighting coefficient. Indicates the target grayscale image in pixels Calculate the gradient magnitude in the horizontal x-direction. Indicates the target grayscale image in pixels Calculate the gradient magnitude in the vertical direction y for the location.
5. The scratch detection method for transparent films according to claim 1, characterized in that, In step S4, obtaining the first salient image includes: For any edge gradient image, a Gaussian filter is applied to remove granular noise regions, resulting in a preprocessed image. The overall image grayscale mean (Mean) is calculated by iterating through all pixels of the preprocessed image. Based on this mean, a first grayscale threshold and a second grayscale threshold are determined. The first grayscale threshold, denoted as Mean-a, represents a number below the overall image grayscale mean by a constant 'a'. The second grayscale threshold, denoted as Mean+b, represents a number above the overall image grayscale mean by a constant 'b'. A linear grayscale transformation is then performed on the edge gradient image using these two thresholds, mapping it to the target grayscale range. The first salient image is obtained, and the calculation formula is: , In the formula This indicates that the first salient image is output in pixel grayscale values, Indicates the input edge gradient image in pixel grayscale values, This represents the first grayscale threshold. This indicates the second grayscale threshold. This represents the minimum grayscale value within the target grayscale range. This indicates the maximum grayscale value within the target grayscale range.
6. The scratch detection method for transparent films according to claim 1, characterized in that, In step S5, obtaining the second salient image includes: The second salient image is obtained by performing a logarithmic transformation on the grayscale values of all pixels in any of the target grayscale images. The calculation formula is as follows: , , In the formula, This indicates that the output of the second salient image is in The pixel grayscale value after logarithmic transformation Indicates the input target grayscale image in pixel grayscale values, This represents the maximum pixel grayscale value in the target grayscale image. Represents the normalization constant. Represents the base of the logarithm.
7. The scratch detection method for transparent films according to claim 1, characterized in that, In step S6, obtaining the adaptive segmentation threshold includes: Based on the first salient image and the second salient image, calculate the horizontal width of the first salient image, divide it into N image regions in the vertical direction, calculate the grayscale mean of each image region, and obtain the adaptive segmentation threshold of the current image region by adding the grayscale mean to the preset salient threshold. Iterate from the first image region to the Nth image region to obtain all the adaptive segmentation thresholds of the first salient image; similarly, obtain all the adaptive segmentation thresholds of the second salient image.
8. The scratch detection method for transparent films according to claim 1, characterized in that, In step S7, obtaining the final scratch area includes: Based on all adaptive segmentation thresholds of the first and second salient images obtained in step S6, threshold segmentation is performed on the image regions divided by the first and second salient images respectively. The intersection of all defect regions extracted from the first and second salient images is taken to obtain the initial scratch region. The initial scratch region is then filtered according to a preset judgment condition to obtain the final scratch region. The preset judgment condition is to judge by setting a scratch region area threshold. The area of all the obtained initial scratch regions is calculated in turn. If it is greater than or equal to the set scratch region area threshold, the scratch region is output; if it is lower than the set scratch region area threshold, the scratch region is not output.
9. A scratch detection device for transparent films, characterized in that, include: Image acquisition device, acquires several grayscale images of transparent thin films; The image multiplication processing module is configured to perform image multiplication processing on the acquired grayscale image of the transparent film to obtain a first target image, and to map the minimum and maximum grayscale values of the pixels in the first target image to a new grayscale dynamic range to obtain a second target image. The threshold segmentation extraction module is configured to perform threshold segmentation based on the second target image to extract the effective product area, and map it onto the grayscale image of the transparent film to obtain the target grayscale image. The edge detection module is configured to perform Sobel edge detection based on the pixels in the target grayscale image, calculate the gradient magnitude in the horizontal and vertical directions respectively, and synthesize the gradient magnitudes in the two directions to obtain the edge gradient image. The Gaussian filtering module is configured to perform Gaussian filtering on the edge gradient image, calculate the overall image grayscale mean, and determine the first grayscale threshold and the second grayscale threshold based on the overall image grayscale mean. The grayscale linear transformation processing module is configured to perform a grayscale linear transformation on the edge gradient image using the first grayscale threshold and the second grayscale threshold to obtain a first salient image; The logarithmic transformation processing module is configured to perform a logarithmic transformation on the target grayscale image based on the pixel grayscale values in the target grayscale image to obtain a second salient image; The adaptive segmentation threshold determination module is configured to calculate the gray-scale mean of the first salient image and the second salient image respectively, and determine the adaptive segmentation threshold of the first salient image and the second salient image based on the gray-scale mean of the two images and a preset salient threshold. The scratch extraction module is configured to perform threshold segmentation processing on the first salient image and the second salient image respectively using the adaptive segmentation threshold, and to obtain the initial scratch region by taking the intersection of the defect regions extracted from the two images. The final scratch region is obtained by filtering the initial scratch region according to the preset judgment conditions.
10. A scratch detection device for transparent films, characterized in that, include: Memory, used to store computer programs; A processor for executing a computer program to implement the scratch detection method for transparent films as described in any one of claims 1 to 8.
11. A computer-readable storage medium, characterized in that, The computer-readable storage medium stores a computer program that, when executed by a processor, implements the scratch detection method for transparent films as described in any one of claims 1 to 8.
Citation Information
Patent Citations
A visual inspection method for laminated glass production quality
CN117058137B
Watch case quality inspection method based on image data
CN117218122B
Cover film surface defect detection method based on machine vision
CN119273684A
Laboratory plastic film defect detection method based on optical means
CN115131354A
Intelligent detection method for surface flaws and defects of optical film
CN117232791A
Cited By
Battery production line detection system and detection method
CN122415594A
