Blue film tiny scratch detection method based on image enhancement

By employing image enhancement methods such as partitioned gamma transform and local neighborhood difference, the problems of fatigue in manual detection and high resource consumption in automated detection of fine scratches on blue film are solved, achieving scratch detection results with high sensitivity and low error.

CN121998940APending Publication Date: 2026-05-08JIANGYIN JIANGTAI HIGH POLYMER NEW MATERIAL CO LTD
View PDF 0 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
JIANGYIN JIANGTAI HIGH POLYMER NEW MATERIAL CO LTD
Filing Date
2026-01-27
Publication Date
2026-05-08

AI Technical Summary

Technical Problem

Existing technologies for detecting minute scratches on blue film rely on manual visual inspection which is susceptible to fatigue, while automated inspection methods are computationally expensive and poorly adaptable, making them difficult to deploy on handheld devices. Furthermore, traditional image processing methods are not effective on curved glass.

Method used

The method employs partitioned gamma transform and nonlinear mapping to enhance grayscale contrast. It combines local neighborhood difference and morphological top-hat operation to extract subtle scratch marks. Contour information is extracted through horizontal and vertical responses, and then normalized and thresholded for segmentation. Finally, the scratches are marked in the color image.

Benefits of technology

It achieves high sensitivity and low error scratch detection, adapts to different lighting conditions and equipment, is simple and efficient, and is suitable for rapid inspection on industrial lines.

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121998940A_ABST
    Figure CN121998940A_ABST
Patent Text Reader

Abstract

The invention relates to the technical field of image processing and machine vision detection, and discloses a blue film fine scratch detection method based on image enhancement. Collecting a blue film curved glass color image and graying to obtain a gray image matrix; dividing the gray-scale map into sub-regions, setting a gamma index according to the ratio of the sub-regions to the global average gray scale, and performing gamma mapping on pixels in the regions to generate an enhanced gray-scale map; constructing a neighborhood for each pixel in the enhanced gray-scale map, and generating a difference image according to the difference between the average gray scale of the neighborhood and the enhancement value of the pixel; opening operation and top-hat operation are carried out on the difference image, the background is inhibited, and small linear traces are reserved; the method comprises the following steps of: calculating the brightness difference of left and right adjacent pixels and upper and lower adjacent pixels in a top hat image to form a direction response matrix, taking a larger value of each pixel to obtain a comprehensive linear response matrix, obtaining a scratch binary image through normalization and adaptive threshold segmentation, enabling the scratch binary image to correspond to an original color image, and marking scratches with red;
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of image processing and machine vision inspection technology, specifically to a method for detecting fine scratches on a blue film based on image enhancement. Background Technology

[0002] With the widespread application of smart terminals, automotive displays, and precision optical components, curved glass surfaces are typically covered with a blue protective film before leaving the factory to prevent scratches during assembly and transportation. To ensure product appearance quality and optical performance, it is necessary to inspect the blue-film-covered curved glass for minor scratches on the production line. Currently, industrial sites commonly use methods such as manual visual inspection, simple threshold segmentation image detection, or deep learning-based defect identification.

[0003] Manual visual inspection relies on operator experience. Under conditions of blue film color interference, complex reflected light, and long working hours, it is prone to fatigue and subjective bias. Micro-scratches with extremely small widths and low contrast are often difficult to detect in a timely manner, resulting in poor consistency and repeatability of inspection results. Traditional digital image processing methods often employ global grayscale linear transformation, fixed threshold segmentation, or simple edge operators. These methods are typically based on the assumption of relatively uniform illumination and a simple background. When applied to curved glass blue film scenarios, they are easily affected by uneven incident light caused by curvature, local reflective spots, and the texture of the blue film itself, leading to problems such as insufficient contrast between scratches and background, misclassification of noise points as defects, and overexposure or underexposure in local areas. In recent years, some surface defect detection schemes based on deep neural networks have emerged, using convolutional networks for end-to-end classification or segmentation of defects. These methods typically require a large number of labeled samples for training, resulting in complex network structures and parameters, high demands on computational resources and storage space, making them unsuitable for deployment on handheld inspection devices or embedded terminals. Furthermore, the internal feature extraction process of deep learning models is difficult to describe directly in a clear mathematical form, and the adaptability to specific blue film curved surface scenes depends on a large number of experimental parameter adjustments. When imaging conditions or product models change, the detection performance is prone to instability.

[0004] Therefore, this paper aims to propose a blue film fine scratch detection method based on image enhancement. First, grayscale contrast is enhanced by partitioned gamma transform and nonlinear mapping. Second, local neighborhood difference and morphological top-hat operation are used to highlight faint scratch traces. Then, contour information is extracted by horizontal and vertical response. After normalization and threshold segmentation, a binary scratch map is obtained. Finally, the detection results are superimposed back into the color image with red markers to achieve high sensitivity and low error detection of scratch pixels. Summary of the Invention

[0005] This invention provides a blue film fine scratch detection method based on image enhancement, which helps to solve the problems mentioned in the background art.

[0006] This invention provides the following technical solution: a method for detecting fine scratches on a blue film based on image enhancement, comprising:

[0007] Perform image acquisition and grayscale processing, establish a pixel-level two-dimensional coordinate system, obtain the original color image matrix and generate a grayscale image matrix;

[0008] The grayscale image matrix is ​​divided into multiple sub-regions in the horizontal and vertical directions. The average grayscale brightness value of each sub-region and the global average grayscale brightness value of the entire grayscale image matrix are obtained. The gamma transform index is set for each sub-region according to the ratio of the two.

[0009] For each pixel in the grayscale image matrix, a nonlinear brightness mapping is performed based on the gamma transform index of the sub-region where the pixel is located to obtain the enhanced grayscale image matrix;

[0010] In the enhanced grayscale image matrix, a neighborhood of a limited size is constructed around each pixel, the average grayscale brightness value of the neighborhood is obtained, and a difference image matrix is ​​generated based on the difference between the enhanced grayscale brightness value and the average grayscale brightness value of the neighborhood.

[0011] A structuring element opening operation is introduced on the difference image matrix to obtain the erosion result image matrix and the opening operation result image matrix, and the top cap image matrix is ​​constructed based on the difference between the two.

[0012] Using the top-hat image matrix as input, the brightness difference of the top-hat between the left and right adjacent pixels and the top and bottom adjacent pixels is obtained to form the horizontal response matrix and the vertical response matrix.

[0013] Based on the horizontal and vertical response matrices, the larger response value of the two is selected at each pixel position to form a comprehensive linear response matrix. The maximum response value is obtained from the comprehensive linear response matrix, and the response values ​​of each pixel are normalized. The normalized response threshold is set according to the distribution of the normalized response values ​​to obtain the scratch binary image matrix.

[0014] The scratch binary image matrix is ​​mapped pixel-by-pixel to the original color image matrix to construct the output color image matrix. The scratch pixel positions are marked in red to obtain the output color image matrix.

[0015] Optionally, the step of performing image acquisition and grayscale processing, establishing a pixel-level two-dimensional coordinate system, obtaining the original color image matrix, and generating a grayscale image matrix specifically includes:

