Optical lens surface defect detection method and system based on image processing
By performing color channel decomposition and contrast adjustment on the surface image of the optical lens, calculating local channel differences and spatial gradients, and generating a dispersion gradient map, combined with multi-scale brightness enhancement and local standard deviation analysis, the accuracy and stability problems of optical lens surface defect detection in the prior art are solved, and the detection effect is improved.
Patent Information
- Application Number
- CN202510971430.6
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2025-07-15
- Publication Date
- 2025-10-31
- Estimated Expiration
- Not applicable · inactive patent
AI Technical Summary
Existing technologies cannot effectively distinguish and detect surface defects of different sizes and types of optical lenses, which can easily lead to missed detections or misjudgments.
By performing color channel decomposition and contrast adjustment on the surface image of the optical lens, calculating local channel differences and spatial gradients, generating a dispersion gradient map, and combining multi-scale brightness enhancement and local standard deviation analysis, the coordinates of the defect area are determined.
It improves the accuracy and stability of optical lens surface defect detection, enhances the response capability to minute defects, and reduces the risk of false detection.
Smart Images

Figure CN120876390A_ABST
Abstract
Description
Technical Field
[0001] This invention relates to the field of image processing technology, and in particular to a method and system for detecting surface defects in optical lenses based on image processing. Background Technology
[0002] Image processing-based methods for detecting surface defects in optical lenses utilize image processing techniques to perform feature analysis, image enhancement, and difference recognition on images of the lens surface, thereby detecting defective areas or minute imperfections. Existing technologies fail to effectively differentiate defects of different scales and types, leading to missed detections or false positives when detecting minute defects or low-contrast defect areas. Therefore, improvements are needed. Summary of the Invention
[0003] The purpose of this invention is to overcome the shortcomings of the existing technology and propose an optical lens surface defect detection method and system based on image processing.
[0004] To achieve the above objectives, the present invention adopts the following technical solution: a method for detecting surface defects of an optical lens based on image processing, comprising the following steps: Acquire an image of the optical lens surface, decompose the image into three independent color channel intensity data: red, green and blue, adjust the contrast of each color channel intensity data, and generate a set of corrected color channels. Based on the set of corrected color channels, the intensity of the green color channel and the intensity of the red color channel are selected, and the intensity difference between the two is calculated in the preset pixel neighborhood to obtain a local channel difference value array. Based on the local channel difference value array, the spatial gradient magnitude of each difference in the local channel difference value array is calculated to establish a dispersion gradient map. Based on the set of corrected color channels, the average brightness value is calculated to form a single-channel brightness image. Multi-scale center-around difference operation is performed on the single-channel brightness image to obtain a preliminary enhanced brightness map. Based on the preliminary enhanced brightness map, the gradient values of the pixels and the corresponding positions of the dispersion gradient map are fused to generate significant defect feature data. Based on the defect salient feature data, the local standard deviation of the defect salient feature data is calculated in the pixel neighborhood of each pixel to obtain a local variation map. Based on the local variation map, the variation regions are distinguished and the coordinates of the optical lens defect region are established.
[0005] Preferably, the step of obtaining the corrected color channel set is as follows: Acquire an image of the optical lens surface, and perform color channel separation on the optical lens surface image, splitting it into independent red color channel intensity data, green color channel intensity data, and blue color channel intensity data to form initial color channel intensity data; Based on the initial color channel intensity data, the contrast of the red color channel intensity data, green color channel intensity data and blue color channel intensity data are adjusted respectively. By adjusting the dynamic range of pixel intensity within the channel, contrast-enhanced color channel intensity data is formed. Based on the contrast-enhanced color channel intensity data, the adjusted red color channel intensity data, green color channel intensity data, and blue color channel intensity data are merged to obtain the corrected color channel set.
[0006] Preferably, the step of obtaining the local channel difference value array is as follows: Based on the set of corrected color channels, the intensity data of the green color channel and the intensity data of the red color channel are called from the set of corrected color channels respectively. Taking the position of each pixel in the intensity data of the green color channel as a reference, a square area with the pixel as the center and the side length of a preset fixed length is selected to determine the area range within the preset pixel neighborhood and form pixel neighborhood area data. Based on the pixel neighborhood region data, the green color channel intensity data and the red color channel intensity data are called respectively. For each corresponding pixel point in the preset pixel neighborhood, the pixel intensity value difference is calculated point by point. The pixel intensity value of the green color channel intensity data is subtracted from the corresponding pixel intensity value of the red color channel intensity data to form the point-by-point pixel intensity difference data. Based on the pixel intensity difference data, the pixel intensity differences in all preset pixel neighborhood regions are summarized and combined one by one according to the original image pixel arrangement order to obtain a local channel difference value array.
[0007] Preferably, the step of obtaining the dispersion gradient map is as follows: Based on the local channel difference value array, the channel difference values of the two adjacent pixels above and below and the two adjacent pixels to the left and right are extracted from each pixel position in the image to construct the difference value group of each pixel in the vertical and horizontal directions. At the same time, the brightness intensity difference between the current pixel and its adjacent pixels on the diagonal is extracted to obtain the local direction channel difference value group and the brightness diagonal difference value group. The spatial gradient comprehensive amplitude is calculated based on the local directional channel difference group and the brightness diagonal difference group; Based on the spatial gradient composite magnitude, the spatial gradient composite magnitude calculated for each pixel position is sequentially assigned back to the original pixel position according to the pixel arrangement order of the image, thereby generating a dispersion gradient map.
[0008] Preferably, the step of obtaining the preliminary enhanced brightness map is as follows: Based on the corrected color channel set, the channel intensity value of each pixel position is extracted from the red color channel intensity data, green color channel intensity data and blue color channel intensity data respectively. The corresponding pixel positions of the three channels are summed and divided by three to generate the average brightness value of each pixel, forming a single-channel brightness image. Based on the single-channel brightness image, calculate the multi-scale center-surround differential enhancement value for each pixel; Based on the multi-scale center-surround differential enhancement values, the enhancement values of all pixel positions are normalized and mapped and then filled into the corresponding image positions to form a preliminary enhanced brightness map.
[0009] Preferably, the steps for obtaining the significant feature data of the defects are as follows: Based on the preliminary enhanced brightness map, the enhanced brightness value at each pixel position in the preliminary enhanced brightness map is extracted one by one. At the same time, the spatial gradient comprehensive amplitude at each pixel position is extracted one by one from the corresponding pixel position in the dispersion gradient map. A pixel pair mapping relationship between brightness and gradient is established according to the pixel position to obtain brightness gradient mapping data. Based on the brightness gradient mapping data, each pair of pixels in the mapping data is numerically normalized. Taking the initial enhanced brightness value at each pixel position as a reference, the corresponding spatial gradient comprehensive amplitude is proportionally scaled and then numerically superimposed and fused with the brightness value point by point to obtain the normalized pixel fusion value. Based on the normalized pixel fusion value, the pixel positions are sequentially mapped back to the original coordinate positions of the image to obtain the significant feature data of the defects.
[0010] Preferably, the steps for obtaining the local variation degree map are as follows: Based on the defect salient feature data, taking each pixel position in the defect salient feature data as the center, extract the defect salient feature values of all pixels within a square neighborhood with a fixed odd number of pixels as the center, and store all the extracted feature values within the neighborhood position pixel by pixel to obtain a set of pixel neighborhood feature values. Based on the set of pixel neighborhood feature values, the average value of all significant defect feature values in the set is calculated one by one. Based on the difference between each significant defect feature value in the neighborhood of each pixel position and the corresponding average value, the square of the difference is calculated one by one. Then, the squared differences are summed for each pixel position and divided by the number of pixels in the neighborhood. Finally, the square root operation is performed to obtain the local standard deviation value of each pixel position. Based on the local standard deviation values, according to the original image size of the defect salient feature data, all local standard deviation values are mapped to their original corresponding pixel positions one by one, and the pixel positions are filled to form a complete image data matrix, thus obtaining a local variation map.
[0011] Preferably, the step of obtaining the coordinates of the optical lens defect region is as follows: Based on the local variation map, the local standard deviation of each pixel in the image is extracted pixel by pixel, and the maximum, minimum and median values of the local standard deviation are obtained from all pixels. At the same time, the local standard deviation of the current pixel is extracted, and the correlation parameter set between the current pixel and the overall distribution benchmark is constructed to obtain the local variation statistical parameter set. Based on the set of local variation statistical parameters, calculate the local variation judgment threshold for each pixel; Based on the local variation judgment threshold of each pixel, it is compared with the local standard deviation value corresponding to the current pixel. If the local standard deviation value of the current pixel is greater than or equal to the local variation judgment threshold, it is marked as a pixel in a high variation region; otherwise, it is marked as a pixel in a low variation region, thus generating the coordinates of the optical lens defect region.
[0012] This invention provides an optical lens surface defect detection system, comprising: Image preprocessing module: acquires an image of the optical lens surface, decomposes the image of the optical lens surface into three independent color channel intensity data of red, green and blue, adjusts the contrast of the color channel intensity data of each channel, and generates a set of corrected color channels; Color difference analysis module: Based on the set of corrected color channels, select the intensity of green color channel and red color channel, calculate the intensity difference between the two in the preset pixel neighborhood, obtain a local channel difference value array, calculate the spatial gradient magnitude of each difference in the local channel difference value array based on the local channel difference value array, and establish a dispersion gradient map; Brightness enhancement and fusion module: Based on the set of corrected color channels, calculate the average brightness value to form a single-channel brightness image, perform multi-scale center-around difference operation on the single-channel brightness image to obtain a preliminary enhanced brightness map, and based on the preliminary enhanced brightness map, fuse the gradient values of the pixels with the corresponding positions of the dispersion gradient map to generate significant defect feature data; Defect localization module: Based on the defect salient feature data, calculate the local standard deviation of the defect salient feature data in the pixel neighborhood of each pixel to obtain a local variation map. Based on the local variation map, distinguish the variation regions and establish the coordinates of the optical lens defect region.
[0013] Compared with the prior art, the advantages and positive effects of the present invention are as follows: This invention improves the color difference between defective and background areas in optical lens images by performing detailed color channel decomposition and targeted contrast adjustment on the acquired images, thus enhancing the detail expression of defective areas. Furthermore, by locally calculating the intensity differences between color channels and analyzing spatial gradient amplitude, it effectively integrates color changes with spatial features, strengthening the visual expressiveness of defective areas. Simultaneously, during single-channel brightness processing, multi-scale center-around differential operations are used to improve the sensitivity of brightness anomaly areas at different scales, enhancing the response capability to minute defects. In feature fusion, multi-scale brightness information and dispersion gradient information are fused to extract salient features of defective areas, reducing the risk of false detection in irrelevant areas. Finally, by performing local standard deviation analysis on the salient feature data of defects, local fluctuation information is used to delineate the boundaries of highly variable areas, determining the specific coordinate location of defects, thereby improving the accuracy and stability of optical lens surface defect detection. Attached Figure Description
[0014] Figure 1 This is a schematic diagram of the steps of the present invention. Detailed Implementation
[0015] To make the objectives, technical solutions, and advantages of this invention clearer, the invention will be further described in detail below with reference to the accompanying drawings and embodiments. It should be understood that the specific embodiments described herein are merely illustrative and not intended to limit the invention.
[0016] Please see Figure 1 This invention provides a technical solution: a method for detecting surface defects in optical lenses based on image processing, comprising the following steps: Acquire an image of the optical lens surface, decompose the image into three independent color channel intensity data: red, green and blue, adjust the contrast of each color channel intensity data, and generate a set of corrected color channels. Based on the set of corrected color channels, the intensity of the green color channel and the intensity of the red color channel are selected. The intensity difference between the two is calculated in the preset pixel neighborhood to obtain a local channel difference value array. Based on the local channel difference value array, the spatial gradient magnitude of each difference in the local channel difference value array is calculated to establish a dispersion gradient map. Based on the set of corrected color channels, the average brightness value is calculated to form a single-channel brightness image. Multi-scale center-around difference operation is performed on the single-channel brightness image to obtain a preliminary enhanced brightness map. Based on the preliminary enhanced brightness map, the gradient values of the corresponding positions of the pixels and the dispersion gradient map are fused to generate significant defect feature data. Based on the salient feature data of defects, the local standard deviation of the salient feature data of defects is calculated in the pixel neighborhood of each pixel to obtain a local variation map. Based on the local variation map, the variation regions are distinguished and the coordinates of the defect region of the optical lens are established.
[0017] The steps to obtain the corrected color channel set are as follows: Acquire an image of the optical lens surface, and perform color channel separation on the optical lens surface image, splitting it into independent red color channel intensity data, green color channel intensity data, and blue color channel intensity data to form initial color channel intensity data; Based on the initial color channel intensity data, the contrast of the red, green, and blue color channel intensity data is adjusted respectively. By adjusting the dynamic range of pixel intensity within the channel, contrast-enhanced color channel intensity data is formed. Based on the contrast-enhanced color channel intensity data, the adjusted red, green, and blue color channel intensity data are merged to obtain the corrected color channel set.
[0018] Specifically, the acquired image of the optical lens surface, captured by an industrial camera under controlled lighting conditions, is stored digitally as a two-dimensional pixel matrix. Each pixel contains three color components: red, green, and blue. For example, each component can be an 8-bit unsigned integer with a value between 0 and 255. Color channel separation processing is then performed on this optical lens surface image. This process involves traversing every pixel in the image. Specifically, for any coordinate position in the image... Extract the corresponding red color component value from the pixels. Green color component value and blue color component value Next, three independent two-dimensional data structures are created, with dimensions exactly matching the width and height of the original optical lens surface image. The first data structure stores the red color component values of all pixels, forming independent red color channel intensity data. The value at that location is Similarly, the second data structure is used to store the green color component values of all pixels, forming independent green color channel intensity data, which is located at... The value at that location is The third data structure stores the blue color component values of all pixels, forming independent blue color channel intensity data, which is located at... The value at that location is Through the above separation operation, the original multi-channel color image is decomposed into three single-channel grayscale representations, which together constitute the initial color channel intensity data.
[0019] Based on the initial color channel intensity data obtained in the previous step, namely, independent red, green, and blue color channel intensity data, contrast adjustment operations are performed on the data of these three channels respectively. This adjustment aims to optimize the distribution of pixel intensity within each color channel to expand its dynamic range. Specifically, a method called percentage-truncation linear stretching is used to process each color channel independently. First, for the color channel being processed (e.g., red color channel intensity data), the cumulative distribution histogram of all its pixel intensity values is calculated. Then, two percentage truncation parameters are set, with the lower digit truncated by a percentage. and high-level cutoff percentage These two parameters are set based on experience, for example, It can be set to 1%. It can be set to 99% to eliminate the impact of extremely bright or dark outlier pixels on the overall contrast adjustment, based on the cumulative distribution histogram and the set value. Find an intensity value This value satisfies the channel requirements. The proportion of pixels whose intensity is less than or equal to Similarly, according to Find an intensity value This value satisfies the channel requirements. The proportion of pixels whose intensity is less than or equal to (or rather, The ratio of pixels has an intensity greater than Taking the red channel as an example, let's perform a calculation: For instance, if its pixel intensity ranges from 0 to 255, by analyzing its cumulative pixel intensity distribution histogram, if we set... Calculate the corresponding Set to 20. Calculate the corresponding If the value is 235, then the effective input dynamic range of this channel is determined to be... Then, the original pixel intensity values within this range are... A linear mapping to the target output dynamic range is typically standard. The calculation method used is ,in and Substituting the values into the example gives us... For the original strength Less than (i.e., pixels less than 20) have their adjusted intensity It was set to 0, while for the original strength Greater than (i.e., pixels greater than 235) have their adjusted intensity Set to 255, this contrast adjustment process is also applied independently to the green and blue color channel intensity data, calculating their respective values separately. and It is then stretched to create contrast-enhanced color channel intensity data.
[0020] Based on the contrast-enhanced color channel intensity data obtained by adjusting the contrast of the red, green, and blue color channel intensity data in the previous step, a color channel merging operation is performed. This operation aims to reintegrate the three independently optimized single-channel data into a multi-channel color image representation. Specifically, a new image data structure is first created, whose spatial dimensions (i.e., the number of pixels in width and height) are consistent with the original acquired optical lens surface image and the individual color channel intensity data. Each pixel location in this new image data structure will be used to store a color value containing three color components (red, green, and blue). The merging process is completed by filling in the data pixel by pixel, that is, for each pixel coordinate in the image... Read the coordinate position from the contrast-enhanced red color channel intensity data. The adjusted red intensity value at the location is denoted as Similarly, the same coordinate position is read from the contrast-enhanced green color channel intensity data. The adjusted green intensity value at the location is denoted as And read the corresponding coordinate position from the contrast-enhanced blue color channel intensity data. The adjusted blue intensity value at the location is denoted as Then, these three independent intensity values , and The coordinates are combined according to a predetermined color order (e.g., RGB order) to form the coordinates in the new image data structure. The final color value of a pixel is obtained by iterating through all pixel positions until the entire image area is covered. The final data generated is the set of corrected color channels.
[0021] The steps for obtaining the local channel difference value array are as follows: Based on the set of corrected color channels, the intensity data of the green color channel and the intensity data of the red color channel are called from the set of corrected color channels respectively. Taking the position of each pixel in the intensity data of the green color channel as the reference, a square area with the pixel as the center and the side length of the preset fixed length is selected to determine the area range within the preset pixel neighborhood and form the pixel neighborhood area data. Based on the pixel neighborhood region data, the green color channel intensity data and the red color channel intensity data are called respectively. For each corresponding pixel point in the preset pixel neighborhood, the pixel intensity value difference is calculated point by point. The pixel intensity value of the green color channel intensity data is subtracted from the corresponding pixel intensity value of the red color channel intensity data to form the pixel intensity difference data point by point. Based on the pixel intensity difference data, the pixel intensity differences in all preset pixel neighborhood regions are summarized and combined one by one according to the original image pixel arrangement order to obtain a local channel difference value array.
[0022] Specifically, based on the set of corrected color channels obtained in the previous steps, the contrast-adjusted green and red color channel intensity data are first extracted from this set. Both of these data are two-dimensional arrays with the same size as the original optical lens surface image, storing the pixel intensity values of the corresponding color channels. Then, the green color channel intensity data (or equivalently, the intensity values of each pixel position in the original image) are used to refine the data. Using this as the reference center point for the current processing, a local square region is selected around this center point. The side length of this square region is a pre-defined fixed length. This length It must be a positive odd number, such as 3, 5, or 7. The specific value is selected based on prior knowledge of the typical defect size on the optical lens surface and a comprehensive consideration of the image noise level. For example, if analysis of sample defect images determines that the feature size of most of the minute defects to be detected is distributed within the range of 3 to 5 pixels, and considering the balance between smoothing effects and detail preservation in subsequent calculations, a preset fixed length can be set. 100 pixels, that is, the neighborhood window size is 100 pixels. Pixels, after the center point is determined and side length Then, the area covering the coordinates can be defined by expanding from this center point. arrive The complete region range within the preset pixel neighborhood, for those located at the image edge and unable to form a complete range. The neighboring pixels are expanded using a mirror padding strategy. This involves copying the pixel values from the image boundary to fill the portion of the neighborhood outside the image, ensuring that each reference pixel has a complete neighborhood. Then, for each reference pixel... and its determined The neighborhood is formed by extracting the intensity values of all pixels within the neighborhood from the green and red color channel intensity data, respectively, to form the pixel neighborhood region data corresponding to the reference point. This data includes the set of green intensity values and the set of red intensity values of the neighborhood.
[0023] Based on the pixel neighborhood region data obtained for each reference pixel in the previous step, this data specifically includes each The set of green and red color channel intensity values within the neighborhood window is then used to process these extracted neighborhood intensity values for each reference pixel. Corresponding Neighborhood (e.g., when) , then (the neighborhood of the given area), traversing all the elements within that neighborhood. For each pixel position, the relative coordinates within the neighborhood are: Pixels (of which and The range of values is from arrive For example, when hour, Its absolute coordinates in the original image are Obtain the pixel intensity value of this point in the green color channel intensity data, denoted as . Simultaneously, obtain the corresponding pixel intensity value in the red color channel intensity data, denoted as... Then, the pixel intensity values at these two corresponding positions are calculated point-by-point. Specifically, the pixel intensity value in the green color channel intensity data is subtracted from the corresponding pixel intensity value in the red color channel intensity data to calculate the difference. This difference calculation will be used for the current baseline pixel. A difference is generated for each pixel in the neighborhood of each reference pixel, thus forming a difference for each reference pixel. A set of differences, calculated for the neighborhood of each reference pixel. These differences together constitute the pixel intensity difference data.
[0024] Based on the pixel intensity difference data calculated for the neighborhood of each reference pixel in the previous step, i.e., each reference pixel Each corresponds to a containment One (e.g.) (25 differences at the time) The next step is to summarize the difference information within these neighborhoods to obtain a single value that can represent the local channel difference at the location of the reference pixel. Specifically, for each reference pixel... and its corresponding The intensity difference of all pixels in the neighborhood Calculate the average of these differences, which is achieved by averaging all differences within the neighborhood. Add up the differences and then divide by the total number of pixels in the neighborhood. That is, local channel difference value ,in At the reference pixel Within the neighborhood of, the relative position is The difference between the green channel intensity and the red channel intensity of a point is calculated by averaging these neighborhood differences for each reference pixel. This yields a two-dimensional dataset with the same dimensions (width and height) as the original image (or the image after boundary padding). Then, the average difference of these calculated values is... According to the corresponding reference pixels in the original image The spatial arrangement order is used to fill the corresponding positions in this new two-dimensional data structure one by one, thus finally obtaining the local channel difference value array.
[0025] The steps to obtain the dispersive gradient map are as follows: Based on the local channel difference value array, the channel difference values of the two adjacent pixels above and below and the two adjacent pixels to the left and right are extracted from each pixel position in the image to construct the difference value group of each pixel in the vertical and horizontal directions. At the same time, the brightness intensity difference between the current pixel and its adjacent pixels on the diagonal is extracted to obtain the local direction channel difference value group and the brightness diagonal difference value group. The spatial gradient comprehensive amplitude is calculated based on the local directional channel difference group and the brightness diagonal difference group. The calculation formula is as follows: ; in, Indicates the first The combined magnitude of the spatial gradient at each pixel location and These represent the values of the local channel difference array. Line 1 Column and number Line 1 Channel difference values of the column and Indicates the first Line 1 Column and number Channel difference values of the column Represents the first in the brightness image Line 1 The brightness intensity value of the column, Indicates the first Line 1 The brightness intensity value of the column, The mean square reference value representing the range of channel difference intensity. A reference value representing the average value of the brightness intensity range; Based on the spatial gradient comprehensive magnitude, the spatial gradient comprehensive magnitude calculated for each pixel position is sequentially assigned back to the original pixel position according to the pixel arrangement order of the image, thereby generating a dispersion gradient map.
[0026] Specifically, based on the local channel difference value array obtained in the previous steps, this array is a two-dimensional array with the same size as the original optical lens surface image, where each element... This represents the corresponding pixel position in the original image. At this location, the average difference between the green channel intensity and the red channel intensity within its local neighborhood is calculated. Next, for each pixel location in this local channel difference value array... First, it is necessary to extract the difference information between adjacent channels in the vertical and horizontal directions. Specifically, this involves reading the data located at the current pixel. Channel difference values of adjacent pixels above Channel difference value between the pixel below and the adjacent pixel And read the channel difference value of the neighboring pixel to the left of the current pixel. Channel difference value between the pixel and the pixel to the right Using these extracted values, the vertical channel difference variation is constructed, i.e. The change in channel difference in the horizontal direction, i.e. At the same time, it is also necessary to utilize a pre-generated single-channel brightness image. (This brightness image was obtained in an earlier step by calculating the average brightness of the corrected color channel set, where each pixel...) (Representing the brightness intensity at the corresponding location), extract the current pixel from this brightness image. Brightness intensity value and the brightness intensity value of its lower right diagonal adjacent pixel. And calculate the difference in brightness intensity between the two, i.e. When processing pixels at image boundaries, to ensure that all necessary adjacent pixel values can be obtained, mirror padding is used to extend the boundaries of both the local channel difference array and the single-channel brightness image. The extension width is at least one pixel. Through the above operation, the position of each pixel is determined. This yields a set of data including the vertical channel difference change, the horizontal channel difference change, and the brightness intensity difference in a specific diagonal direction. This set of data is the local directional channel difference set and the brightness diagonal difference set.
[0027] formula: The advantage of this formula lies in its calculation of the gradient magnitude by comprehensively considering changes in local channel differences (related to color characteristics) and brightness information. The first term captures the drastic change in color difference in the vertical direction, while the second term cleverly integrates changes in color difference in the horizontal direction with changes in brightness in the diagonal direction. This makes the gradient more sensitive to defect regions that exhibit abnormalities in both color and brightness. Unlike traditional gradient operators that rely solely on brightness or a single color channel, this formula utilizes multimodal information, which helps to more accurately identify specific types of optical defects, such as those caused by dispersion, in complex backgrounds. and The introduction of this method normalizes and adjusts the contribution weights of each part, making the gradient value less sensitive to changes in the overall brightness and contrast of the input image, thereby improving the robustness of defect detection. parameter The steps to obtain it are as follows: This parameter represents the currently processed pixel in the local channel difference value array. The next row and column position (i.e.) The local channel difference values (at position) are a two-dimensional array calculated in the previous step. The numerical range of its elements depends on the intensity range of the original red and green channels (e.g., 0-255) and their differences, typically within... To retrieve the values, simply index the corresponding coordinates from the array. For example, if the currently processed pixel is in row 100 and column 50, then... This refers to the element value in the 101st row and 50th column of the local channel difference value array.
[0028] parameter The steps to obtain it are as follows: This parameter represents the currently processed pixel in the local channel difference value array. The position in the same column above (i.e.) The channel difference value (location), obtained in the same way as Similarly, the corresponding coordinates can be directly indexed from the local channel difference value array. For example, if the currently processed pixel is in row 100 and column 50, then... This refers to the element value in row 99 and column 50 of the local channel difference value array.
[0029] parameter The steps to obtain it are as follows: This parameter represents the currently processed pixel in the local channel difference value array. The position of the next column in the same row (i.e.) The channel difference value (position) is obtained by directly indexing the corresponding coordinates from the local channel difference value array. For example, if the currently processed pixel is in row 100 and column 50, then... This refers to the value of the element in the 100th row and 51st column of the local channel difference value array.
[0030] parameter The steps to obtain it are as follows: This parameter represents the currently processed pixel in the local channel difference value array. The position of the previous column in the same row (i.e.) The channel difference value (position) is obtained by directly indexing the corresponding coordinates from the local channel difference value array. For example, if the currently processed pixel is in row 100 and column 50, then... This refers to the element value in the 100th row and 49th column of the local channel difference value array.
[0031] parameter The steps to obtain it are as follows: This parameter represents the currently processed pixel in a single-channel brightness image. The brightness intensity value at a given location is represented by a single-channel brightness image, which is a two-dimensional array calculated in a previous step by averaging the intensity values of the red, green, and blue channels of the calibrated color channel set. The numerical range of its elements is typically [value missing]. (For 8-bit images), the corresponding coordinates are directly indexed from the brightness image during acquisition. The value is sufficient; for example, if the currently processed pixel is in row 100 and column 50, then... This refers to the brightness value of that point in the brightness image.
[0032] parameter The steps to obtain it are as follows: This parameter represents the currently processed pixel in a single-channel brightness image. The upper right diagonal (or defined by coordinates as a specific diagonal direction) position (i.e. The brightness intensity value (at position) is obtained by directly indexing the corresponding coordinates from the single-channel brightness image. For example, if the currently processed pixel is in row 100 and column 50, then... This is the brightness value in row 99 and column 51 of the brightness image.
[0033] parameter The steps to obtain the mean square reference value of the channel difference intensity range are as follows: parameter The process for normalizing the changes in local channel difference values is as follows: First, collect a batch (e.g., 100) of representative optical lens surface images without obvious defects. For each image, perform all the aforementioned steps until a corresponding "local channel difference value array" is generated. (in Then, for each array Calculate the variance of all its elements. The calculation formula is: ,in and These are the width and height of the image, respectively. It is an array Middle position The element value, It is an array The average of all elements is calculated, and finally, the average of the variances calculated from all sample images is obtained. Values, for example, through the steps described above, for 100 The local channel difference array of pixels (whose values are mainly distributed between -30 and 30, with a mean close to 0) is calculated to obtain each The average value is 25.36, so set .
[0034] parameter The steps to obtain the average reference value of the brightness intensity range are as follows: parameter Used to normalize the luminance intensity difference, its acquisition process is the same as Similarly: using the same batch of 100 images of the optical lens surface without obvious defects, perform all the aforementioned steps for each image until a corresponding "single-channel brightness image" is generated. (in Then, for each brightness image Calculate the average brightness value of all its pixels. Finally, the average brightness values calculated from all sample images are averaged to obtain the final result. Value, that is This method makes This represents the typical average brightness level of a normal optical lens image; for example, through the steps described above, for 100... The brightness of each pixel (with pixel values ranging from 0 to 255) is calculated to obtain the following values: The average value is 121.75, so set .
[0035] Calculation process: With a specific pixel position For example, substituting actual values into the calculation, we obtain the example values from the aforementioned parameters, as well as, for example, the neighboring pixel values: Set current pixel position The relevant values are: Extracted from the local channel difference value array: ; ; ; ; Extract from a single-channel brightness image: ; ; Based on the calculated reference values: ; ; The calculation process is as follows: Calculate the squared term of the vertical channel difference: ; ; Calculate the square of the product of the horizontal channel difference and the diagonal difference in brightness: Calculate the normalized value of the horizontal channel difference: ; ; Calculate the normalized value of the diagonal difference in brightness: ; ; Calculate the product of the two and square it: ; Calculate the sum of the two terms and take the square root: ; Therefore, for this pixel position (corresponding coordinates) Its spatial gradient comprehensive magnitude .
[0036] This result indicates that at the current pixel position Its spatial gradient comprehensive amplitude is 3.97204. This value reflects the comprehensive change of the channel dispersion characteristics and brightness characteristics in the local area of this point. The larger the value, the more significant the change at this point, and the higher the probability of defects. Conversely, the smaller the value, the more flat the area or the less obvious the change.
[0037] Based on the spatial gradient comprehensive magnitude calculated in the previous step for each pixel location This means that for each or most of the pixels in the image (depending on the boundary processing method, here for example, calculations have been completed for all target pixels), a scalar value is obtained. This value quantifies the combined characteristics of local dispersion and brightness variations. Next, these discrete gradient magnitudes need to be combined into a spatially structured visualization image. Specifically, first, a new two-dimensional array (or image data structure) is created, whose dimensions (width and height) are exactly the same as the dimensions of the original image (or its effective processing area) used when calculating the gradient. Then, the pixel positions from which the calculated spatial gradient combined magnitude is obtained are traversed. The corresponding spatial gradient comprehensive magnitude (in Is with position The unique corresponding index is accurately assigned to the same coordinate in the newly created two-dimensional array. The elements ensure that each gradient value is accurately mapped back to its corresponding position in the original image space. After all pixel positions are assigned, this new two-dimensional array constitutes a dispersion gradient map. The intensity (or gray value) of each pixel in the map is the spatial gradient magnitude of that point, thus transforming abstract gradient information into an intuitive image. High gradient value areas (manifested as brighter areas) indicate potential defect locations or areas of drastic change.
[0038] The steps for obtaining the preliminary enhanced brightness map are as follows: Based on the corrected color channel set, the channel intensity value of each pixel position is extracted from the red color channel intensity data, green color channel intensity data and blue color channel intensity data respectively. The corresponding pixel positions of the three channels are summed and divided by three to generate the average brightness value of each pixel, forming a single-channel brightness image. Based on the single-channel brightness image, the multi-scale center-surround differential enhancement value of each pixel is calculated using the following formula: ; in, Indicates the first Multi-scale center-surround differential enhancement value per pixel Represents the first luminance in a single-channel image Line 1 The brightness value of the column pixels, and , These represent offsets centered on the current pixel. Diagonal and anti-diagonal brightness values at a distance of one pixel Represents a fixed integer offset radius. A fixed scaling factor used to adjust the enhancement intensity. This indicates that the summation and averaging of each group of difference structures is performed within a defined scale range; Based on the multi-scale center-surround differential enhancement value, the enhancement values of all pixel positions are normalized and mapped and then filled into the corresponding image positions to form a preliminary enhanced brightness map.
[0039] Specifically, based on the corrected color channel set obtained from the previous steps, this set contains independent, contrast-adjusted red color channel intensity data. Green color channel intensity data and blue color channel intensity data First, the intensity data of the three color channels needs to be retrieved from the set. These data are two-dimensional arrays with the same spatial dimension as the original optical lens surface image. Next, in order to generate the average brightness value of each pixel, the intensity data of each pixel position in the image will be calculated. Perform the following operations: Extract the value at the current pixel position. The intensity value in the red color channel intensity data. Intensity values in the green color channel intensity data and the intensity value in the blue color channel intensity data. Then, the intensity values of the three extracted channels are summed to obtain the total intensity value. Next, the calculated total strength value Divide by 3 to obtain the average brightness value at that pixel location. If the original channel intensity value is an integer in the range of 0 to 255, then the calculated average brightness value is... The result may contain decimals, in which case it needs to be converted to an integer format suitable for image storage, for example, by rounding to the nearest integer, and ensuring that the result is within the standard grayscale range of 0 to 255. This involves performing the following steps on the calculation result. This operation is applied to all pixels in the image, creating a new two-dimensional array where each element represents the average brightness of the corresponding pixel in the original image. This is the single-channel brightness image.
[0040] formula: The advantage of this formula lies in its ability to enhance local contrast in an image through a multi-scale center-surround difference mechanism. This effectively highlights areas that differ in brightness from their surroundings, particularly for features of different sizes, through parameter... Controlled summation range It achieves information fusion across multiple spatial scales, enabling the algorithm to respond to defects or textures of varying sizes. (Numerator) The absolute difference in brightness between the center pixel and its neighboring pixels in a specific diagonal direction was calculated, reflecting the contrast in that direction. The denominator term... This introduces an adaptive normalization property, where the other diagonal direction is horizontal (or vertical, depending on the direction). When the difference between neighboring pixels in the direction of (understanding) is large, it will suppress the current scale. The contribution of the target features is increased, and vice versa. This design helps reduce interference from background textures and improve the signal-to-noise ratio of target features. It provides direct control over the overall reinforcement strength, allowing the reinforcement effect to be adjusted according to the specific application; parameter The steps to obtain it are as follows: This parameter indicates the position of the currently processed core pixel in the generated single-channel brightness image (the...). Okay, number The brightness values (columns) of a single-channel brightness image are a two-dimensional array, where each element represents the average brightness of the corresponding pixel in the original color image. The values typically range from 0 to 255 (for 8-bit images). That is, directly index the coordinates from the single-channel brightness image. The pixel value at that location; for example, if the pixel brightness value in the 10th row and 20th column of a single-channel brightness image is 128, then... .
[0041] parameter The steps to obtain it are as follows: This parameter represents the value relative to the current core pixel in a single-channel brightness image. At an offset of In the case of coordinates The brightness value of the pixel at that location; this coordinate represents the offset along the image row direction. Units, column direction offset A unit of points, that is, a diagonal direction of the current pixel (if... If the value is in the lower right or upper left (depending on the coordinate system definition), the neighboring pixels are obtained by directly indexing the pixel value at the calculated coordinates from the single-channel brightness image. If the calculated coordinates exceed the image boundary, a mirror padding strategy is used to obtain the value, that is, the nearest pixel value within the boundary is used for padding. For example, if the current pixel is... , Then query The brightness value at that location.
[0042] parameter The steps to obtain it are as follows: This parameter represents the value relative to the current core pixel in a single-channel brightness image. At an offset of In the case of coordinates The brightness value of the pixel at that location; this coordinate represents the offset along the image row direction. Each unit, the column direction is also offset. A point of units, that is, the other diagonal direction of the current pixel (if) If the value is in the lower right or upper left corner, it is the neighboring pixel. The method of obtaining this value is the same as... Similarly, indexing is done directly from the single-channel brightness image, and mirror filling is applied to boundary cases. For example, if the current pixel is... , Then query The brightness value at that location.
[0043] parameter The steps to obtain it are as follows: This parameter represents the value relative to the current core pixel in a single-channel brightness image. At an offset of In the case of coordinates The brightness value of the pixel at this location; this coordinate indicates no offset along the row direction and an offset along the column direction of the image. A unit of points, that is, the current pixel in the horizontal direction (if If the current pixel is (then it is the neighboring pixel on the left), the method is also to directly index from the single-channel brightness image, and to use mirror filling for boundary cases. For example, if the current pixel is , Then query The brightness value at that location.
[0044] parameter The steps to obtain the (fixed integer offset radius) are as follows: parameter The size of the neighborhood considered in multi-scale analysis is determined by prior knowledge of the target defect or feature (such as typical size) and the image resolution. Specifically, a series of candidate models can be selected. Values (e.g., 1, 2, 3) were used in experiments on a sample image set containing known defects to evaluate different The influence of the value on the defect enhancement effect and background noise suppression capability is analyzed by comparing the contrast, signal-to-noise ratio, and other indicators between the defect area and the background area, and selecting the value that can optimally distinguish between the defect and the background. Values, for example, were found in tests on optical lens images containing minute scratches (approximately 3-7 pixels in size) when... At that time, the algorithm's response to these scratches was most sensitive and stable, therefore it was set... .
[0045] parameter The steps to obtain the fixed scaling factor (used to adjust the enhancement intensity) are as follows: parameter Controlling the amplification level of the differential signal affects the contrast of the final enhanced image. Setting this amplification level is an empirical process, requiring a trade-off between enhancement and noise amplification. One approach is to prepare a set of test images with different contrast defects and then experiment with different methods. Values (e.g., from 0.5 to 3.0, in steps of 0.1) are used to observe the visibility of defects and the level of background noise in the enhanced image, selecting a value that allows weak defects to be effectively enhanced without excessively amplifying background noise to the point of interfering with subsequent processing. Values, for example, observed through experiments on a series of optical lens images, when At that time, it can better highlight subtle surface textures and defects, and the overall visual effect of the image and the stability of subsequent processing are both good, so it is set to... .
[0046] Calculation process: With a specific pixel (its coordinates are) For example, substitute the actual values into the calculation.
[0047] Set the current pixel The brightness value .
[0048] Based on the example values obtained from the parameter acquisition steps, set... and .
[0049] therefore, The range of values is .
[0050] Each needs to be calculated The item corresponding to the value: .
[0051] To simplify the example, only the complete calculation is performed. and In this case, and give other... Values, for example, intermediate results.
[0052] set up At that time, the relevant brightness values (obtained by consulting a single-channel brightness image or mirror fill) are: ; ; ; Then for : absolute difference in numerator .
[0053] Absolute difference in the denominator .
[0054] denominator .
[0055] .
[0056] set up hour: .
[0057] .
[0058] .
[0059] absolute difference in numerator .
[0060] Absolute difference in the denominator .
[0061] denominator .
[0062] .
[0063] Set other The calculated value is: for :For example .
[0064] for :For example , , .
[0065] molecular Denominator .
[0066] .
[0067] for :For example .
[0068] Now calculate the sum. : .
[0069] Calculate the denominator .
[0070] Final calculation : .
[0071] This result indicates that in the current pixel (coordinate At point ), the multi-scale center-around differential enhancement value is 0.87166. This value comprehensively reflects the brightness contrast of this pixel with its specific diagonal and horizontal neighbors across multiple scales with a radius of 2. A higher value indicates better performance. The value indicates that the pixel has a significant brightness difference from its surroundings across multiple directions and scales under consideration, suggesting that the pixel may be an edge point or belong to a feature region of interest.
[0072] Based on the previous step, the position of each pixel in the image is... Calculated multi-scale center-surround differential enhancement values ,These The values collectively form a two-dimensional data set with the same size as the original single-channel luminance image, where each value represents the degree of local contrast enhancement for the corresponding pixel. Next, to convert these enhancement values into a standardized format usable for image display and to form a preliminary enhanced luminance map, it is necessary to process all the calculated values... The values are normalized by first iterating through all pixel positions. Find the minimum value among the values. and maximum value ,like and Equal (i.e., all) If all values are the same, then all normalized values You can uniformly set it to the middle value (e.g., 128, if the target range is 0-255) or the minimum value (e.g., 0). Greater than Then for each Values, applying the linear normalization formula Map it to a preset output grayscale range, which is set to a standard 8-bit image grayscale level. and After completing the normalization mapping, a new set of enhanced values is obtained. Then, create a new two-dimensional array with the same size as the original image, and store each normalized augmentation value... Fill the array with its original pixel position In the corresponding positions, a preliminary enhanced brightness map is thus formed. The pixel brightness in this image intuitively reflects the contrast enhancement information in the original image after multi-scale center-around difference operation and normalization.
[0073] The steps for obtaining significant defect feature data are as follows: Based on the preliminary enhanced brightness map, the enhanced brightness value of each pixel position in the preliminary enhanced brightness map is extracted one by one. At the same time, the spatial gradient comprehensive amplitude of each pixel position is extracted one by one from the corresponding pixel position in the dispersion gradient map. The pixel pair mapping relationship between brightness and gradient is established one by one according to the pixel position to obtain brightness gradient mapping data. Based on the brightness gradient mapping data, the values of each pair of pixels in the mapping data are normalized. Taking the initial enhanced brightness value at each pixel position as the benchmark, the corresponding spatial gradient comprehensive amplitude is scaled proportionally and then numerically superimposed and fused with the brightness value point by point to obtain the normalized pixel fusion value. Based on the normalized pixel fusion values, the pixel positions are sequentially mapped back to the original coordinate positions of the image to obtain the significant feature data of the defects.
[0074] Specifically, based on the preliminary enhanced brightness map and dispersion gradient map generated in the previous steps, both of which are two-dimensional image data with the same spatial dimensions as the original optical lens surface image, it is first necessary to process each pixel position in the image one by one. The specific operation is as follows: for any pixel coordinate in the image... Extract the coordinate position from the preliminary enhanced brightness map. The enhanced brightness value is denoted as The enhanced brightness value is typically normalized, for example, its value ranges from 0 to 255. Simultaneously, identical corresponding pixel coordinates are extracted from the dispersion gradient map. The combined magnitude of the spatial gradient on the surface is denoted as . The spatial gradient magnitude reflects the combined intensity of dispersion and brightness variations in the local region at that point. Its numerical range depends on the specific calculation method, calculated for each pixel location in the image. They all obtained such an enhanced brightness value Combined amplitude of spatial gradient The numerical pairs formed This ensures that the pairing strictly corresponds one-to-one with the spatial coordinates of the original image, thereby establishing a direct mapping relationship between the brightness and gradient features of each pixel. All these sets of pixel position values together constitute the brightness gradient mapping data.
[0075] Based on the brightness gradient mapping data obtained in the previous step, this data represents the position of each pixel in the image. It provides a pair of related values, namely the initial brightness enhancement value. Combined amplitude of spatial gradient The next step is to further process each pair of values in these mapped data to fuse these two features. First, for all spatial gradient comprehensive magnitudes... Perform a global numerical normalization operation to unify the numerical range and make it comparable to the units of the initial enhanced brightness values, or to make it a weighting factor. Specifically, identify all... Minimum value and maximum value Then for each Applying the linear minimum-maximum normalization formula to map it to Within the interval, the normalized gradient value is obtained. Next, the initial brightness enhancement value for each pixel location is used. As a baseline for fusion, the normalized gradient values are... Scaling is performed by introducing a fixed scaling factor. To achieve this scaling factor This is used to adjust the contribution strength of gradient information in the final fusion result. Its value is set based on experimental tuning, aiming to enhance the significance of defects while avoiding excessive amplification of noise. For example, if the brightness value is initially increased... The range is You can select The value is 50, and the criterion for selecting this value is to ensure that the scaled gradient term... (its scope becomes) ) contributions and Compared to the main numerical range (e.g., around the average brightness), it can produce effective modulation without overly dominating the fusion result. Experimental comparisons of different... The impact of values (such as test values of 20, 50, 80, 100, etc.) on the final defect detection effect is considered. The value that maximizes the distinction between the defect area and the background area is selected, for example, the final value is determined. Then, the scaled gradient values are numerically superimposed and fused with the corresponding initial enhanced brightness values point by point. The calculation formula is as follows: For example, if a certain pixel's Its corresponding ,and Then its fusion value is Calculated from all pixels These values together constitute the normalized pixel fusion value.
[0076] Based on the normalized pixel fusion values calculated in the previous step, these values exist in the form of a two-dimensional array, where each element of the array... Corresponding to the original image in coordinates The result of fusing brightness and gradient information at a given pixel is as follows. The next step is to formally confirm these fused values as the final feature representation. Specifically, this involves ensuring that each calculated normalized pixel fused value... They were all accurately placed in their original image coordinates At the corresponding positions, a new image data is formed. The dimensions (width and height) of this new image data are consistent with the dimensions of the original optical lens surface image and the various intermediate images generated during previous processing (such as the preliminary enhanced brightness map and dispersion gradient map). This is because in the fusion calculation... After that, what was obtained The range of values may exceed the standard image display range (e.g., if...). The maximum is 255. The maximum is 50, then The maximum value could reach 305, therefore, before finally forming the data on significant defect features, it is usually necessary to process all... Perform a range adjustment on the values, for example, adjust the range of all calculated values. The values are mapped to the standard 8-bit grayscale image range through linear stretching or direct truncation. For example, exceeding The range of values is truncated to 0 or 255. The set of pixel values after this final adjustment is the defect salient feature data.
[0077] The steps to obtain the local variation level map are as follows: Based on the defect salient feature data, taking each pixel position in the defect salient feature data as the center, extract the defect salient feature values of all pixels within a square neighborhood with a fixed odd number of pixels as the center, and store all the extracted feature values within the neighborhood position pixel by pixel to obtain a set of pixel neighborhood feature values. Based on the set of pixel neighborhood feature values, the average value of all defect salient feature values in the set is calculated one by one. Based on the difference between each defect salient feature value in the neighborhood of each pixel position and the corresponding average value, the square of the difference is calculated one by one. Then, the squared differences are summed for each pixel position and divided by the number of pixels in the neighborhood. Finally, the square root operation is performed to obtain the local standard deviation value of each pixel position. Based on the local standard deviation values, according to the original image size of the defect salient feature data, all local standard deviation values are mapped to their original corresponding pixel positions one by one, and the image data matrix is filled pixel by pixel to form a complete image data matrix, thus obtaining a local variation map.
[0078] Specifically, based on the defect saliency feature data generated in the previous steps, this data is a two-dimensional array with the same spatial dimensions as the original optical lens surface image. Each pixel value represents the saliency of that point after fusing multiple features. Next, based on this defect saliency feature data, we will analyze each pixel location... Perform neighborhood feature extraction at this pixel location. The current center pixel is considered as such. A square local neighborhood is defined around this center pixel, with a side length of a pre-defined fixed odd number of pixels, denoted as . ,this The choice of value is crucial for subsequent measurement of local variability. Its setting typically requires a trade-off between robustness to noise and sensitivity to minute changes. For example, it can be determined based on the pixel area typically occupied by common defects on the optical lens surface in the defect salient feature data. If the area affected by a typical minute defect is approximately... to Pixels can be set The resolution is set at 7 pixels to ensure the neighborhood fully encompasses these variations. The specific determination process may include: analyzing a series of defect salient feature data samples containing representative defects, statistically analyzing the average size and shape of the defect region, and then experimentally comparing different... The local standard deviations calculated using values (e.g., 3, 5, 7, 9) are used to differentiate defects. The value with the best differentiation effect and acceptable computational efficiency is selected. Value, as set in this description It is 7 pixels, that is, the neighborhood size is Pixel, for each center pixel Its neighborhood range covers the coordinates arrive All pixels, when the center pixel is close to the image boundary, cause its When the neighborhood exceeds the actual range of the defect salient feature data, a mirror padding strategy is used to virtually expand the image boundary. This involves using pixel values inside the image boundary to fill the corresponding external positions of the neighborhood, thus ensuring that each central pixel can be extracted as a complete image. All within the neighborhood (That is, 49) significant defect feature values. These extracted values are temporarily stored and compared with the current center pixel position. By associating and traversing all pixel positions, a set of pixel neighborhood feature values is formed, which stores all feature values in the neighborhood of each pixel.
[0079] Based on the previous step, each pixel position The set of pixel neighborhood feature values is acquired and stored, where each element contains all the feature values within a specific pixel neighborhood. A significant characteristic value of a defect (e.g., when (At that time, there were 49 values). Next, we will analyze each pixel position. For each pixel and its corresponding neighborhood feature value list, its local standard deviation is calculated independently, and the calculation process strictly follows the definition of standard deviation: First, for the pixel position being processed... The corresponding list of neighborhood feature values, calculate all values in the list. The average of the salient feature values of each defect is calculated by summing all the values in the neighborhood and then dividing by . First, the local average salient feature value of the neighborhood is obtained. Then, for each defect salient feature value in the neighborhood, the difference between it and the previously obtained local average salient feature value is calculated. This difference is then squared to obtain the squared deviation of each pixel in the neighborhood from the local mean. Finally, all pixels in the current neighborhood are... The squared deviations of all pixels are summed up to obtain the total sum of squared deviations. This total sum of squared deviations is then divided by the total number of pixels in the neighborhood. This process calculates the variance of the salient feature values of defects within the neighborhood. Finally, the square root of the calculated variance is taken, and the result is the current pixel position. The local standard deviation value is calculated by applying it sequentially to each set of neighborhood data in the set of pixel neighborhood feature values, that is, calculating a corresponding local standard deviation value for each pixel position in the original image.
[0080] Based on the previous step, each pixel position in the image The calculated local standard deviations collectively reflect the degree of variation or fluctuation in the salient feature data of defects within various local regions. The next step is to organize these calculated local standard deviations into a spatially meaningful image. Specifically, first, a new two-dimensional data matrix is created, with its width and height exactly matching the dimensions of the original image of the salient feature data of defects, to ensure that the subsequently generated image is spatially aligned with the original image. Then, for each pixel coordinate in the original salient feature data... The local standard deviation value corresponding to the coordinates calculated in the previous step is accurately assigned to the same coordinates in the newly created two-dimensional data matrix. The data points at each pixel are filled with the local standard deviation values into the corresponding positions of the new matrix. This filling process covers all pixels in the new data matrix. When all pixel positions are filled with their corresponding local standard deviation values, this complete data matrix constitutes a local variation map. This local variation map is a single-channel grayscale image, where the grayscale value of each pixel directly represents the standard deviation of the original defect salient image in the local neighborhood of that point, i.e., the local variation of that point.
[0081] The steps for obtaining the coordinates of the defective region in an optical lens are as follows: Based on the local variation map, the local standard deviation of each pixel in the image is extracted pixel by pixel, and the maximum, minimum and median values of the local standard deviation are obtained from all pixels. At the same time, the local standard deviation of the current pixel is extracted, and the correlation parameter set between the current pixel and the overall distribution benchmark is constructed to obtain the local variation statistical parameter set. Based on the set of local variation statistical parameters, the local variation judgment threshold for each pixel is calculated using the following formula: ; in, This represents the threshold for determining local variation in the current pixel. This represents the maximum local standard deviation among all pixels in an image. This represents the median value of the local standard deviation of all pixels in an image. This represents the local standard deviation of the current pixel. This represents the minimum local standard deviation of all pixels in an image. A constant parameter with dimensions consistent with the local standard deviation, used to avoid the denominator being zero and to control dynamic sensitivity; Based on the local variation judgment threshold of each pixel, it is compared with the local standard deviation value corresponding to the current pixel. If the local standard deviation value of the current pixel is greater than or equal to the local variation judgment threshold, it is marked as a pixel in a high variation region; otherwise, it is marked as a pixel in a low variation region, thus generating the coordinates of the optical lens defect region.
[0082] Specifically, based on the local variation map generated in the previous steps, which is a two-dimensional array with the same spatial dimension as the original optical lens surface image, the intensity value of each pixel represents the standard deviation of the significant feature of the defect in the local neighborhood at that location. First, a global statistical analysis needs to be performed on the entire local variation map to obtain its overall distribution characteristics. This process includes traversing every pixel position in the map and extracting the local standard deviation value at that position. Then, based on the set of all extracted local standard deviation values, the maximum local standard deviation over the entire image range is calculated, denoted as . The minimum value is denoted as And the median, denoted as The median is calculated by sorting all local standard deviations from low to high and selecting the middle value. If the total number of values is even, the average of the two middle values is taken. After obtaining the global statistical parameters, the local variation map is processed pixel by pixel for each pixel position in the image. Extract its local standard deviation, denoted as . (in (A unique identifier representing the current pixel), then, the local standard deviation of the current pixel. Compared with previously calculated global statistical parameters , and These four values are combined to form a parameter set that represents the degree of local variation of the current pixel and its relative position in the overall image variation distribution. After constructing such a parameter set for each pixel in the image, we obtain the local variation statistical parameter set.
[0083] formula: The advantage of this formula is that it can dynamically calculate an adaptive decision threshold for each pixel based on the overall statistical characteristics of the image content and the local characteristics of the current pixel. Instead of using a fixed global threshold, this adaptability allows the algorithm to better adapt to the contrast, noise level, and diversity of defects in different images. It combines the global variation span (the difference between the maximum and median values) and the local standard deviation of the current pixel. When global variation is significant and the current pixel standard deviation is large, the threshold baseline will be increased accordingly, and the denominator term will be adjusted accordingly. This introduces the deviation of the current pixel standard deviation from the global minimum standard deviation as an adjustment factor, parameter... The addition of ensures the non-zero nature of the denominator and controls the sensitivity of the threshold to small standard deviation changes. Overall, the formula enables the threshold to more accurately distinguish statistically significant “highly variable” pixels from the background by non-linearly combining global and local statistical information. parameter The steps to obtain (the maximum value among the local standard deviations of all pixels in the image) are as follows: This parameter is obtained through global statistics based on the local variation map generated in the previous step. Specifically, it involves iterating through each pixel in the local variation map, reading its local standard deviation, and finding the largest value among all these local standard deviations. This value represents the upper limit of the local variation in the current image. For example, in a local variation map, if the maximum local standard deviation of all pixels is found to be 25.0 after statistical analysis, then... .
[0084] parameter The steps to obtain (the median of the local standard deviations of all pixels in the image) are as follows: This parameter is also obtained through global statistics based on the local variation map. The acquisition process is as follows: collect the local standard deviation values of all pixels in the local variation map, sort these values in ascending order, and then... (The sentence is incomplete and requires more context to translate accurately.) If it is an odd number, then the median value is the th position after sorting. The value at each position, if If it is an even number, then the median value is the th position after sorting. The and the first The median is the average of the values at each location. This value represents the general level of local variation in the current image. For example, if the median is 5.0 after sorting and statistically analyzing the local standard deviations of the same image with varying degrees of local variation, then... .
[0085] parameter The steps to obtain (the local standard deviation of the current pixel) are as follows: This parameter represents the local standard deviation of the pixel being analyzed during pixel-by-pixel processing of the image. This value is directly derived from the local variation map corresponding to the current pixel coordinates. The location is extracted, reflecting the variation within a small neighborhood of the current pixel. For example, when processing an image with coordinates of... When a pixel is defined, and its value read from the local variation map is 10.0, then for that pixel, .
[0086] parameter The steps to obtain (the minimum local standard deviation of all pixels in the image) are as follows: The method of obtaining this parameter is the same as Similarly, both methods rely on global statistics based on local variation maps. Specifically, they involve iterating through each pixel in the local variation map, reading its local standard deviation, and then finding the smallest value among all these local standard deviations. This value represents the lower limit of the local variation in the current image, usually corresponding to the flattest or most uniform region in the image. For example, in the same local variation map, if the local standard deviation of all pixels is statistically analyzed and found to be at a minimum of 0.5, then... .
[0087] parameter The steps to obtain the constant parameter (with dimensions consistent with the local standard deviation) are as follows: parameter It is a preset small positive constant, the main purpose of which is to ensure that the denominator of the formula is small when calculating the threshold for determining local variation. Not because equal And by setting it to zero, calculation errors can be avoided. Meanwhile, The value of will also slightly affect the threshold value when it is close to 0. of Sensitivity to value The specific value should be much smaller than usual. The value of is non-zero, but it must be positive. Its selection can be based on analysis of the local standard deviation distribution characteristics of a large number of sample images. For example, it can be set to... Calculated for all sample images This can be a tiny percentage (e.g., 1%) of the average of the values, or set to a fixed, empirically derived absolute value much smaller than the typical non-zero local standard deviation. For example, if the observed local standard deviation is typically greater than 0.1, then... Set it to a value such as 0.01 to minimize its usual impact on threshold calculation while ensuring computational stability. In this implementation, set... .
[0088] Calculation process: With a specific pixel For example, the relevant parameter values are obtained from the set of local variation statistical parameters and substituted into the formula for calculation.
[0089] Set the current pixel Local standard deviation .
[0090] The parameter values obtained from the global statistics are: ; ; ; Set constant parameters .
[0091] The calculation process is as follows: Calculate the absolute difference term in the numerator: ; Calculate the numerator: ; Calculate the absolute difference term in the denominator: ; Calculate the denominator: ; Calculate the threshold for determining local variation : ; Therefore, for the current pixel Its local variation determination threshold .
[0092] The results show that the local variation threshold for the currently analyzed pixel is 21.03049. This threshold is dynamically calculated based on the local standard deviation of the pixel itself and the distribution characteristics (maximum, median, and minimum) of the local standard deviation of the entire image.
[0093] Based on the previous step, each pixel in the image The calculated local variation thresholds for each Simultaneously, the actual local standard deviation value corresponding to the pixel is extracted from the local variation map. Next, each pixel will be classified and labeled. Specifically, for each pixel location in the image... its local standard deviation The local variation threshold calculated for it The comparison is made, and the condition for judgment is: if Greater than or equal to Then determine the current pixel point Pixels belonging to high-variability regions and marked as such typically indicate that the local features of the region containing these pixels change drastically, making them highly likely to be part of a defect. Conversely, if... Less than Then determine the current pixel point Pixels belonging to low-variance regions are marked as such, indicating that the region is relatively flat or has little variation. To store these marking results, a new two-dimensional data structure (such as a binary image or mask image) is created, with the exact same dimensions as the original optical lens surface image. For each pixel marked as a high-variance region... A specific value (e.g., a value of 1 or 255, representing "defect" or "high variability") is assigned to the corresponding position in the new data structure. For each pixel marked as a low variability region, another different specific value is assigned (e.g., a value of 0, representing "background" or "low variability"). Once all pixels in the image are marked and filled into this new data structure, the coordinates of the optical lens defect region are formed. This result visually indicates the spatial positions of all pixels in the image that are judged to be high variability. These positions together constitute the detected potential defect region.
[0094] The above are merely preferred embodiments of the present invention and are not intended to limit the present invention in any other way. Any person skilled in the art may make changes or modifications to the above-disclosed technical content to create equivalent embodiments that can be applied to other fields. However, any simple modifications, equivalent changes, and modifications made to the above embodiments based on the technical essence of the present invention without departing from the scope of the present invention shall still fall within the protection scope of the present invention.
Claims
1. A method for detecting surface defects in an optical lens based on image processing, characterized in that, Includes the following steps: Acquire an image of the optical lens surface, decompose the image into three independent color channel intensity data: red, green and blue, adjust the contrast of each color channel intensity data, and generate a set of corrected color channels. Based on the set of corrected color channels, the intensity of the green color channel and the intensity of the red color channel are selected, and the intensity difference between the two is calculated in the preset pixel neighborhood to obtain a local channel difference value array. Based on the local channel difference value array, the spatial gradient magnitude of each difference in the local channel difference value array is calculated to establish a dispersion gradient map. Based on the set of corrected color channels, the average brightness value is calculated to form a single-channel brightness image. Multi-scale center-around difference operation is performed on the single-channel brightness image to obtain a preliminary enhanced brightness map. Based on the preliminary enhanced brightness map, the gradient values of the pixels and the corresponding positions of the dispersion gradient map are fused to generate significant defect feature data. Based on the defect salient feature data, the local standard deviation of the defect salient feature data is calculated in the pixel neighborhood of each pixel to obtain a local variation map. Based on the local variation map, the variation regions are distinguished and the coordinates of the optical lens defect region are established.
2. The method for detecting surface defects of an optical lens based on image processing according to claim 1, characterized in that, The steps for obtaining the corrected color channel set are as follows: Acquire an image of the optical lens surface, and perform color channel separation on the optical lens surface image, splitting it into independent red color channel intensity data, green color channel intensity data, and blue color channel intensity data to form initial color channel intensity data; Based on the initial color channel intensity data, the contrast of the red color channel intensity data, green color channel intensity data and blue color channel intensity data are adjusted respectively. By adjusting the dynamic range of pixel intensity within the channel, contrast-enhanced color channel intensity data is formed. Based on the contrast-enhanced color channel intensity data, the adjusted red color channel intensity data, green color channel intensity data, and blue color channel intensity data are merged to obtain the corrected color channel set.
3. The method for detecting surface defects of an optical lens based on image processing according to claim 1, characterized in that, The steps for obtaining the local channel difference value array are as follows: Based on the set of corrected color channels, the intensity data of the green color channel and the intensity data of the red color channel are called from the set of corrected color channels respectively. Taking the position of each pixel in the intensity data of the green color channel as a reference, a square area with the pixel as the center and the side length of a preset fixed length is selected to determine the area range within the preset pixel neighborhood and form pixel neighborhood area data. Based on the pixel neighborhood region data, the green color channel intensity data and the red color channel intensity data are called respectively. For each corresponding pixel point in the preset pixel neighborhood, the pixel intensity value difference is calculated point by point. The pixel intensity value of the green color channel intensity data is subtracted from the corresponding pixel intensity value of the red color channel intensity data to form the point-by-point pixel intensity difference data. Based on the pixel intensity difference data, the pixel intensity differences in all preset pixel neighborhood regions are summarized and combined one by one according to the original image pixel arrangement order to obtain a local channel difference value array.
4. The method for detecting surface defects of an optical lens based on image processing according to claim 1, characterized in that, The steps for obtaining the dispersion gradient map are as follows: Based on the local channel difference value array, the channel difference values of the two adjacent pixels above and below and the two adjacent pixels to the left and right are extracted from each pixel position in the image to construct the difference value group of each pixel in the vertical and horizontal directions. At the same time, the brightness intensity difference between the current pixel and its adjacent pixels on the diagonal is extracted to obtain the local direction channel difference value group and the brightness diagonal difference value group. The spatial gradient comprehensive amplitude is calculated based on the local directional channel difference group and the brightness diagonal difference group; Based on the spatial gradient composite magnitude, the spatial gradient composite magnitude calculated for each pixel position is sequentially assigned back to the original pixel position according to the pixel arrangement order of the image, thereby generating a dispersion gradient map.
5. The method for detecting surface defects of an optical lens based on image processing according to claim 1, characterized in that, The steps for obtaining the preliminary enhanced brightness map are as follows: Based on the corrected color channel set, the channel intensity value of each pixel position is extracted from the red color channel intensity data, green color channel intensity data and blue color channel intensity data respectively. The corresponding pixel positions of the three channels are summed and divided by three to generate the average brightness value of each pixel, forming a single-channel brightness image. Based on the single-channel brightness image, calculate the multi-scale center-surround differential enhancement value for each pixel; Based on the multi-scale center-surround differential enhancement values, the enhancement values of all pixel positions are normalized and mapped and then filled into the corresponding image positions to form a preliminary enhanced brightness map.
6. The method for detecting surface defects of an optical lens based on image processing according to claim 1, characterized in that, The steps for obtaining the significant feature data of the defects are as follows: Based on the preliminary enhanced brightness map, the enhanced brightness value at each pixel position in the preliminary enhanced brightness map is extracted one by one. At the same time, the spatial gradient comprehensive amplitude at each pixel position is extracted one by one from the corresponding pixel position in the dispersion gradient map. A pixel pair mapping relationship between brightness and gradient is established according to the pixel position to obtain brightness gradient mapping data. Based on the brightness gradient mapping data, each pair of pixels in the mapping data is numerically normalized. Taking the initial enhanced brightness value at each pixel position as a reference, the corresponding spatial gradient comprehensive amplitude is proportionally scaled and then numerically superimposed and fused with the brightness value point by point to obtain the normalized pixel fusion value. Based on the normalized pixel fusion value, the pixel positions are sequentially mapped back to the original coordinate positions of the image to obtain the significant feature data of the defects.
7. The method for detecting surface defects of an optical lens based on image processing according to claim 1, characterized in that, The steps for obtaining the local variation degree map are as follows: Based on the defect salient feature data, taking each pixel position in the defect salient feature data as the center, extract the defect salient feature values of all pixels within a square neighborhood with a fixed odd number of pixels as the center, and store all the extracted feature values within the neighborhood position pixel by pixel to obtain a set of pixel neighborhood feature values. Based on the set of pixel neighborhood feature values, the average value of all significant defect feature values in the set is calculated one by one. Based on the difference between each significant defect feature value in the neighborhood of each pixel position and the corresponding average value, the square of the difference is calculated one by one. Then, the squared differences are summed for each pixel position and divided by the number of pixels in the neighborhood. Finally, the square root operation is performed to obtain the local standard deviation value of each pixel position. Based on the local standard deviation values, according to the original image size of the defect salient feature data, all local standard deviation values are mapped to their original corresponding pixel positions one by one, and the pixel positions are filled to form a complete image data matrix, thus obtaining a local variation map.
8. The method for detecting surface defects of an optical lens based on image processing according to claim 1, characterized in that, The steps for obtaining the coordinates of the defective region of the optical lens are as follows: Based on the local variation map, the local standard deviation of each pixel in the image is extracted pixel by pixel, and the maximum, minimum and median values of the local standard deviation are obtained from all pixels. At the same time, the local standard deviation of the current pixel is extracted, and the correlation parameter set between the current pixel and the overall distribution benchmark is constructed to obtain the local variation statistical parameter set. Based on the set of local variation statistical parameters, calculate the local variation judgment threshold for each pixel; Based on the local variation judgment threshold of each pixel, it is compared with the local standard deviation value corresponding to the current pixel. If the local standard deviation value of the current pixel is greater than or equal to the local variation judgment threshold, it is marked as a pixel in a high variation region; otherwise, it is marked as a pixel in a low variation region, thus generating the coordinates of the optical lens defect region.
9. The optical lens surface defect detection system according to the image processing-based optical lens surface defect detection method according to any one of claims 1-8, characterized in that, include: Image preprocessing module: acquires an image of the optical lens surface, decomposes the image of the optical lens surface into three independent color channel intensity data of red, green and blue, adjusts the contrast of the color channel intensity data of each channel, and generates a set of corrected color channels; Color difference analysis module: Based on the set of corrected color channels, select the intensity of green color channel and red color channel, calculate the intensity difference between the two in the preset pixel neighborhood, obtain a local channel difference value array, calculate the spatial gradient magnitude of each difference in the local channel difference value array based on the local channel difference value array, and establish a dispersion gradient map; Brightness enhancement and fusion module: Based on the set of corrected color channels, calculate the average brightness value to form a single-channel brightness image, perform multi-scale center-around difference operation on the single-channel brightness image to obtain a preliminary enhanced brightness map, and based on the preliminary enhanced brightness map, fuse the gradient values of the pixels with the corresponding positions of the dispersion gradient map to generate significant defect feature data; Defect localization module: Based on the defect salient feature data, calculate the local standard deviation of the defect salient feature data in the pixel neighborhood of each pixel to obtain a local variation map. Based on the local variation map, distinguish the variation regions and establish the coordinates of the optical lens defect region.
Citation Information
Cited By
Image data enhancement processing method for industrial visual inspection
CN121120457A
Root increasing container seedling culture state monitoring method and system
CN121458810A