[0016] Establish a two-dimensional discrete pixel coordinate system, select the center of the pixel in the upper left corner of the original color image matrix as the origin of the coordinate system, set the horizontal direction as the column index with the positive direction facing the right side of the image, and set the vertical direction as the row index with the positive direction facing the bottom of the image.

[0017] Obtain the total number of rows in the original color image matrix as the row count parameter, and obtain the total number of columns in the original color image matrix as the column count parameter;

[0018] The raw color images acquired by the handheld inspection device are converted and stored as a raw color image matrix. The raw color image matrix contains three channels of data: red, green and blue. The data of each channel is arranged according to the row index and column index.

[0019] For each pixel position in the original color image matrix, read the brightness value of the current pixel in the red, green and blue channels from the original color image matrix, add the brightness values ​​of the three channels and divide by the number of channels to obtain the grayscale brightness value of the current pixel, and organize the grayscale brightness values ​​of all pixels into a grayscale image matrix according to the corresponding row index and column index.

[0020] Optionally, the grayscale image matrix is ​​divided into multiple sub-regions in the horizontal and vertical directions, the average grayscale brightness value of each sub-region and the global average grayscale brightness value of the entire grayscale image matrix are obtained, and a gamma transform index is set for each sub-region according to the ratio of the two, specifically including:

[0021] The number of sub-regions of the grayscale image matrix is ​​set in the horizontal direction and the number of sub-regions of the grayscale image matrix is ​​set in the vertical direction. Based on the row number parameter and column number parameter, the grayscale image matrix is ​​divided into several non-overlapping rectangular sub-regions according to the equal interval of row index and column index. Each sub-region is identified by numbering in the vertical and horizontal directions.

[0022] For each sub-region, set the start index and end index in the row index direction and column index direction according to the number to form the index range of continuous pixel rows and pixel columns covered by the corresponding sub-region, and collect all pixel positions within the index range defined by the start index and end index to construct the pixel index set within the sub-region;

[0023] For each sub-region, the pixel positions are traversed one by one in the pixel index set, the corresponding grayscale brightness value is read from the grayscale image matrix, the grayscale brightness values ​​of all pixels in the corresponding sub-region are summed and divided by the number of pixels to obtain the average grayscale brightness value of the corresponding sub-region.

[0024] For the entire grayscale image matrix, traverse all pixel positions within all row and column indices, read the corresponding grayscale brightness values, sum the grayscale brightness values ​​of all pixels and divide by the total number of pixels to obtain the global average grayscale brightness value of the entire grayscale image matrix.

[0025] For each sub-region, the gamma transform index is calculated based on the ratio between the average grayscale value of the corresponding sub-region and the global average grayscale value of the entire grayscale image matrix, and the gamma transform index is associated with and stored with the corresponding sub-region number.

[0026] Optionally, the step of performing nonlinear brightness mapping on each pixel in the grayscale image matrix according to the gamma transform exponent of the sub-region where the pixel is located to obtain an enhanced grayscale image matrix specifically includes:

[0027] Create an enhanced grayscale image matrix that has the same number of rows and columns as the grayscale image matrix;

[0028] For each pixel position in the grayscale image matrix, the corresponding gamma transform index is read from the associated stored gamma transform index record according to the number of the sub-region where the pixel is located.

[0029] For each pixel, the grayscale brightness value is normalized according to a preset grayscale range. The normalized value is then mapped by exponentiation of the gamma transform. Finally, it is inversely normalized according to the preset grayscale range to obtain the enhanced grayscale brightness value of the current pixel. The enhanced grayscale brightness values ​​of all pixels are then written into the enhanced grayscale image matrix according to the original row and column indices.

[0030] Optionally, the step of constructing a neighborhood of a defined size around each pixel in the enhanced grayscale image matrix, obtaining the average grayscale brightness value of the neighborhood, and generating a difference image matrix based on the difference between the enhanced grayscale brightness value and the average grayscale brightness value of the neighborhood specifically includes:

[0031] For each pixel position in the enhanced grayscale image matrix, extend it forward and backward by one pixel step in the row index direction and the column index direction respectively, and truncate it at the position that exceeds the boundary of the enhanced grayscale image matrix to obtain the set of neighborhood pixel coordinates around the current pixel, which is extended by one pixel in the row direction and the column direction respectively.

[0032] Establish a local average image matrix with the same size as the enhanced grayscale image matrix; traverse the pixel positions one by one in the neighborhood pixel coordinate set, read the enhanced grayscale brightness value of the corresponding pixel from the enhanced grayscale image matrix, sum the enhanced grayscale brightness values ​​of all pixels in the neighborhood and divide by the number of neighborhood pixels to obtain the neighborhood average grayscale brightness value of the current pixel, and write the neighborhood average grayscale brightness value into the local average image matrix at the position corresponding to the current pixel position;

[0033] For each pixel location, the enhanced grayscale brightness value is read from the enhanced grayscale image matrix, and the neighborhood average grayscale brightness value is read from the local average image matrix. The difference between the two is calculated and the absolute value is taken to obtain the differential brightness value. The differential brightness values ​​of all pixels are organized into a differential image matrix according to the row index and column index.

[0034] Optionally, the step of introducing a structuring element opening operation on the difference image matrix to obtain the erosion result image matrix and the opening operation result image matrix, and constructing a top-hat image matrix based on the difference between the two, specifically includes:

[0035] Establish a set of structural element offsets. The structural elements are circular structural elements with a unit of pixels and a radius of two pixels. Each element in the set contains a row offset and a column offset, and both the row offset and the column offset are integers.

[0036] For each pixel position in the difference image matrix, based on the structuring element offset set and the boundary position of the difference image matrix, offsets that do not exceed the range of the number of rows and columns of the difference image matrix in both row and column indices are selected to generate a structuring element offset subset corresponding to the current pixel position.

[0037] For each pixel location, among all pixel locations covered by the structuring element offset subset, the corresponding differential brightness value is read from the differential image matrix, and the minimum value is selected as the pixel value of the erosion result image matrix at the current pixel location.

[0038] A dilation operation is performed on the erosion result image matrix. For each pixel position, based on the structuring element offset subset, the pixel values ​​of all covered pixel positions are read from the erosion result image matrix, and the maximum value is selected as the pixel value of the opening operation result image matrix at the current pixel position.

[0039] For each pixel position, read the differential brightness value from the differential image matrix, read the corresponding pixel value from the opening operation result image matrix, subtract the opening operation result pixel value from the differential brightness value to obtain the top cap brightness value, and organize all the top cap brightness values ​​into a top cap image matrix according to the row index and column index.

[0040] Optionally, the step of using the top-hat image matrix as input to obtain the top-hat brightness difference between left and right adjacent pixels and top and bottom adjacent pixels to form a horizontal response matrix and a vertical response matrix specifically includes:

[0041] A horizontal response matrix is ​​established based on the top-hat image matrix. When the top-hat image matrix contains only one column of pixels, the horizontal response values ​​of all pixels in that column are set to zero. When the top-hat image matrix contains multiple columns of pixels, for each pixel in each column except the last column, the absolute value of the top-hat brightness difference between the current pixel and its right-side adjacent pixel is calculated as the horizontal response value of the current pixel. For each pixel in the last column, the absolute value of the top-hat brightness difference between the current pixel and its left-side adjacent pixel is calculated as the horizontal response value of the current pixel.

[0042] A vertical response matrix is ​​established based on the top-hat image matrix. When the top-hat image matrix contains only one row of pixels, the vertical response values ​​of all pixels in that row are set to zero. When the top-hat image matrix contains multiple rows of pixels, for each pixel in each row except the last row, the absolute value of the top-hat brightness difference between the current pixel and the pixels in the same column of the next row is calculated as the vertical response value of the current pixel. For each pixel in the last row, the absolute value of the top-hat brightness difference between the current pixel and the pixels in the same column of the previous row is calculated as the vertical response value of the current pixel.

[0043] At each pixel location, the corresponding response value is read from the horizontal response matrix and the vertical response matrix. The larger of the two response values ​​is selected as the response value of the composite linear response matrix at the current pixel location, and the composite linear response matrix is ​​constructed.

[0044] Optionally, based on the horizontal and vertical response matrices, the larger response value is selected at each pixel location to form a composite linear response matrix; the maximum response value is obtained from the composite linear response matrix, normalization is performed on the response values ​​of each pixel, and a normalized response threshold is set according to the distribution of normalized response values, thereby obtaining a scratch binary image matrix, specifically including:

[0045] Traverse all pixel positions in the composite linear response matrix, read the composite linear response value of each pixel, and obtain the maximum response value.

[0046] When the maximum response value is greater than zero, for each pixel, the comprehensive linear response value is divided by the maximum response value to obtain the normalized response value; when the maximum response value is equal to zero, the normalized response values ​​of all pixels are set to zero, and a normalized response matrix with the same size as the comprehensive linear response matrix is ​​constructed.

[0047] The normalized response values ​​of all pixel positions in the normalized response matrix are formed into a finite set of real numbers. The elements in this finite set of real numbers are sorted in ascending order of value, and the element in the middle position after sorting is taken as the normalized response threshold.

[0048] For each pixel location, the normalized response value is compared with the normalized response threshold. When the normalized response value is greater than the threshold, the value of the scratch binary image matrix at the current pixel location is set to one. When the normalized response value is less than or equal to the threshold, the value of the scratch binary image matrix at the current pixel location is set to zero, thus constructing the scratch binary image matrix.

[0049] Optionally, the step of constructing an output color image matrix by pixel-by-pixel mapping between the scratch binary image matrix and the original color image matrix, and marking the scratch pixel positions with red to obtain the output color image matrix, specifically includes: establishing an output color image matrix with the same number of rows and columns as the original color image matrix, and setting brightness storage units for red, green and blue channels at each pixel position;

[0050] For each pixel position, read the value of the current pixel position from the scratch binary image matrix. When the value is 1, set the red channel brightness of the output color image matrix at the current pixel position to the preset maximum brightness, set the green channel brightness to the preset minimum brightness, and set the blue channel brightness to the preset minimum brightness.

[0051] When the value is zero in the scratch binary image matrix, the red channel brightness, green channel brightness and blue channel brightness of the current pixel position are read from the original color image matrix, and the three channel brightness of the output color image matrix at the current pixel position are set to the corresponding original brightness values ​​respectively.

[0052] The output color image matrix is ​​used as the blue film fine scratch detection result image matrix, and the pixel positions with a value of one in the scratch binary image matrix are formed into red scratch marking areas.

[0053] The present invention has the following beneficial effects:

[0054] 1. By establishing a pixel-level two-dimensional coordinate system and splitting the color image into three channels before converting it into a single-channel grayscale image, a unified data carrier for subsequent processing is achieved. On one hand, matrix storage is used directly at the acquisition end, avoiding the performance overhead caused by multiple read / write operations and format conversions. On the other hand, channel averaging is used in grayscale calculation to balance the impact of different spectra on scratch detection, taking into account the differences in scratch feature presentation among the red, green, and blue channels. Compared to traditional methods of directly extracting single channels or weighted grayscale, this method is more versatile and can adapt to color image preprocessing under different acquisition devices and lighting conditions.

[0055] 2. The grayscale image matrix is ​​divided into multiple regions at equal intervals. The local average brightness is calculated for each region, and its ratio to the global average brightness is used to generate a gamma index. Independent contrast enhancement is then applied to each region. Adaptive regional gamma adjustment: By comparing the differences between the brightness of each region and the global brightness, gamma values ​​are dynamically allocated, ensuring stronger enhancement in dark areas where scratches are located, while preventing oversaturation in bright areas. This method effectively avoids overexposure or underexposure problems caused by a fixed overall gamma, and it significantly improves the performance of unevenly illuminated areas on the blue film surface. Compared to traditional full-image gamma correction, regional adjustment is more targeted, improving the contrast of subtle scratches and significantly enhancing the sensitivity of subsequent detection.

[0056] 3. Based on the adaptive gamma index, the grayscale brightness of each pixel is mapped by exponentiation and then denormalized to generate an enhanced grayscale image. First, combining gamma mapping with normalization and denormalization preserves the dynamic range of the original image; second, it precisely applies gamma values ​​to different regions at the pixel level, ensuring that local details are not lost due to overall enhancement; and third, the mapping curve can be flexibly configured as needed, suitable for different materials and scratch levels.

[0057] 4. Construct a fixed-size neighborhood around each pixel. First, calculate the average gray level of the neighborhood, then calculate the absolute value of the difference between the current pixel and the neighborhood average value to form a difference map. Blur suppression through neighborhood averaging effectively removes uniform background noise and highlights local brightness abrupt changes. Simultaneously, the difference operation is particularly sensitive to brightness abrupt changes at the edges of subtle scratches, helping to enhance the scratch signal. Unlike simple high-pass filtering or the Sobel operator, this method does not require manual filter kernel design; it extracts scratch marks using only gray-level differences. The algorithm is simpler to implement and has lower computational cost, making it suitable for rapid inspection scenarios on industrial production lines.

[0058] 5. A circular structuring element with a radius of two pixels is introduced into the difference image. Erosion followed by dilation (opening operation) is performed first, and the difference between the original difference image and the opening operation result is used to obtain the top-hat image. The top-hat operation can preserve bright details smaller than the structuring element size (such as fine scratches) to the greatest extent possible, while removing large areas of undulating background. Combined with adaptive boundary clipping of the structuring element, it ensures normal operation even at image edges without producing boundary artifacts. Compared with existing simple morphological filtering or closing operations, this method has a stronger ability to highlight minute traces.

[0059] 6. Calculate the absolute values ​​of the brightness differences between adjacent pixels in the horizontal and vertical directions on the top-hat image, generating response matrices for both directions. This bidirectional response separation effectively captures the linear features of scratches along either principal direction, while special handling of single-row or single-column boundary cases (setting the value to zero for single-row / single-column images) ensures the algorithm's versatility. Compared to using only a one-dimensional gradient operator, this scheme employs bidirectional separation and parallel processing, extracting richer and more structured response values, which contributes to the accurate construction of the subsequent comprehensive response.

[0060] 7. At each pixel location, the larger of the horizontal and vertical response values ​​is selected to construct a comprehensive response matrix. This matrix is ​​then globally normalized, and the median is automatically selected as the threshold based on the normalized response distribution to complete binarization. Firstly, the "maximum value selection" strategy ensures maximum sensitivity in any direction; secondly, the median-based threshold adaptive segmentation can adapt to different image response distributions without manual parameter tuning; and thirdly, the binarization result clearly distinguishes scratches from the background. Compared to fixed thresholds or the Otsu method, this scheme is more sensitive to weak scratch signals and has better suppression capabilities for noise points and occasional bright areas.

[0061] 8. The binarized scratch locations are mapped back to the original color image matrix pixel by pixel, and the scratch pixel channel is set to red, while other pixels retain their original color, forming the final result image. This simple and direct pixel-level overlay not only intuitively displays the scratch location but also preserves the original image background information; for users, no additional annotation or post-processing is required, and the scratch area can be clearly identified at a glance. Compared to heatmaps or mask overlays, this method uses high-contrast red markers to improve visibility, and the data channel processing overhead is extremely low, meeting the requirements of real-time detection. Attached Figure Description

[0062] Figure 1 This is a schematic diagram of the process of the present invention.

[0063] Figure 2 This is a schematic diagram of the pixel coordinate system of the present invention.

[0064] In the diagram: 1 - origin, 2 - horizontal direction, 3 - vertical direction. Detailed Implementation

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

[0066] Example, refer to Figure 1A method for detecting fine scratches on a blue film based on image enhancement, comprising:

[0067] Perform image acquisition and grayscale processing, establish a pixel-level two-dimensional coordinate system, obtain the original color image matrix and generate a grayscale image matrix;

[0068] The grayscale image matrix is ​​divided into multiple sub-regions in the horizontal and vertical directions. The average grayscale brightness value of each sub-region and the global average grayscale brightness value of the entire grayscale image matrix are obtained. The gamma transform index is set for each sub-region according to the ratio of the two.

[0069] For each pixel in the grayscale image matrix, a nonlinear brightness mapping is performed based on the gamma transform index of the sub-region where the pixel is located to obtain the enhanced grayscale image matrix;

[0070] In the enhanced grayscale image matrix, a neighborhood of a limited size is constructed around each pixel, the average grayscale brightness value of the neighborhood is obtained, and a difference image matrix is ​​generated based on the difference between the enhanced grayscale brightness value and the average grayscale brightness value of the neighborhood.

[0071] A structuring element opening operation is introduced on the difference image matrix to obtain the erosion result image matrix and the opening operation result image matrix, and the top cap image matrix is ​​constructed based on the difference between the two.

[0072] Using the top-hat image matrix as input, the brightness difference of the top-hat between the left and right adjacent pixels and the top and bottom adjacent pixels is obtained to form the horizontal response matrix and the vertical response matrix.

[0073] Based on the horizontal and vertical response matrices, the larger response value of the two is selected at each pixel position to form a comprehensive linear response matrix. The maximum response value is obtained from the comprehensive linear response matrix, and the response values ​​of each pixel are normalized. The normalized response threshold is set according to the distribution of the normalized response values ​​to obtain the scratch binary image matrix.

[0074] The scratch binary image matrix is ​​mapped pixel-by-pixel to the original color image matrix to construct the output color image matrix. The scratch pixel positions are marked in red to obtain the output color image matrix.

[0075] By acquiring high-resolution color images of the blue film surface and generating a grayscale image matrix in a pixel-level two-dimensional coordinate system, subsequent processing is ensured to be based on accurate and addressable pixel data. Dividing the grayscale image into several sub-regions and adaptively setting the gamma transform exponent enables differentiated contrast enhancement for different brightness regions, highlighting minute scratches on the blue film surface with uneven illumination and significant local reflection differences. Applying gamma mapping to each pixel for the corresponding region yields a uniformly enhanced grayscale image, further eliminating local overexposure or underexposure caused by fixed global gain. Performing local neighborhood averaging and differencing on the enhanced grayscale image automatically suppresses uniform background noise and sudden changes. The image reveals edges of sudden brightness changes, providing a high signal-to-noise ratio differential map for scratch signal extraction. Based on the differential map, morphological opening and top-hat operations are introduced to directly filter out background undulations that do not match the scratch scale, retaining tiny linear traces smaller than the structuring element radius. Response matrices are constructed from the brightness differences between adjacent pixels in the horizontal and vertical directions of the top-hat image, enabling accurate extraction of linear scratch features from different directions. A comprehensive linear response matrix is ​​constructed by selecting the maximum bidirectional response, and a robust binary scratch map with strong anti-interference capabilities is obtained through global normalization and median adaptive threshold segmentation. Finally, the binary scratch map is mapped back to a color image and marked in red for intuitive display of the detection results.

[0076] Reference Figure 2 The step of performing image acquisition and grayscale processing, establishing a pixel-level two-dimensional coordinate system, obtaining the original color image matrix, and generating a grayscale image matrix specifically includes:

[0077] Establish a two-dimensional discrete pixel coordinate system, select the center of the pixel in the upper left corner of the original color image matrix as the origin of the coordinate system, set the horizontal direction as the column index with the positive direction facing the right side of the image, and set the vertical direction as the row index with the positive direction facing the bottom of the image.

[0078] Obtain the total number of rows in the original color image matrix as the row count parameter, and obtain the total number of columns in the original color image matrix as the column count parameter;

[0079] The raw color images acquired by the handheld inspection device are converted and stored as a raw color image matrix. The raw color image matrix contains three channels of data: red, green and blue. The data of each channel is arranged according to the row index and column index.

[0080] For each pixel position in the original color image matrix, read the brightness value of the current pixel in the red, green and blue channels from the original color image matrix, add the brightness values ​​of the three channels and divide by the number of channels to obtain the grayscale brightness value of the current pixel, and organize the grayscale brightness values ​​of all pixels into a grayscale image matrix according to the corresponding row index and column index.

[0081] Further specific implementation steps include:

[0082] Establish a two-dimensional discrete pixel coordinate system, taking the center of the top-left pixel of the image as the origin, and the corresponding coordinates... Set the horizontal direction as a column index. The positive direction is to the right, and the vertical direction is set as the row index. The positive direction is downward;

[0083] Get the total number of rows in the image, denoted as ; Obtain the total number of columns in the image, denoted as ;

[0084] The raw color images acquired by the handheld inspection device are set as a three-channel matrix: ;in, , ; The data set of the entire color image; , , At pixel coordinates The brightness values ​​of the red, green, and blue channels;

[0085] Constructing a grayscale image matrix The grayscale value of each pixel is calculated using the following formula: ;in, For grayscale values The grayscale image matrix is ​​composed of; In pixel coordinates The grayscale brightness value at that location.

[0086] The grayscale image matrix is ​​divided into multiple sub-regions in the horizontal and vertical directions. The average grayscale brightness value of each sub-region and the global average grayscale brightness value of the entire grayscale image matrix are obtained. A gamma transform index is then set for each sub-region based on the ratio of these two values. Specifically, this includes:

[0087] The number of sub-regions of the grayscale image matrix is ​​set in the horizontal direction and the number of sub-regions of the grayscale image matrix is ​​set in the vertical direction. Based on the row number parameter and column number parameter, the grayscale image matrix is ​​divided into several non-overlapping rectangular sub-regions according to the equal interval of row index and column index. Each sub-region is identified by numbering in the vertical and horizontal directions.

[0088] For each sub-region, set the start index and end index in the row index direction and column index direction according to the number to form the index range of continuous pixel rows and pixel columns covered by the corresponding sub-region, and collect all pixel positions within the index range defined by the start index and end index to construct the pixel index set within the sub-region;

[0089] For each sub-region, the pixel positions are traversed one by one in the pixel index set, the corresponding grayscale brightness value is read from the grayscale image matrix, the grayscale brightness values ​​of all pixels in the corresponding sub-region are summed and divided by the number of pixels to obtain the average grayscale brightness value of the corresponding sub-region.

[0090] For the entire grayscale image matrix, traverse all pixel positions within all row and column indices, read the corresponding grayscale brightness values, sum the grayscale brightness values ​​of all pixels and divide by the total number of pixels to obtain the global average grayscale brightness value of the entire grayscale image matrix.

[0091] For each sub-region, the gamma transform index is calculated based on the ratio between the average grayscale value of the corresponding sub-region and the global average grayscale value of the entire grayscale image matrix, and the gamma transform index is associated with and stored with the corresponding sub-region number.

[0092] Further specific implementation steps include:

[0093] Let the number of sub-regions in the horizontal direction be . The number of sub-regions that divide the image vertically is ;

[0094] Divide the grayscale image into Non-overlapping sub-regions ;in, For the numbered pair The determined number Line number The range of pixel coordinates corresponding to the column sub-region; , These are the sub-region numbers in the vertical and horizontal directions, respectively.

[0095] Set the boundaries between the row and column indexes of the sub-region, specifically as follows: , , , ;in, , Sub-region numbering The corresponding start and end row indices for the row direction; , Sub-region numbering The corresponding column direction start and end row indexes;

[0096] And construct sub-regions The set of pixel indices within: ;in, sub-region All pixel coordinate pairs A set;

[0097] Calculate sub-region Local average grayscale brightness within Specifically: ;in, For set The number of elements in the middle;

[0098] Calculate the global average grayscale brightness of the entire image. Specifically: ;

[0099] Construct sub-regions The corresponding gamma transformation index is .

[0100] The process of performing nonlinear brightness mapping on each pixel in the grayscale image matrix based on the gamma transform exponent of the sub-region where the pixel is located to obtain the enhanced grayscale image matrix specifically includes:

[0101] Create an enhanced grayscale image matrix that has the same number of rows and columns as the grayscale image matrix;

[0102] For each pixel position in the grayscale image matrix, the corresponding gamma transform index is read from the associated stored gamma transform index record according to the number of the sub-region where the pixel is located.

[0103] For each pixel, the grayscale brightness value is normalized according to a preset grayscale range. The normalized value is then mapped by exponentiation of the gamma transform. Finally, it is inversely normalized according to the preset grayscale range to obtain the enhanced grayscale brightness value of the current pixel. The enhanced grayscale brightness values ​​of all pixels are then written into the enhanced grayscale image matrix according to the original row and column indices.

[0104] Further specific implementation steps include:

[0105] Construct the enhanced grayscale image matrix as follows For each pixel Determine whether it meets the requirements. regional index pairs Calculate the enhanced brightness using the following formula: ;in, This is the grayscale image matrix enhanced by gamma transform, consisting of elements... composition; In pixel coordinates The grayscale brightness value after gamma mapping.

[0106] In the enhanced grayscale image matrix, a neighborhood of a defined size is constructed around each pixel, the average grayscale brightness value of the neighborhood is obtained, and a difference image matrix is ​​generated based on the difference between the enhanced grayscale brightness value and the average grayscale brightness value of the neighborhood. Specifically, this includes:

[0107] For each pixel position in the enhanced grayscale image matrix, extend it forward and backward by one pixel step in the row index direction and the column index direction respectively, and truncate it at the position that exceeds the boundary of the enhanced grayscale image matrix to obtain the set of neighborhood pixel coordinates around the current pixel, which is extended by one pixel in the row direction and the column direction respectively.

[0108] Establish a local average image matrix with the same size as the enhanced grayscale image matrix; traverse the pixel positions one by one in the neighborhood pixel coordinate set, read the enhanced grayscale brightness value of the corresponding pixel from the enhanced grayscale image matrix, sum the enhanced grayscale brightness values ​​of all pixels in the neighborhood and divide by the number of neighborhood pixels to obtain the neighborhood average grayscale brightness value of the current pixel, and write the neighborhood average grayscale brightness value into the local average image matrix at the position corresponding to the current pixel position;

[0109] For each pixel location, the enhanced grayscale brightness value is read from the enhanced grayscale image matrix, and the neighborhood average grayscale brightness value is read from the local average image matrix. The difference between the two is calculated and the absolute value is taken to obtain the differential brightness value. The differential brightness values ​​of all pixels are organized into a differential image matrix according to the row index and column index.

[0110] Further specific implementation steps include:

[0111] For each pixel The steps S401 to S403 are executed to construct the domain index set, specifically as follows:

[0112] S401. Set the row index of the pixels in the neighborhood to... : ;

[0113] S402, Set the column index of the pixels in the neighborhood to : ;

[0114] S403, obtain pixel coordinates The set of neighboring pixel coordinates centered at the image boundary, extending outward by 1 pixel in each row and column direction, and cropped to the image boundary. ;

[0115] Constructing a local average image matrix The elements in the local average image matrix are specifically: ;in, For It represents the average gray level of the pixels within the central neighborhood; For neighborhood set The number of pixel coordinate pairs;

[0116] Constructing the difference image matrix The elements in the difference image matrix are: ;in, For pixels The absolute difference between the enhanced gray level and the local average gray level.

[0117] The step of introducing a structuring element opening operation on the difference image matrix to obtain the erosion result image matrix and the opening operation result image matrix, and constructing the top cap image matrix based on the difference between the two, specifically includes:

[0118] Establish a set of structural element offsets. The structural elements are circular structural elements with a unit of pixels and a radius of two pixels. Each element in the set contains a row offset and a column offset, and both the row offset and the column offset are integers.

[0119] For each pixel position in the difference image matrix, based on the structuring element offset set and the boundary position of the difference image matrix, offsets that do not exceed the range of the number of rows and columns of the difference image matrix in both row and column indices are selected to generate a structuring element offset subset corresponding to the current pixel position.

[0120] For each pixel location, among all pixel locations covered by the structuring element offset subset, the corresponding differential brightness value is read from the differential image matrix, and the minimum value is selected as the pixel value of the erosion result image matrix at the current pixel location.

[0121] A dilation operation is performed on the erosion result image matrix. For each pixel position, based on the structuring element offset subset, the pixel values ​​of all covered pixel positions are read from the erosion result image matrix, and the maximum value is selected as the pixel value of the opening operation result image matrix at the current pixel position.

[0122] For each pixel position, read the differential brightness value from the differential image matrix, read the corresponding pixel value from the opening operation result image matrix, subtract the opening operation result pixel value from the differential brightness value to obtain the top cap brightness value, and organize all the top cap brightness values ​​into a top cap image matrix according to the row index and column index.

[0123] Further specific implementation steps include:

[0124] The set of offset coordinates for constructing the struct element is as follows ;in, , These are the relative offsets of the structural element in the row direction and the column direction, respectively; The set of all integers;

[0125] For each pixel, the subset of structuration offsets available at that pixel location is constructed as follows: ;in, In pixels The set of structuring element offsets that do not extend beyond the image boundary when centered;

[0126] Constructing an image matrix of corrosion results The specific elements in the erosion result image matrix are: ;in, For Centered on the set of structural elements The minimum value of the difference within the range;

[0127] Construct the image matrix of the opening operation result The elements in the resulting image matrix after the opening operation are specifically: ;in, For in pixels The corrosion results The value obtained after performing the expansion operation;

[0128] Constructing the top hat image matrix The elements in the top hat image matrix are specifically: ;in, For pixels Original difference value The result of the opening operation The difference between them.

[0129] The process uses the top-hat image matrix as input to obtain the top-hat brightness difference between left and right adjacent pixels and top and bottom adjacent pixels, forming a horizontal response matrix and a vertical response matrix, specifically including:

[0130] A horizontal response matrix is ​​established based on the top-hat image matrix. When the top-hat image matrix contains only one column of pixels, the horizontal response values ​​of all pixels in that column are set to zero. When the top-hat image matrix contains multiple columns of pixels, for each pixel in each column except the last column, the absolute value of the top-hat brightness difference between the current pixel and its right-side adjacent pixel is calculated as the horizontal response value of the current pixel. For each pixel in the last column, the absolute value of the top-hat brightness difference between the current pixel and its left-side adjacent pixel is calculated as the horizontal response value of the current pixel.

[0131] A vertical response matrix is ​​established based on the top-hat image matrix. When the top-hat image matrix contains only one row of pixels, the vertical response values ​​of all pixels in that row are set to zero. When the top-hat image matrix contains multiple rows of pixels, for each pixel in each row except the last row, the absolute value of the top-hat brightness difference between the current pixel and the pixels in the same column of the next row is calculated as the vertical response value of the current pixel. For each pixel in the last row, the absolute value of the top-hat brightness difference between the current pixel and the pixels in the same column of the previous row is calculated as the vertical response value of the current pixel.

[0132] At each pixel location, the corresponding response value is read from the horizontal response matrix and the vertical response matrix. The larger of the two response values ​​is selected as the response value of the composite linear response matrix at the current pixel location, and the composite linear response matrix is ​​constructed.

[0133] Further specific implementation steps include:

[0134] Constructing the horizontal response matrix Steps S611 to S613 are executed to obtain the elements in the horizontal response matrix, specifically:

[0135] S611, when At that time, for all ,make ;in, For a single row of pixels, the pixel The horizontal response value at that location;

[0136] S612, when and season: ;in, For pixels in general cases The absolute value of the brightness difference between its adjacent pixels in the row direction;

[0137] S613, when and season: ;

[0138] Constructing the vertical response matrix Steps S621 to S623 are executed to obtain the elements in the vertical response matrix, specifically:

[0139] S621, when At that time, for all ,make ;in, For a single column of pixels, the pixel Vertical response value at;

[0140] S622, when and season: ;in, For pixels in general cases The absolute value of the brightness difference between its adjacent pixels in the column direction;

[0141] S623, and season: ;

[0142] Constructing the comprehensive linear response matrix The elements in the comprehensive linear response matrix are as follows: ;in, For pixels The larger of the linear response values ​​in the horizontal and vertical directions.

[0143] The process involves selecting the larger response value from the horizontal and vertical response matrices at each pixel location to form a composite linear response matrix. The maximum response value is then obtained from this matrix. Normalization is performed on the response values ​​of each pixel, and a normalization threshold is set based on the distribution of the normalized response values, thereby obtaining the scratch binary image matrix. Specifically, this includes:

[0144] Traverse all pixel positions in the composite linear response matrix, read the composite linear response value of each pixel, and obtain the maximum response value.

[0145] When the maximum response value is greater than zero, for each pixel, the comprehensive linear response value is divided by the maximum response value to obtain the normalized response value; when the maximum response value is equal to zero, the normalized response values ​​of all pixels are set to zero, and a normalized response matrix with the same size as the comprehensive linear response matrix is ​​constructed.

[0146] The normalized response values ​​of all pixel positions in the normalized response matrix are formed into a finite set of real numbers. The elements in this finite set of real numbers are sorted in ascending order of value, and the element in the middle position after sorting is taken as the normalized response threshold.

[0147] For each pixel location, the normalized response value is compared with the normalized response threshold. When the normalized response value is greater than the threshold, the value of the scratch binary image matrix at the current pixel location is set to one. When the normalized response value is less than or equal to the threshold, the value of the scratch binary image matrix at the current pixel location is set to zero, thus constructing the scratch binary image matrix.

[0148] Further specific implementation steps include:

[0149] Get the maximum response value ;

[0150] Constructing the normalized response matrix After executing steps S701 and S702, the elements in the normalized response matrix are:

[0151] S701, when season ;in, For pixels The normalized response value at the location;

[0152] Construct normalized response values ​​from all pixel locations The set of real numbers Specifically: ;

[0153] Set the normalized response threshold to distinguish between scratched and non-scratched pixels as follows: ;in, This is the median function, which returns the middle element of a finite set of real numbers when sorted in ascending order.

[0154] Construct a binary image matrix of scratches The elements in the binary image matrix of the scratch are specifically: ;in, For pixels The scratch determination result is 1, which indicates that the pixel is a scratch, and 0 indicates that the pixel is not a scratch.

[0155] The step of mapping the scratch binary image matrix to the original color image matrix pixel by pixel to construct an output color image matrix, and marking the scratch pixel positions with red to obtain the output color image matrix, specifically includes: establishing an output color image matrix with the same number of rows and columns as the original color image matrix, and setting brightness storage units for red, green and blue channels at each pixel position;

[0156] For each pixel position, read the value of the current pixel position from the scratch binary image matrix. When the value is 1, set the red channel brightness of the output color image matrix at the current pixel position to the preset maximum brightness, set the green channel brightness to the preset minimum brightness, and set the blue channel brightness to the preset minimum brightness.

[0157] When the value is zero in the scratch binary image matrix, the red channel brightness, green channel brightness and blue channel brightness of the current pixel position are read from the original color image matrix, and the three channel brightness of the output color image matrix at the current pixel position are set to the corresponding original brightness values ​​respectively.

[0158] The output color image matrix is ​​used as the blue film fine scratch detection result image matrix, and the pixel positions with a value of one in the scratch binary image matrix are formed into red scratch marking areas.

[0159] Further specific implementation steps include:

[0160] Construct the output image matrix After executing steps S801 and S802, the elements in the output image matrix are:

[0161] S801, when At that time, calculate the brightness of each channel of the output pixel using the following formula: , , ;

[0162] in, , , The output image is in pixels. The brightness values ​​of the red, green, and blue channels;

[0163] S802, when At that time, calculate the brightness of each channel of the output pixel using the following formula: , , ;

[0164] Output image matrix The output image is used as the result of detecting minor scratches on the blue film. The pixels are set to red in the output image.

[0165] It should be noted that, in this document, relational terms such as "first" and "second" are used only to distinguish one entity or operation from another, and do not necessarily require or imply any such actual relationship or order between these entities or operations. Furthermore, the terms "comprising," "including," or any other variations thereof are intended to cover non-exclusive inclusion, such that a process, method, article, or apparatus that comprises a list of elements includes not only those elements but also other elements not expressly listed, or elements inherent to such process, method, article, or apparatus.

[0166] The above description is only a preferred embodiment of the present invention. It should be noted that for those skilled in the art, several improvements and modifications can be made without departing from the technical principles of the present invention, and these improvements and modifications should also be considered within the scope of protection of the present invention.

Claims

1. A method for detecting fine scratches on a blue film based on image enhancement, characterized in that, include: Perform image acquisition and grayscale processing, establish a pixel-level two-dimensional coordinate system, obtain the original color image matrix and generate a grayscale image matrix; The grayscale image matrix is ​​divided into multiple sub-regions in the horizontal and vertical directions. The average grayscale brightness value of each sub-region and the global average grayscale brightness value of the entire grayscale image matrix are obtained. The gamma transform index is set for each sub-region according to the ratio of the two. For each pixel in the grayscale image matrix, a nonlinear brightness mapping is performed based on the gamma transform index of the sub-region where the pixel is located to obtain the enhanced grayscale image matrix; In the enhanced grayscale image matrix, a neighborhood of a limited size is constructed around each pixel, the average grayscale brightness value of the neighborhood is obtained, and a difference image matrix is ​​generated based on the difference between the enhanced grayscale brightness value and the average grayscale brightness value of the neighborhood. A structuring element opening operation is introduced on the difference image matrix to obtain the erosion result image matrix and the opening operation result image matrix, and the top cap image matrix is ​​constructed based on the difference between the two. Using the top-hat image matrix as input, the brightness difference of the top-hat between left and right adjacent pixels and top and bottom adjacent pixels is obtained to form a horizontal response matrix and a vertical response matrix. Based on the horizontal and vertical response matrices, the larger response value between the two is selected at each pixel location to form a comprehensive linear response matrix; The maximum response value is obtained from the comprehensive linear response matrix, the response values ​​of each pixel are normalized, and the normalized response threshold is set according to the distribution of the normalized response values, thereby obtaining the scratch binary image matrix. The scratch binary image matrix is ​​mapped pixel-by-pixel to the original color image matrix to construct the output color image matrix. The scratch pixel positions are marked in red to obtain the output color image matrix.

2. The method for detecting fine scratches on a blue film based on image enhancement according to claim 1, characterized in that, The process of performing image acquisition and grayscale processing, establishing a pixel-level two-dimensional coordinate system, obtaining the original color image matrix, and generating a grayscale image matrix specifically includes: Establish a two-dimensional discrete pixel coordinate system, select the center of the pixel in the upper left corner of the original color image matrix as the origin of the coordinate system, set the horizontal direction as the column index with the positive direction facing the right side of the image, and set the vertical direction as the row index with the positive direction facing the bottom of the image. Obtain the total number of rows in the original color image matrix as the row count parameter, and obtain the total number of columns in the original color image matrix as the column count parameter; The raw color images acquired by the handheld inspection device are converted and stored as a raw color image matrix. The raw color image matrix contains three channels of data: red, green and blue. The data of each channel is arranged according to the row index and column index. For each pixel position in the original color image matrix, read the brightness value of the current pixel in the red, green and blue channels from the original color image matrix, add the brightness values ​​of the three channels and divide by the number of channels to obtain the grayscale brightness value of the current pixel, and organize the grayscale brightness values ​​of all pixels into a grayscale image matrix according to the corresponding row index and column index.

3. The method for detecting fine scratches on a blue film based on image enhancement according to claim 2, characterized in that, The grayscale image matrix is ​​divided into multiple sub-regions in the horizontal and vertical directions. The average grayscale brightness value of each sub-region and the global average grayscale brightness value of the entire grayscale image matrix are obtained. A gamma transform index is then set for each sub-region based on the ratio of these two values. Specifically, this includes: The number of sub-regions of the grayscale image matrix is ​​set in the horizontal direction and the number of sub-regions of the grayscale image matrix is ​​set in the vertical direction. Based on the row number parameter and column number parameter, the grayscale image matrix is ​​divided into several non-overlapping rectangular sub-regions according to the equal interval of row index and column index. Each sub-region is identified by numbering in the vertical and horizontal directions. For each sub-region, set the start index and end index in the row index direction and column index direction according to the number to form the index range of continuous pixel rows and pixel columns covered by the corresponding sub-region, and collect all pixel positions within the index range defined by the start index and end index to construct the pixel index set within the sub-region; For each sub-region, the pixel positions are traversed one by one in the pixel index set, the corresponding grayscale brightness value is read from the grayscale image matrix, the grayscale brightness values ​​of all pixels in the corresponding sub-region are summed and divided by the number of pixels to obtain the average grayscale brightness value of the corresponding sub-region. For the entire grayscale image matrix, traverse all pixel positions within all row and column indices, read the corresponding grayscale brightness values, sum the grayscale brightness values ​​of all pixels and divide by the total number of pixels to obtain the global average grayscale brightness value of the entire grayscale image matrix. For each sub-region, the gamma transform index is calculated based on the ratio between the average grayscale value of the corresponding sub-region and the global average grayscale value of the entire grayscale image matrix, and the gamma transform index is associated with and stored with the corresponding sub-region number.

4. The method for detecting fine scratches on a blue film based on image enhancement according to claim 3, characterized in that, The process of performing nonlinear brightness mapping on each pixel in the grayscale image matrix based on the gamma transform exponent of the sub-region where the pixel is located to obtain the enhanced grayscale image matrix specifically includes: Create an enhanced grayscale image matrix that has the same number of rows and columns as the grayscale image matrix; For each pixel position in the grayscale image matrix, the corresponding gamma transform index is read from the associated stored gamma transform index record according to the number of the sub-region where the pixel is located. For each pixel, the grayscale brightness value is normalized according to a preset grayscale range. The normalized value is then mapped by exponentiation of the gamma transform. Finally, it is inversely normalized according to the preset grayscale range to obtain the enhanced grayscale brightness value of the current pixel. The enhanced grayscale brightness values ​​of all pixels are then written into the enhanced grayscale image matrix according to the original row and column indices.

5. The method for detecting fine scratches on a blue film based on image enhancement according to claim 4, characterized in that, In the enhanced grayscale image matrix, a neighborhood of a defined size is constructed around each pixel, the average grayscale brightness value of the neighborhood is obtained, and a difference image matrix is ​​generated based on the difference between the enhanced grayscale brightness value and the average grayscale brightness value of the neighborhood. Specifically, this includes: For each pixel position in the enhanced grayscale image matrix, extend it forward and backward by one pixel step in the row index direction and the column index direction respectively, and truncate it at the position that exceeds the boundary of the enhanced grayscale image matrix to obtain the set of neighborhood pixel coordinates around the current pixel, which is extended by one pixel in the row direction and the column direction respectively. Establish a local average image matrix with the same size as the enhanced grayscale image matrix; traverse the pixel positions one by one in the neighborhood pixel coordinate set, read the enhanced grayscale brightness value of the corresponding pixel from the enhanced grayscale image matrix, sum the enhanced grayscale brightness values ​​of all pixels in the neighborhood and divide by the number of neighborhood pixels to obtain the neighborhood average grayscale brightness value of the current pixel, and write the neighborhood average grayscale brightness value into the local average image matrix at the position corresponding to the current pixel position; For each pixel location, the enhanced grayscale brightness value is read from the enhanced grayscale image matrix, and the neighborhood average grayscale brightness value is read from the local average image matrix. The difference between the two is calculated and the absolute value is taken to obtain the differential brightness value. The differential brightness values ​​of all pixels are organized into a differential image matrix according to the row index and column index.

6. The method for detecting fine scratches on a blue film based on image enhancement according to claim 5, characterized in that, The step of introducing a structuring element opening operation on the difference image matrix to obtain the erosion result image matrix and the opening operation result image matrix, and constructing the top cap image matrix based on the difference between the two, specifically includes: Establish a set of structural element offsets. The structural elements are circular structural elements with a unit of pixels and a radius of two pixels. Each element in the set contains a row offset and a column offset, and both the row offset and the column offset are integers. For each pixel position in the difference image matrix, based on the structuring element offset set and the boundary position of the difference image matrix, offsets that do not exceed the range of the number of rows and columns of the difference image matrix in both row and column indices are selected to generate a structuring element offset subset corresponding to the current pixel position. For each pixel location, among all pixel locations covered by the structuring element offset subset, the corresponding differential brightness value is read from the differential image matrix, and the minimum value is selected as the pixel value of the erosion result image matrix at the current pixel location. A dilation operation is performed on the erosion result image matrix. For each pixel position, based on the structuring element offset subset, the pixel values ​​of all covered pixel positions are read from the erosion result image matrix, and the maximum value is selected as the pixel value of the opening operation result image matrix at the current pixel position. For each pixel position, read the differential brightness value from the differential image matrix, read the corresponding pixel value from the opening operation result image matrix, subtract the opening operation result pixel value from the differential brightness value to obtain the top cap brightness value, and organize all the top cap brightness values ​​into a top cap image matrix according to the row index and column index.

7. The method for detecting fine scratches on a blue film based on image enhancement according to claim 6, characterized in that, The process uses the top-hat image matrix as input to obtain the top-hat brightness difference between left and right adjacent pixels and top and bottom adjacent pixels, forming a horizontal response matrix and a vertical response matrix, specifically including: A horizontal response matrix is ​​established based on the top-hat image matrix. When the top-hat image matrix contains only one column of pixels, the horizontal response values ​​of all pixels in that column are set to zero. When the top-hat image matrix contains multiple columns of pixels, for each pixel in each column except the last column, the absolute value of the top-hat brightness difference between the current pixel and its right-side adjacent pixel is calculated as the horizontal response value of the current pixel. For each pixel in the last column, the absolute value of the top-hat brightness difference between the current pixel and its left-side adjacent pixel is calculated as the horizontal response value of the current pixel. A vertical response matrix is ​​established based on the top-hat image matrix. When the top-hat image matrix contains only one row of pixels, the vertical response values ​​of all pixels in that row are set to zero. When the top-hat image matrix contains multiple rows of pixels, for each pixel in each row except the last row, the absolute value of the top-hat brightness difference between the current pixel and the pixels in the same column of the next row is calculated as the vertical response value of the current pixel. For each pixel in the last row, the absolute value of the top-hat brightness difference between the current pixel and the pixels in the same column of the previous row is calculated as the vertical response value of the current pixel. At each pixel location, the corresponding response value is read from the horizontal response matrix and the vertical response matrix. The larger of the two response values ​​is selected as the response value of the composite linear response matrix at the current pixel location, and the composite linear response matrix is ​​constructed.

8. The method for detecting fine scratches on a blue film based on image enhancement according to claim 7, characterized in that, The method involves selecting the larger response value from the horizontal and vertical response matrices at each pixel location to form a comprehensive linear response matrix. The maximum response value is obtained from the comprehensive linear response matrix. Normalization is performed on the response values ​​of each pixel, and a normalized response threshold is set based on the distribution of the normalized response values, thus obtaining the scratch binary image matrix. Specifically, this includes: Traverse all pixel positions in the composite linear response matrix, read the composite linear response value of each pixel, and obtain the maximum response value. When the maximum response value is greater than zero, for each pixel, the comprehensive linear response value is divided by the maximum response value to obtain the normalized response value; when the maximum response value is equal to zero, the normalized response values ​​of all pixels are set to zero, and a normalized response matrix with the same size as the comprehensive linear response matrix is ​​constructed. The normalized response values ​​of all pixel positions in the normalized response matrix are formed into a finite set of real numbers. The elements in this finite set of real numbers are sorted in ascending order of value, and the element in the middle position after sorting is taken as the normalized response threshold. For each pixel location, the normalized response value is compared with the normalized response threshold. When the normalized response value is greater than the threshold, the value of the scratch binary image matrix at the current pixel location is set to one. When the normalized response value is less than or equal to the threshold, the value of the scratch binary image matrix at the current pixel location is set to zero, thus constructing the scratch binary image matrix.

9. The method for detecting fine scratches on a blue film based on image enhancement according to claim 8, characterized in that, The step of mapping the scratch binary image matrix to the original color image matrix pixel-by-pixel to construct the output color image matrix, with the scratch pixel positions marked in red, specifically includes: Create an output color image matrix with the same number of rows and columns as the original color image matrix, and set up brightness storage units for the red, green and blue channels at each pixel position; For each pixel position, read the value of the current pixel position from the scratch binary image matrix. When the value is 1, set the red channel brightness of the output color image matrix at the current pixel position to the preset maximum brightness, set the green channel brightness to the preset minimum brightness, and set the blue channel brightness to the preset minimum brightness. When the value is zero in the scratch binary image matrix, the red channel brightness, green channel brightness and blue channel brightness of the current pixel position are read from the original color image matrix, and the three channel brightness of the output color image matrix at the current pixel position are set to the corresponding original brightness values ​​respectively. The output color image matrix is ​​used as the blue film fine scratch detection result image matrix, and the pixel positions with a value of one in the scratch binary image matrix are formed into red scratch mark areas.