Defect detection method for fixed focus lens based on image enhancement technology

CN122948845APending Publication Date: 2026-10-20INSTITUTE OF MATERIALS & INTELLIGENT MANUFACTURING JIANGXI ACADEMY OF SCIENCES
View PDF 0 Cites 0 Cited by

Patent Information

Application Number
CN202611194258.9
Authority / Receiving Office
CN · China
Patent Type
Applications(China)
Current Assignee / Owner
Filing Date
2026-08-07
Publication Date
2026-10-20

AI Technical Summary

Technical Problem

[0005]本发明的目的在于提供基于图像增强技术的定焦镜头表面缺陷检测方法,以解决现有技术中微小缺陷对比度低、难以与背景纹理和噪声有效区分,从而导致检测精度不足的问题

Benefits of technology

对频域频谱图中的低频分量进行零频抑制处理,依据中心低频圆盘区域内幅度值的均值,逐像素扣除低频均值后,与原始相位谱重构生成高频增强频谱图。这一处理方式并非简单地截断或衰减低频成分,而是将低频区域的整体能量中心平移至零值附近,抑制了均匀光照不均匀性造成的平滑背景渐变,同时完整保留了表征纹理突变和边缘轮廓的高频信息。逆傅里叶变换得到的细节增强图像中,原本淹没于平缓灰度过渡中的微小凹陷、划痕等缺陷表现为显著的局部起伏,缺陷与背景的灰度差异被放大,为后续梯度方向场的构建提供了高对比度的特征基础。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure REF-OBJ-1786084930514-000002
    Figure REF-OBJ-1786084930514-000002
  • Figure REF-OBJ-1786084930514-000045
    Figure REF-OBJ-1786084930514-000045
  • Figure REF-OBJ-1786084930514-000078
    Figure REF-OBJ-1786084930514-000078
Patent Text Reader

Abstract

This invention discloses a method for detecting surface defects in a fixed-focus lens based on image enhancement technology, belonging to the field of optical lens defect detection technology. The method includes: acquiring the original grayscale image of the fixed-focus lens under uniform illumination; performing a two-dimensional Fourier transform on the original grayscale image to obtain a frequency domain spectrum; performing zero-frequency suppression processing on the low-frequency components in the frequency domain spectrum to generate a high-frequency enhanced spectrum; performing an inverse Fourier transform on the high-frequency enhanced spectrum to obtain a detail enhanced image; performing gradient field reconstruction processing on the detail enhanced image to obtain a gradient direction field; performing integral surface fitting on the gradient direction field to generate an integral reconstructed surface; calculating the second-order partial derivative of the integral reconstructed surface to obtain a curvature response map; performing local extremum point detection on the curvature response map to generate a candidate defect coordinate set; performing spatial neighborhood aggregation on the candidate defect coordinate set to generate a defect region marker map; and performing connected component analysis on the defect region marker map to output the surface defect detection result.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of optical lens defect detection technology, specifically a method for detecting surface defects in fixed-focus lenses based on image enhancement technology. Background Technology

[0002] Surface defect detection in fixed-focus lenses is a crucial step in quality control during optical component manufacturing. Minor defects such as scratches, pits, and bubbles on the lens surface can adversely affect the imaging performance of the optical system. Existing surface defect detection technologies for fixed-focus lenses largely rely on manual visual inspection or machine vision methods based on traditional image processing algorithms. Manual visual inspection is inefficient, highly subjective, and difficult to adapt to the inspection needs of mass production. Traditional machine vision methods typically perform edge detection, threshold segmentation, or template matching directly on the lens surface image to identify defect areas.

[0003] Existing technical solutions suffer from the following drawbacks. Lens surface images acquired under uniform illumination typically exhibit low contrast between defect areas and background areas. Minor surface anomalies are easily masked by the lens's own optical texture, illumination inhomogeneity, or sensor noise. Directly performing edge extraction or region segmentation on such low-contrast images can easily lead to missed detections and false positives. Furthermore, minute defects on the lens surface manifest as weak grayscale fluctuations in two-dimensional images, making it difficult for traditional methods to reliably extract geometric features characterizing the defect morphology from these fluctuation patterns. While some methods utilize frequency domain filtering techniques to enhance image details, conventional high-pass or band-pass filters, while strengthening edges, also amplify high-frequency noise, resulting in insufficient signal-to-noise ratio for subsequent defect assessment.

[0004] The problem to be solved by this invention is how to effectively enhance the detail representation of minute defects in fixed-focus lens images acquired under uniform lighting conditions, and accurately extract the defect area while suppressing noise interference, thereby improving the reliability and accuracy of surface defect detection. Summary of the Invention

[0005] The purpose of this invention is to provide a method for detecting surface defects of fixed-focus lenses based on image enhancement technology, so as to solve the problem that the small defects have low contrast and are difficult to distinguish from the background texture and noise in the prior art, resulting in insufficient detection accuracy.

[0006] To achieve the above objectives, the present invention provides the following technical solution: The present invention provides a method for detecting surface defects of a fixed-focus lens based on image enhancement technology, comprising: A raw grayscale image of a fixed-focus lens under uniform illumination is acquired. A two-dimensional Fourier transform is performed on the raw grayscale image to obtain a frequency domain spectrum. Zero-frequency suppression processing is applied to the low-frequency components in the frequency domain spectrum to generate a high-frequency enhanced spectrum. An inverse Fourier transform is performed on the high-frequency enhanced spectrum to obtain a detail-enhanced image. Gradient field reconstruction processing is performed on the detail-enhanced image to obtain a gradient direction field. Integral surface fitting is performed on the gradient direction field to generate an integral reconstructed surface. Second-order partial derivative calculations are performed on the integral reconstructed surface to obtain a curvature response map. Local extremum point detection is performed on the curvature response map to generate a candidate defect coordinate set. Spatial neighborhood aggregation is performed on the candidate defect coordinate set to generate a defect region marker map. Connectivity analysis is performed on the defect region marker map to output the surface defect detection results.

[0007] As a preferred embodiment of the present invention, a two-dimensional Fourier transform is performed on the original grayscale image to obtain a frequency domain spectrum. Zero-frequency suppression processing is then applied to the low-frequency components in the frequency domain spectrum to generate a high-frequency enhanced spectrum. Specifically, this involves: performing a discrete Fourier transform on the original grayscale image to obtain the frequency domain spectrum; dividing the amplitude spectrum of the frequency domain spectrum into a circular region to obtain a central low-frequency disk region; calculating the mean of all amplitude values ​​within the central low-frequency disk region to obtain a low-frequency mean; subtracting the low-frequency mean from the amplitude value of each pixel within the central low-frequency disk region to obtain a zero-frequency suppression amplitude value; and reconstructing the zero-frequency suppression amplitude value and the phase spectrum of the frequency domain spectrum using complex number reconstruction to obtain the high-frequency enhanced spectrum. This adaptively suppresses low-frequency background components introduced by uniform illumination, significantly enhancing the high-frequency detail components corresponding to defects.

[0008] As a preferred embodiment of the present invention, the inverse Fourier transform of the high-frequency enhanced spectrogram is performed to obtain a detail-enhanced image. Specifically, this involves performing a discrete inverse Fourier transform on the high-frequency enhanced spectrogram to obtain a frequency-domain enhanced complex field; performing a modulo operation on the frequency-domain enhanced complex field to obtain an amplitude response matrix; performing linear normalization on the amplitude response matrix to obtain a normalized amplitude matrix; performing power-law mapping adjustment on the normalized amplitude matrix to obtain an intermediate enhanced image; and performing median filtering on the intermediate enhanced image to remove impulse noise, thus obtaining the detail-enhanced image. Through power-law mapping adjustment and median filtering, the contrast between defects and the background can be further improved, and impulse noise can be effectively removed, ensuring the clarity of the detail image.

[0009] As a preferred embodiment of the present invention, the gradient direction field is obtained by performing gradient field reconstruction processing on the detail-enhanced image. Specifically, this involves: performing Sobel gradient operator convolution on the detail-enhanced image to obtain an initial gradient matrix; performing gradient magnitude thresholding on the initial gradient matrix to obtain an effective gradient mask; calculating the eight-neighbor gradient direction histogram for each pixel within the coverage area of ​​the effective gradient mask; extracting the dominant gradient direction from the eight-neighbor gradient direction histogram to obtain the local dominant gradient direction; and performing orientation constraint correction on the initial gradient matrix based on the local dominant gradient direction to obtain the gradient direction field. Through orientation constraint correction, continuous and consistent gradient directions in defective regions can be obtained, suppressing the interference of non-defective textures on the orientation.

[0010] As a preferred embodiment of the present invention, an integral reconstructed surface is generated by fitting an integral surface to the gradient direction field. Specifically, the following steps are performed: A pixel in the first row and first column of the gradient direction field is selected as the integration starting point. An initial integral value is assigned to the integration starting point. The gradient direction field is scanned row by row. The gradient direction of the currently scanned pixel is subtracted from the gradient direction of the pixel to its left to obtain the horizontal increment. The horizontal increment is added to the integral value of the pixel to its left to obtain the horizontal integral value of the current pixel. The gradient direction field is scanned column by column. The gradient direction of the currently scanned pixel is subtracted from the gradient direction of the pixel above it to obtain the vertical increment. The vertical increment is added to the integral value of the pixel above it to obtain the vertical integral value of the current pixel. The horizontal and vertical integral values ​​are weighted and averaged to obtain the integral reconstructed pixel value. The integral reconstructed surface is constructed based on the integral reconstructed pixel values ​​of all pixels. This integral reconstruction process transforms the gradient direction field into a surface reflecting the surface morphology, highlighting the three-dimensional morphological features of minor defects such as pits and scratches.

[0011] As a preferred embodiment of the present invention, the curvature response map is obtained by calculating the second-order partial derivatives of the integral reconstructed surface. Specifically, this involves: calculating the horizontal curvature matrix by performing second-order difference calculations in the horizontal direction on the integral reconstructed surface; calculating the vertical curvature matrix by performing second-order difference calculations in the vertical direction on the integral reconstructed surface; calculating the diagonal curvature matrix by performing second-order difference calculations in the diagonal direction on the integral reconstructed surface; summing the absolute values ​​of the horizontal, vertical, and diagonal curvature matrices to obtain the curvature intensity matrix; and performing local contrast stretching enhancement on the curvature intensity matrix to obtain the curvature response map. Multi-directional curvature fusion enables high response at defect edges in all directions, improving the detection capability for defects in any direction.

[0012] As a preferred technical solution of the present invention, the curvature response map is subjected to local extremum point detection to generate a candidate defect coordinate set. Specifically, for each pixel in the curvature response map, the curvature values ​​within its eight-neighbor range are extracted to form a local curvature sequence. The local curvature sequence is sorted to obtain the maximum and minimum values. It is determined whether the curvature value of the current pixel is equal to the maximum or minimum value. If so, the current pixel is marked as a local extremum candidate point. The coordinates corresponding to all local extremum candidate points are organized to obtain an extremum coordinate list. Non-maximum suppression is applied to the extremum coordinate list to remove adjacent redundant points, thereby obtaining the candidate defect coordinate set. Through eight-neighbor extremum filtering and non-maximum suppression, the geometric center or boundary response extremum point of the defect can be accurately located, reducing redundant candidates.

[0013] As a preferred technical solution of the present invention, a defect region marking map is generated by spatial neighborhood aggregation of the candidate defect coordinate set. Specifically, this involves: selecting an unmarked coordinate point from the candidate defect coordinate set as a seed point; performing an eight-neighbor expansion search on the seed point to obtain adjacent candidate coordinate points; determining the connectivity of the adjacent candidate coordinate points to obtain connected regions; assigning the same region number to all coordinate points within the connected regions; repeating the selection of the seed point and the connectivity determination until all candidate coordinate points are assigned region numbers; generating an initial defect region marking map based on the region numbers; and performing a morphological closing operation on the initial defect region marking map to fill small holes to obtain the final defect region marking map. This neighborhood aggregation and closing operation can fuse discrete defect candidate points into a complete defect region and fill in small discontinuities within the region.

[0014] Preferably, the initial defect region marker image is obtained by performing morphological closing operations to fill small holes. Specifically, this involves: constructing a circular structuring element and performing a dilation operation on the initial defect region marker image to obtain a dilated image; performing an erosion operation on the dilated image to obtain an eroded image; updating the connected component numbers of the eroded image to obtain an updated region marker image; filling the hole regions in the updated region marker image with pixels whose area is smaller than a preset hole threshold to obtain a filled region marker image; and performing a logical OR operation between the filled region marker image and the initial defect region marker image to obtain the final defect region marker image. Based on the closing operation and hole filling using the circular structuring element, the defect region boundaries can be smoothed and isolated internal holes can be eliminated, resulting in a more complete description of the defect morphology.

[0015] As a preferred technical solution of the present invention, the surface defect detection result is output by performing connected component analysis on the defect region marking map. Specifically, the area parameter is obtained by counting pixels in each connected region of the defect region marking map, the boundary of each connected region is extracted to obtain a set of boundary pixels, the length and width parameters of the region are obtained by fitting the boundary pixel set with the minimum bounding rectangle, the area parameter and the length and width parameters of the region are jointly determined, and the connected regions that simultaneously satisfy the area threshold range and the aspect ratio threshold range are determined as valid defect regions. A defect boundary line map is generated based on the contour coordinates of all valid defect regions, and the defect boundary line map is superimposed on the original grayscale image to output the surface defect detection result. By jointly determining the area and aspect ratio, false regions caused by noise can be effectively eliminated, and accurate defect contour information can be output. The overall method integrates frequency domain zero-frequency suppression, gradient direction field reconstruction, integral surface fitting and curvature extremum analysis to achieve high-precision detection of surface defects of fixed-focus lenses, and has good anti-interference ability and robustness.

[0016] The technical effects and advantages provided by the present invention in the above technical solution are as follows: Zero-frequency suppression is applied to the low-frequency components in the frequency domain spectrogram. Based on the mean amplitude value within the central low-frequency disk region, the low-frequency mean is subtracted pixel by pixel, and then reconstructed with the original phase spectrum to generate a high-frequency enhanced spectrogram. This processing method does not simply truncate or attenuate low-frequency components, but rather shifts the overall energy center of the low-frequency region to near zero, suppressing the smooth background gradation caused by uneven uniform illumination, while fully preserving the high-frequency information characterizing texture abrupt changes and edge contours. In the detail-enhanced image obtained by inverse Fourier transform, tiny depressions, scratches, and other defects that were originally submerged in the smooth gray-level transition appear as significant local undulations. The gray-level difference between defects and the background is amplified, providing a high-contrast feature basis for the subsequent construction of the gradient direction field.

[0017] In the process of reconstructing the integral surface from the gradient direction field, a method of row-by-row and column-by-column difference accumulation and weighted averaging is used to transform the directional information reflecting the direction of the defect edge into a continuous integral reconstructed surface. This step overcomes the limitation of conventional gradient magnitude analysis, which can only reflect edge intensity. By accumulating small changes in the direction field, the local surface deformation caused by the defect is completely reproduced as a spatial undulating structure. The second-order partial derivatives in the horizontal, vertical, and diagonal directions are calculated on the integral reconstructed surface, and the absolute values ​​of the curvature matrices in the three directions are summed to form the curvature intensity matrix. This makes the defect region exhibit a significantly higher response peak in the curvature response map than the flat background and non-defect texture regions. The multi-directional fusion of curvature response allows scratches with arbitrary orientations, irregularly shaped pits, and shallow pits with blurred edges to be stably captured, regardless of the defect's directionality and shape. Based on the local extremum point detection of the curvature response map and non-maximum suppression to generate a candidate defect coordinate set, isolated pseudo-extremum points caused by noise are effectively eliminated. The final output surface defect detection result can accurately mark the location and contour boundary of the defect. Attached Figure Description

[0018] To more clearly illustrate the technical solutions in the embodiments of this application or the prior art, the drawings used in the embodiments will be briefly introduced below. Obviously, the drawings described below are only some embodiments recorded in this invention. For those skilled in the art, other drawings can be obtained based on these drawings.

[0019] Figure 1 This is a flowchart of a fixed-focus lens surface defect detection method based on image enhancement technology; Figure 2 This is a flowchart of the gradient orientation field generation process for detail-enhanced images; Figure 3 This is a flowchart of the defect area marking method. Detailed Implementation

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

[0021] See Figure 1This invention provides a method for detecting surface defects in a fixed-focus lens based on image enhancement technology, comprising: acquiring an original grayscale image of the fixed-focus lens under uniform illumination; performing a two-dimensional Fourier transform on the original grayscale image to obtain a frequency domain spectrum; performing zero-frequency suppression processing on the low-frequency components in the frequency domain spectrum to generate a high-frequency enhanced spectrum; performing an inverse Fourier transform on the high-frequency enhanced spectrum to obtain a detail enhanced image; performing gradient field reconstruction processing on the detail enhanced image to obtain a gradient direction field; performing integral surface fitting on the gradient direction field to generate an integral reconstructed surface; performing second-order partial derivative calculation on the integral reconstructed surface to obtain a curvature response map; performing local extremum point detection on the curvature response map to generate a candidate defect coordinate set; performing spatial neighborhood aggregation on the candidate defect coordinate set to generate a defect region marking map; and performing connected component analysis on the defect region marking map to output surface defect detection results.

[0022] Example 1:

[0023] In practice, after acquiring the original grayscale image of the fixed-focus lens under uniform illumination, a Discrete Fourier Transform (DFT) is performed on the original grayscale image to obtain a frequency domain spectrum. The DFT is calculated by using a two-dimensional Fast Fourier Transform (FFT) algorithm to transform the original grayscale image from the spatial domain to the frequency domain. The frequency domain spectrum consists of two components: an amplitude spectrum and a phase spectrum. The amplitude spectrum represents the energy intensity of different frequency components in the original grayscale image, while the phase spectrum represents the spatial relationship between different frequency components in the original grayscale image.

[0024] A central low-frequency disk region is obtained by dividing the amplitude spectrum of the frequency domain spectrogram into annular regions. In some embodiments, the annular region division method involves setting a circular mask with a preset radius centered on the center point of the amplitude spectrum; the amplitude spectrum region covered by the circular mask is the central low-frequency disk region. The preset radius of the central low-frequency disk region is determined based on the spatial frequency characteristics of the surface defects of the fixed-focus lens. A corresponding cutoff frequency is selected within the typical size range of the surface defects of the fixed-focus lens, and the pixel index distance corresponding to the cutoff frequency is used as the specific value of the preset radius. The low-frequency mean is obtained by averaging all amplitude values ​​within the central low-frequency disk region. The mathematical expression of the low-frequency mean is:

[0025] in, Indicates the low-frequency mean. Indicates the central low-frequency disk area The total number of pixels contained within. This represents the set of pixel coordinates corresponding to the central low-frequency disk region. This represents the x-coordinate index of a pixel within the central low-frequency disk region. This represents the ordinate index of a pixel within the central low-frequency disk region. Indicates the index of the horizontal axis within the central low-frequency disk region. and y-axis index The amplitude value at that point. Low-frequency mean. The arithmetic mean of all amplitude values ​​within the central low-frequency disk region is used directly as the overall intensity estimate of the low-frequency component.

[0026] The zero-frequency suppression amplitude value is obtained by subtracting the low-frequency mean from the amplitude value of each pixel within the central low-frequency disk region. This subtraction operation is performed independently at each pixel within the central low-frequency disk region, replacing the original amplitude value of each pixel with the difference between the original amplitude value and the low-frequency mean. When the original amplitude value of a pixel is less than the low-frequency mean, the corresponding zero-frequency suppression amplitude value is negative; when the original amplitude value of a pixel is greater than the low-frequency mean, the corresponding zero-frequency suppression amplitude value is positive. The amplitude spectrum region outside the central low-frequency disk region remains unchanged and does not undergo amplitude value subtraction.

[0027] The high-frequency enhancement spectrum is obtained by complex reconstruction of the zero-frequency suppression amplitude value and the phase spectrum of the frequency domain spectrogram. The complex reconstruction process involves traversing each frequency coordinate position in the frequency domain spectrogram and determining whether the current frequency coordinate position is within the central low-frequency disk region. If the current frequency coordinate position is within the central low-frequency disk region, the zero-frequency suppression amplitude value corresponding to the current frequency coordinate position is taken as the reconstructed amplitude value. If the current frequency coordinate position is outside the central low-frequency disk region, the original amplitude value of the current frequency coordinate position is taken as the reconstructed amplitude value. Based on the reconstructed amplitude value and the original phase spectrum, a complex number is constructed at each frequency coordinate position. The real part of the complex number is determined by the product of the reconstructed amplitude value and the cosine of the phase angle, and the imaginary part of the complex number is determined by the product of the reconstructed amplitude value and the sine of the phase angle. The complex numbers at all frequency coordinate positions together constitute the high-frequency enhancement spectrum.

[0028] A discrete inverse Fourier transform (IFT) is performed on the high-frequency enhanced spectrum to obtain a frequency-domain enhanced complex field. The IFT is calculated by using a two-dimensional inverse fast Fourier transform (IFFT) algorithm to transform the high-frequency enhanced spectrum from the frequency domain back to the spatial domain. The result is a frequency-domain enhanced complex field containing both real and imaginary parts. A modulo operation is then performed on the frequency-domain enhanced complex field to obtain the amplitude response matrix. This operation is performed by summing the squares of the real and imaginary parts of the complex value at each pixel in the frequency-domain enhanced complex field, and taking the square root of this sum as the amplitude response value for that pixel. The amplitude response values ​​of all pixels constitute the amplitude response matrix.

[0029] The amplitude response matrix is ​​linearly normalized to obtain a normalized amplitude matrix. The linear normalization method involves iterating through all amplitude response values ​​in the matrix, determining the maximum and minimum values, and then applying a linear scaling formula to each value. This linear scaling formula maps the original amplitude response value linearly to a value range of zero to one, resulting in the normalized amplitude matrix. Power-law mapping is then applied to the normalized amplitude matrix to obtain an intermediate enhanced image. The mathematical form of power-law mapping is to perform a gamma-power operation on each normalized amplitude value in the matrix, with the exponent parameter set to a positive value less than one. This non-linear stretching of the normalized amplitude values ​​enhances the contrast in dark areas, and the result of the gamma-power operation constitutes the intermediate enhanced image. Finally, median filtering is applied to the intermediate enhanced image to remove impulse noise, resulting in a detail-enhanced image. The median filtering method involves selecting a square filter window of a fixed size and sliding it pixel by pixel on the intermediate enhanced image. The gray values ​​of all pixels within the coverage area of ​​the filter window are sorted, and the median of the sorting results is taken as the new gray value of the center pixel of the filter window. After traversing all pixels of the intermediate enhanced image, the detail enhanced image is obtained.

[0030] Example 2:

[0031] In specific implementation, please refer to Figure 2After acquiring the detail-enhanced image, the Sobel gradient operator convolution is performed on the detail-enhanced image to obtain the initial gradient matrix. The Sobel gradient operator convolution method involves constructing horizontal and vertical Sobel convolution kernels. The horizontal Sobel convolution kernel matrix is ​​set to 3 rows and 3 columns, where the values ​​in the first row are -1, 0, +1, the values ​​in the second row are -2, 0, +2, and the values ​​in the third row are -1, 0, +1. The vertical Sobel convolution kernel matrix is ​​also set to 3 rows and 3 columns, where the values ​​in the first row are -1, -2, -1, the values ​​in the second row are 0, 0, 0, and the values ​​in the third row are +1, +2, +1. The horizontal Sobel convolution kernel is then convolved with the detail-enhanced image in two dimensions to obtain the horizontal gradient component matrix, and the vertical Sobel convolution kernel is convolved with the detail-enhanced image in two dimensions to obtain the vertical gradient component matrix. For each pixel in the detail-enhanced image, the horizontal gradient component value at the corresponding position in the horizontal gradient component matrix and the vertical gradient component value at the corresponding position in the vertical gradient component matrix are taken. The sum of the squares of the horizontal and vertical gradient component values ​​is calculated, and the square root of the sum of squares is taken as the initial gradient magnitude value for that pixel position. The initial gradient magnitude values ​​of all pixel positions constitute the initial gradient magnitude matrix. The arctangent of the ratio of the vertical gradient component value to the horizontal gradient component value is taken as the initial gradient direction value for that pixel position. The initial gradient direction values ​​of all pixel positions constitute the initial gradient direction matrix. The initial gradient magnitude matrix and the initial gradient direction matrix together form the initial gradient matrix.

[0032] An effective gradient mask is obtained by thresholding the gradient magnitude of the initial gradient matrix. In some implementations, the gradient magnitude thresholding method involves statistically analyzing all initial gradient magnitude values ​​in the initial gradient magnitude matrix, calculating the average and standard deviation of all initial gradient magnitude values, and using the average plus a preset multiple of the standard deviation as the gradient magnitude threshold. The preset multiple of the standard deviation is set to 2.5. This setting is based on the assumption of a normal distribution, where a range of 2.5 times the standard deviation can cover approximately 98.8% of the data points, and initial gradient magnitude values ​​exceeding this range are considered significant gradient responses. Each pixel position in the initial gradient magnitude matrix is ​​traversed, and pixels with initial gradient magnitude values ​​greater than the gradient magnitude threshold are marked as effective gradient positions, while pixels with initial gradient magnitude values ​​less than or equal to the gradient magnitude threshold are marked as invalid gradient positions. The marking results of effective and invalid gradient positions constitute a binary form of the effective gradient mask.

[0033] For each pixel within the effective gradient mask coverage area, calculate its 8-neighbor gradient direction histogram. In practice, it iterates through all pixels marked as effective gradient positions within the effective gradient mask. For each effective gradient position, perform an 8-neighbor extraction operation. This operation involves obtaining the coordinates of eight neighboring pixels (3 rows, 3 columns) around the current effective gradient position. These eight neighboring pixels are located at the top left, top right, top right, bottom left, bottom right, and bottom right directions from the center. The initial gradient direction values ​​corresponding to the eight neighboring pixels are read from the initial gradient direction matrix. The circumferential angle interval is then equally divided into eight direction intervals, each covering a 45-degree angle range. The boundaries of these direction intervals are 0 degrees, 45 degrees, 90 degrees, 135 degrees, 180 degrees, 225 degrees, 270 degrees, 315 degrees, and 360 degrees, respectively. The frequency of the initial gradient direction values ​​of 8 neighboring pixels falling into each direction interval is counted. An 8-neighbor gradient direction histogram is constructed with the direction interval number as the horizontal axis and the frequency as the vertical axis. The frequency of the b-th direction interval in the 8-neighbor gradient direction histogram is represented by hhist(b), where b represents the direction interval number index, and the value of b is an integer from 1 to 8. hhist(b) represents the number of neighboring pixels in the b-th direction interval in the 8-neighbor gradient direction histogram.

[0034] The dominant gradient direction is obtained by extracting the principal direction from the 8-neighbor gradient direction histogram. The method for extracting the principal direction is as follows: traverse the frequency values ​​of the 8 direction intervals in the 8-neighbor gradient direction histogram, determine the direction interval number corresponding to the maximum frequency value. If there is only one direction interval corresponding to the maximum frequency value, then the center angle value of that direction interval is taken as the local dominant gradient direction. If there are multiple direction intervals corresponding to the maximum frequency value, then calculate the arithmetic mean of the center angle values ​​of these direction intervals, and take the arithmetic mean as the local dominant gradient direction. The center angle value of the direction interval is defined as the arithmetic mean of the lower boundary angle value and the upper boundary angle value of the direction interval. Taking the 0-degree to 45-degree direction interval as an example, the lower boundary angle value of the direction interval is 0 degrees, the upper boundary angle value is 45 degrees, and the center angle value of the direction interval is 22.5 degrees.

[0035] The gradient direction field is obtained by correcting the orientation of the initial gradient matrix based on the local dominant gradient direction. The method for orientation constraint correction is as follows: traverse all pixels marked as valid gradient positions in the effective gradient mask; read the initial gradient direction value corresponding to each valid gradient position from the initial gradient direction matrix; and calculate the angle difference between the initial gradient direction value and the local dominant gradient direction of the corresponding pixel position. Compare the absolute value of the angle difference with a preset angle deviation threshold, set to 30 degrees. This setting is based on the premise that a 30-degree deviation range can cover orientation fluctuations caused by image noise and local texture changes, while excluding edge pixels with severely deviated orientations. If the absolute value of the angle difference is less than or equal to the preset angle deviation threshold, the initial gradient direction value is used as the gradient direction field direction value for that pixel position; if the absolute value of the angle difference is greater than the preset angle deviation threshold, the local dominant gradient direction is used as the gradient direction field direction value for that pixel position. For all pixels marked as invalid gradient positions in the effective gradient mask, the gradient direction field direction value is set to 0. The gradient direction field direction values ​​for all pixel positions constitute the gradient direction field.

[0036] Example 3:

[0037] In the specific implementation, the pixel in the first row and first column of the gradient direction field is selected as the integration starting point. The gradient direction field is a two-dimensional matrix, with the row indices increasing from top to bottom and the column indices increasing from left to right. The pixel in the first row and first column corresponds to the position in the two-dimensional matrix where both the row index and column index are 1. An initial integration value is assigned to the integration starting point, which is set to zero. This initial integration value indicates that the surface height reference corresponding to the integration starting point position is zero.

[0038] The gradient direction field is scanned row by row. The scanning order is as follows: starting from the second column of the gradient direction field, each pixel in each row is visited sequentially from left to right. The horizontal increment is obtained by calculating the difference between the gradient direction of the currently scanned pixel and the pixel to its left. In the specific implementation, let the coordinates of the currently scanned pixel be... ,in This indicates the row index of the currently scanned pixel in the gradient direction field. This indicates the column index of the currently scanned pixel in the gradient direction field. The value of is an integer ranging from 1 to the total number of rows of the gradient direction field. The value of is an integer ranging from the second to the total number of columns of the gradient direction field. Read the currently scanned pixel from the gradient direction field. The gradient direction value at point is denoted as Read the left pixel The gradient direction value at point is denoted as The differential calculation method involves calculating the gradient direction value. With gradient direction value The difference is taken as the horizontal increment.

[0039] The horizontal integral value of the current pixel is obtained by adding the horizontal increment to the integral value of the left pixel. The integral value of the left pixel refers to the integral value of the left pixel. The integral value calculated in the previous processing steps is denoted as . The horizontal integral value of the current pixel. The calculation method is to integrate the horizontal increment with the value of the left pixel. Add them together. For the first scanned pixel in each row, i.e., the column index... The pixel with a value equal to 2 is the starting point of integration, and the integral value at the starting point is the initial integral value of zero.

[0040] The gradient direction field is scanned column by column. The scanning order is as follows: starting from the second row of the gradient direction field, each pixel in each column is visited sequentially from top to bottom. The vertical increment is calculated by subtracting the gradient direction of the currently scanned pixel from that of the pixels above it. Let the coordinates of the currently scanned pixel be... ,in The value range is an integer from the total number of rows of the gradient direction field to the second. The value range is an integer from 1 to the total number of columns in the gradient direction field. The coordinates of the upper pixel are... Read the currently scanned pixel from the gradient direction field. gradient direction value at Read the pixels above gradient direction value at The differential calculation method involves calculating the gradient direction value. With gradient direction value The difference is used as the vertical increment.

[0041] The vertical integral value of the current pixel is obtained by adding the vertical increment to the integral value of the pixel above. The integral value of the pixel above refers to the integral value of the pixel above. The integral value calculated in the previous processing steps is denoted as . The vertical integral value of the current pixel. The calculation method is to integrate the vertical increment with the value of the pixel above. Add them together. For the first scanned pixel in each column, i.e., the row index... The pixel value equal to 2 is the pixel in the column corresponding to the row where the integration starts. The integration value of the pixel in the column corresponding to the row where the integration starts is determined by the horizontal integration value calculated during the row-by-row scanning process.

[0042] The reconstructed pixel value is obtained by taking a weighted average of the horizontal and vertical integral values. The formula for calculating the weighted average is:

[0043] in, Indicates that it is located in the row index and column indexes Integral reconstruction of pixel values ​​at the location, Indicates that it is located in the row index and column indexes The horizontal integral value at that point, Indicates that it is located in the row index and column indexes The vertical integral value at that point. This represents the weighting coefficients for the integral value in the horizontal direction. These represent the weighting coefficients for the integral value in the vertical direction. and The way to obtain the value is, Set to 0.5. The value is set to 0.5. The basis for this setting is that the horizontal and vertical integration paths contribute equally to the surface reconstruction results. By merging the integration information from the two directions with equal weights, the directional cumulative error can be balanced.

[0044] An integral reconstruction surface is constructed based on the integral reconstructed pixel values ​​of all pixels. The integral reconstruction surface is a two-dimensional matrix with the same size as the gradient direction field, and the value at each pixel position in the two-dimensional matrix is ​​the integral reconstructed pixel value of the corresponding pixel. .

[0045] The horizontal curvature matrix is ​​obtained by performing a second-order difference calculation in the horizontal direction on the integrally reconstructed surface. The method for calculating the second-order difference in the horizontal direction is as follows: for each pixel position in the integrally reconstructed surface... Obtain the integral reconstructed pixel value of the left adjacent pixel in the horizontal direction. Integral reconstruction of pixel value with adjacent pixels on the right Calculate the sum of the integral reconstructed pixel values ​​of the left and right adjacent pixels, and subtract twice the integral reconstructed pixel value of the current pixel. The difference obtained is used as the horizontal curvature value of the pixel position, and the horizontal curvature values ​​of all pixel positions constitute the horizontal curvature matrix.

[0046] The vertical curvature matrix is ​​obtained by performing a second-order difference calculation in the vertical direction on the integrally reconstructed surface. The method for calculating the second-order difference in the vertical direction is as follows: for each pixel position in the integrally reconstructed surface... Obtain the integral reconstructed pixel value of the adjacent pixels above it in the vertical direction. Reconstruct the pixel value by integrating with the adjacent pixels below. Calculate the sum of the integral reconstructed pixel values ​​of the upper adjacent pixels and the lower adjacent pixels, and subtract twice the integral reconstructed pixel value of the current pixel. The difference obtained is used as the vertical curvature value of the pixel position, and the vertical curvature values ​​of all pixel positions constitute the vertical curvature matrix.

[0047] The diagonal curvature matrix is ​​obtained by performing second-order difference calculations in the diagonal direction on the integrally reconstructed surface. The method for calculating the second-order difference in the diagonal direction is as follows: for each pixel position in the integrally reconstructed surface... Obtain the integral reconstructed pixel value of the top-left adjacent pixel in the main diagonal direction. Integral reconstruction of pixel values ​​with the bottom right adjacent pixel Calculate the sum of the integral reconstructed pixel value of the top-left adjacent pixel and the integral reconstructed pixel value of the bottom-right adjacent pixel, and subtract twice the integral reconstructed pixel value of the current pixel. The difference is used as the first diagonal curvature component; the integral reconstructed pixel value of the upper right adjacent pixel in the secondary diagonal direction is obtained. Integral reconstruction of pixel values ​​with the bottom left adjacent pixels Calculate the sum of the integral reconstructed pixel value of the upper right adjacent pixel and the integral reconstructed pixel value of the lower left adjacent pixel, and subtract twice the integral reconstructed pixel value of the current pixel. The difference obtained is used as the second diagonal curvature component; the one with the largest absolute value between the first and second diagonal curvature components is taken as the diagonal curvature value of the pixel position, and the diagonal curvature values ​​of all pixel positions constitute a diagonal curvature matrix. For a pixel located at the boundary of the integral reconstruction surface, if its required neighboring pixels are outside the range of the integral reconstruction surface, the horizontal curvature value, vertical curvature value, and diagonal curvature value of the pixel position are all set to zero.

[0048] The curvature intensity matrix is ​​obtained by summing the absolute values ​​of the horizontal, vertical, and diagonal curvature matrices. The method for summing the absolute values ​​is to perform the summation on the position of each pixel in the integrally reconstructed surface. Take the absolute value of the horizontal curvature value of the pixel position in the horizontal curvature matrix, the absolute value of the vertical curvature value of the pixel position in the vertical curvature matrix, and the absolute value of the diagonal curvature value of the pixel position in the diagonal curvature matrix. Add the three absolute values ​​to obtain the curvature intensity value of the pixel position. The curvature intensity values ​​of all pixel positions constitute the curvature intensity matrix.

[0049] The curvature response map is obtained by performing local contrast stretching enhancement on the curvature intensity matrix. The method involves dividing the curvature intensity matrix into multiple non-overlapping local blocks, each with a size of 16 rows and 16 columns of pixels. For each local block, the minimum and maximum curvature intensity values ​​are determined. The curvature intensity value at each pixel location within the local block is then remapped to an integer range of 0 to 255 using a linear mapping method. The mapping formula is: subtract the minimum value of the local block from the original curvature intensity value at the pixel location, divide by the difference between the maximum and minimum values ​​of the local block, multiply by 255, and round the result. After processing all local blocks, the mapping results of all local blocks are stitched together to form the curvature response map.

[0050] Example 4:

[0051] In specific implementation, please refer to Figure 3 For each pixel in the curvature response map, the curvature values ​​within its eight-neighbor range are extracted to form a local curvature sequence. The eight-neighbor range is defined as follows: taking the current pixel as the center, select three pixels in the row above the center pixel that are to the left, right, and left of the center column; select two pixels in the row above the center pixel that are to the left and right of the center column; and select three pixels in the row below the center pixel that are to the left, right, and left of the center column. A total of eight neighboring pixels are then selected. The curvature response values ​​of each of the eight neighboring pixels are read from the curvature response map, and these eight curvature response values ​​are stored in a one-dimensional array in the order they are read. This one-dimensional array represents the local curvature sequence corresponding to the current pixel.

[0052] The local curvature sequence is sorted to obtain the maximum and minimum values. The sorting method involves comparing the eight curvature response values ​​in the one-dimensional array numerically, rearranging them in descending order. The first element of the sorted one-dimensional array is the maximum value, and the last element is the minimum value. The curvature value of the current pixel is then determined by reading the curvature response value from the curvature response map, comparing it with both the maximum and minimum values. If either the maximum or minimum value is equal, the current pixel is marked as a local extremum candidate. Finally, all pixels in the curvature response map are traversed, and the coordinates of all pixels marked as local extremum candidates are compiled to obtain a list of extremum coordinates. The list of extreme coordinates is a two-dimensional array. Each row in the two-dimensional array records the row index and column index of a local extreme candidate point. The row index and column index are defined according to the pixel coordinate system of the curvature response map. The row index increases from top to bottom, and the column index increases from left to right.

[0053] Non-maximum suppression is applied to the extreme value coordinate list to remove adjacent redundant points, resulting in a candidate defect coordinate set. In some implementations, non-maximum suppression is performed by setting a suppression neighborhood radius of three pixels. This radius is based on the fact that the typical size of a surface defect on a fixed-focus lens typically results in a response region width of no less than six pixels on the curvature response map. Setting the suppression neighborhood radius to three pixels allows for the removal of redundant extreme value candidate points within the same response region while retaining the extreme value points of different defect response regions. The coordinates of each local extreme value candidate point in the extreme value coordinate list are traversed, and the Euclidean distance between the current local extreme value candidate point and the retained coordinate points in the candidate defect coordinate set is calculated. The formula for calculating the Euclidean distance is:

[0054] in, Represents the first value in the list of extreme value coordinates. In the set of local extremum candidate points and candidate defect coordinates, the th... Euclidean distance between the preserved coordinate points This represents the index number of the local extremum candidate point in the extremum coordinate list. The value range is an integer from one to the total number of local extremum candidate points in the extremum coordinate list. This indicates the index number of the retained coordinate point in the candidate defect coordinate set. The value range is an integer from one to the total number of coordinate points retained in the candidate defect coordinate set. Represents the first value in the list of extreme value coordinates. Row index value of candidate local extrema. Represents the first value in the list of extreme value coordinates. The column index value of the candidate local extrema. Represents the first in the set of candidate defect coordinates The row index value of the reserved coordinate point Represents the first in the set of candidate defect coordinates The column index values ​​of the reserved coordinate points. If the Euclidean distance... If the distance between the current local extremum candidate point and the already retained coordinate points is less than three pixels from the suppression neighborhood radius, then the current local extremum candidate point is determined to be an adjacent redundant point with respect to the retained coordinate points. The current local extremum candidate point is discarded and not added to the candidate defect coordinate set. If the Euclidean distance between the current local extremum candidate point and all retained coordinate points in the candidate defect coordinate set is greater than or equal to the suppression neighborhood radius, then the current local extremum candidate point is added to the candidate defect coordinate set.

[0055] A seed point is selected from the candidate defect coordinate set, where each unmarked coordinate is chosen. In practice, a marker array of the same size as the candidate defect coordinate set is maintained. Each element in the marker array corresponds to the marking state of a coordinate point in the candidate defect coordinate set, with the marking state being either marked or unmarked. Initially, all elements in the marker array are unmarked. The seed point selection process involves iterating through the marker array, finding the first element with an unmarked state, and using its corresponding coordinate point in the candidate defect coordinate set as the seed point. Simultaneously, the marking state of the corresponding element in the marker array is changed to marked. An eight-neighbor expansion search is then performed on the seed point to obtain neighboring candidate coordinate points. The eight-neighbor expansion search method involves generating eight neighboring coordinate positions around the seed point, based on the seed point's coordinates. These eight neighboring coordinate positions are located at the seed point's upper left, upper right, upper left, upper right, lower left, lower right, and lower right directions. The offsets of each neighboring coordinate position relative to the seed point in the row and column directions are -1 and -1, -1 and 0, -1 and +1, 0 and -1, 0 and +1, +1 and -1, +1 and 0, and +1 and +1, respectively. The search then checks the candidate defect coordinate set to see if any coordinate point matches one of the eight neighboring coordinate positions. If a matching coordinate point exists, it is designated as an adjacent candidate coordinate point.

[0056] Connectivity checks are performed on adjacent candidate coordinate points to obtain connected regions. The connectivity check method is as follows: traverse all adjacent candidate coordinate points, checking the marking status of each adjacent candidate coordinate point in the marking array. If the marking status is unmarked, add the adjacent candidate coordinate point to the current connected region, and modify the marking status of the corresponding element in the marking array to marked. Simultaneously, use the newly added adjacent candidate coordinate point as the new seed point to recursively perform eight-neighbor expansion search and connectivity checks. Repeat the above recursive process until no new adjacent candidate coordinate points are found and added to the current connected region. The current connected region is a complete connected region grown from the initial seed point. Assign the same region number to all coordinate points within the connected region. The region number is a positive integer starting from one and incrementing sequentially. Repeat the selection of seed points and connectivity checks until all candidate coordinate points in the candidate defect coordinate set have been assigned region numbers.

[0057] An initial defect region marker map is generated based on region numbers. The method for generating the initial defect region marker map is as follows: a two-dimensional matrix with the same size as the curvature response map is created, and all element values ​​in the two-dimensional matrix are initialized to zero. For each coordinate point in the candidate defect coordinate set, the corresponding region number value is filled into the corresponding position in the two-dimensional matrix according to the region number assigned to the coordinate point. Positions in the two-dimensional matrix not covered by candidate defect coordinate points are kept as zero. The two-dimensional matrix after filling in the region number values ​​is the initial defect region marker map.

[0058] A circular structuring element is constructed to perform a dilation operation on the initial defect region marker map to obtain a dilated image. The circular structuring element is constructed by setting its radius to three pixels, using its center as the origin, calculating the Euclidean distance from the center to surrounding pixels, and including all pixels with an Euclidean distance less than or equal to three pixels within the effective area of ​​the circular structuring element. The dilation operation is performed by sliding the circular structuring element as a morphological template pixel-by-pixel across the initial defect region marker map. The maximum pixel value within the area covered by the circular structuring element is taken and assigned to the pixel at the center of the circular structuring element. This process is repeated for all pixels in the initial defect region marker map to obtain the dilated image.

[0059] An erosion operation is performed on the dilated image to obtain an eroded image. The erosion operation is performed by sliding circular structuring elements with a radius of three pixels across the dilated image pixel by pixel. The minimum value of each pixel within the area covered by the circular structuring element is taken and assigned to the pixel at the center of the circular structuring element. After traversing all pixels of the dilated image, the eroded image is obtained.

[0060] The updated region label map is obtained by updating the connected component numbers of the eroded image. The method for updating the connected component numbers is as follows: for all non-zero pixels in the eroded image, connected regions are detected in a 4-connected or 8-connected manner. For each independent connected region, a consecutive region number starting from one and increasing sequentially is reassigned. The original region number of each pixel in the eroded image is replaced with the reassigned region number. The eroded image after reassigning the region numbers constitutes the updated region label map.

[0061] The filled region marker map is obtained by filling empty regions in the updated region marker map with pixels whose area is smaller than a preset hole threshold. The preset hole threshold is set to twenty-five pixels. The reason for this setting is that the response area formed by the effective defect area on the curvature response map of a fixed-focus lens surface is usually no less than fifty pixels. Setting the hole threshold to twenty-five pixels can fill small noise holes while preserving the internal structure of the effective defect area. The pixel filling process is as follows: traverse each connected region in the updated region marker map, count the total number of pixels contained in the connected region. If the total number of pixels is less than twenty-five pixels, set the region number of all pixels in the connected region to zero. If the total number of pixels is greater than or equal to twenty-five pixels, keep the region number of all pixels in the connected region unchanged. The image obtained after the traversal is completed is the filled region marker map.

[0062] The defect region marker image is obtained by performing a logical OR operation between the filled region marker image and the initial defect region marker image. The logical OR operation is performed on each corresponding pixel in both images. If either the pixel value in the filled region marker image or the pixel value in the initial defect region marker image is non-zero, or both conditions are met, the pixel value in the defect region marker image is set to a non-zero value. Specifically, the value is the larger of the pixel value in the filled region marker image and the pixel value in the initial defect region marker image. If both the filled region marker image and the initial defect region marker image have zero pixel values, the pixel value in the defect region marker image is set to zero. The image obtained after traversing all pixels is the defect region marker image.

[0063] Example 5:

[0064] In practice, the area parameter of each connected region in the defect region marking map is obtained by counting the number of pixels. The defect region marking map is a two-dimensional matrix. Non-zero pixels with the same value in the two-dimensional matrix constitute a connected region, and different values ​​correspond to different connected regions. The pixel counting method is to traverse all pixels in the defect region marking map and maintain an area counter for each connected region. When a pixel belonging to a certain connected region is scanned, the value of the area counter corresponding to that connected region is incremented by one. After traversing all pixels, the final value of the area counter for each connected region is the area parameter of that connected region.

[0065] Boundary pixel set is obtained by extracting the boundary of each connected region. In some implementations, the boundary extraction method is as follows: a binary mask image is constructed separately for each connected region in the defect region marking image. Pixels belonging to the current connected region in the binary mask image are set as foreground values, and pixels not belonging to the current connected region are set as background values. Boundary tracking is performed on the binary mask image. The starting point of boundary tracking is the foreground pixel with the smallest row index and column index in the binary mask image. Starting from the starting point, the foreground and background states of each pixel within the eight-neighborhood of the starting point are checked in a clockwise direction. The first foreground pixel checked within the eight-neighborhood is taken as the next boundary point, and the tracking direction between the previous boundary point and the current boundary point is recorded. With the newly determined boundary point as the current point, and the direction from the previous boundary point to the current boundary point as the reference direction, starting from the direction after rotating 90 degrees counterclockwise from the reference direction, the foreground and background states of each pixel within the eight-neighborhood of the current point are checked in a clockwise direction. The first foreground pixel checked within the eight-neighborhood is taken as the next boundary point. Repeat the above tracing process until the tracing returns to the starting point and the tracing direction is consistent with the initial direction when leaving the starting point. All boundary points visited during the tracing process constitute the set of boundary pixels for the connected region. Perform the above boundary extraction process on all connected regions to obtain the set of boundary pixels for each connected region.

[0066] The region's length and width parameters are obtained by fitting the minimum bounding rectangle to the boundary pixel set. The method for minimum bounding rectangle fitting involves treating all boundary pixels in the boundary pixel set as a discrete point set and using a rotating caliper algorithm to calculate the minimum area bounding rectangle of the discrete point set. The rotating caliper algorithm is implemented as follows: calculate the convex hull of the discrete point set; select an initial edge on the convex hull; generate an initial bounding rectangle based on the initial edge and calculate its area; rotate the initial edge along the convex hull to the next edge, generating a new bounding rectangle and calculating its area; after traversing all edges on the convex hull, select the bounding rectangle with the smallest area as the minimum bounding rectangle. The length and width dimensions of the minimum bounding rectangle constitute the region's length and width parameters, respectively. The length dimension is the pixel length of the longer side of the minimum bounding rectangle, and the width dimension is the pixel length of the shorter side.

[0067] The area and aspect ratio parameters of the affected area are jointly determined. The method for this joint determination involves two preset threshold conditions: an area threshold range and an aspect ratio threshold range. The lower limit of the area threshold range is set to fifty pixels, and the upper limit is set to ten thousand pixels. The reason for setting the lower limit to fifty pixels is that the smallest resolvable area formed by a valid defect on the surface of a fixed-focus lens in an image typically occupies no less than fifty pixels; connected regions smaller than fifty pixels are highly likely to be image noise or dust interference. The reason for setting the upper limit to ten thousand pixels is that the physical size of a defect on the surface of a fixed-focus lens is limited by the lens aperture, and the number of pixels corresponding to the defect area will not exceed ten thousand pixels at standard imaging resolution. The lower limit of the aspect ratio threshold range is set to 1.2, and the upper limit is set to 5.0. The reason for setting the lower limit to 1.2 is that the shape of a defect on the surface of a fixed-focus lens is usually not perfectly circular; the aspect ratio of the smallest bounding rectangle of the defect area is generally greater than 1.2, and connected regions with an aspect ratio close to 1.0 are usually bubbles or point artifacts. The basis for setting the upper limit of the aspect ratio threshold range to five points is that the length-to-width ratio of long strip-shaped scratches in the surface defects of fixed-focus lenses usually does not exceed five points. Connected areas with an aspect ratio exceeding five points may be lens edge reflections or linear texture interference.

[0068] Connected regions that simultaneously satisfy both area and aspect ratio threshold ranges are identified as valid defect regions. During the joint parameter determination process, for each connected region in the defect region labeling diagram, it is determined whether the region's area parameter is greater than or equal to the lower limit of the area threshold range and less than or equal to the upper limit. Simultaneously, the aspect ratio is calculated by dividing the length of the smallest bounding rectangle of the connected region by its length and width, and then checked against the lower and upper limits of the aspect ratio threshold range. If both the area parameter and aspect ratio of a connected region satisfy the area and aspect ratio threshold ranges, the connected region is marked as a valid defect region. If neither condition is met, the connected region is marked as an invalid interference region.

[0069] A defect boundary line map is generated based on the contour coordinates of all valid defect regions. The generation method involves creating a blank image with the same size as the defect region marker image and all pixel values ​​set to zero. For each valid defect region, the coordinates of all boundary pixels are retrieved from the set of boundary pixels corresponding to that region. The pixel value at the corresponding coordinate position in the blank image is then set as the edge marker value, which is 255. Positions not covered by boundary pixels retain a pixel value of zero. After processing all valid defect regions, the blank image containing the edge marker values ​​is the defect boundary line map.

[0070] The surface defect detection result is output by overlaying the defect boundary line map onto the original grayscale image. The overlay method involves pixel-by-pixel processing of both the original grayscale image and the defect boundary line map. At each pixel location, it is determined whether the pixel value in the defect boundary line map equals the edge marker value of 255. If it does, the output value of that pixel in the surface defect detection result image is set to the edge marker value of 255; otherwise, the output value is set to the original grayscale value of the corresponding pixel in the original grayscale image. The final surface defect detection result is obtained after traversing all pixels.

[0071] The above description is merely a specific embodiment of this application, but the scope of protection of this application is not limited thereto. Any changes or substitutions that can be easily conceived by those skilled in the art within the scope of the technology disclosed in this application should be included within the scope of protection of this application.

Claims

1. A method for detecting surface defects in a fixed-focus lens based on image enhancement technology, characterized in that, include: The original grayscale image of the fixed-focus lens under uniform illumination is obtained. The original grayscale image is subjected to a two-dimensional Fourier transform to obtain a frequency domain spectrum. The low-frequency components in the frequency domain spectrum are subjected to zero-frequency suppression processing to generate a high-frequency enhanced spectrum. The high-frequency enhanced spectrum is subjected to an inverse Fourier transform to obtain a detail enhanced image. The detail enhanced image is subjected to gradient field reconstruction processing to obtain a gradient direction field. An integral surface is fitted to the gradient direction field to generate an integral reconstructed surface. The second-order partial derivative of the integral reconstructed surface is calculated to obtain a curvature response map. Local extremum points are detected in the curvature response map to generate a set of candidate defect coordinates. Spatial neighborhood aggregation is performed on the candidate defect coordinate set to generate a defect region marking map, and connected component analysis is performed on the defect region marking map to output the surface defect detection results.

2. The method for detecting surface defects of a fixed-focus lens based on image enhancement technology according to claim 1, characterized in that, A two-dimensional Fourier transform is performed on the original grayscale image to obtain a frequency domain spectrum. Zero-frequency suppression processing is then applied to the low-frequency components in the frequency domain spectrum to generate a high-frequency enhanced spectrum. Specifically: The original grayscale image is subjected to a discrete Fourier transform to obtain the frequency domain spectrum. The amplitude spectrum of the frequency domain spectrum is divided into a ring region to obtain a central low-frequency disk region. The mean of all amplitude values ​​in the central low-frequency disk region is calculated to obtain the low-frequency mean. The zero-frequency suppression amplitude value is obtained by subtracting the low-frequency mean from the amplitude value of each pixel in the central low-frequency disk region. The zero-frequency suppression amplitude value and the phase spectrum of the frequency domain spectrum are reconstructed using complex numbers to obtain the high-frequency enhancement spectrum.

3. The method for detecting surface defects of a fixed-focus lens based on image enhancement technology according to claim 2, characterized in that, The inverse Fourier transform of the high-frequency enhanced spectrogram yields a detail-enhanced image, specifically: The high-frequency enhanced spectrum is subjected to discrete inverse Fourier transform to obtain a frequency domain enhanced complex field. The frequency domain enhanced complex field is subjected to modulo operation to obtain an amplitude response matrix. The amplitude response matrix is ​​linearly normalized to obtain a normalized amplitude matrix. The normalized amplitude matrix is ​​adjusted by power-law mapping to obtain an intermediate enhanced image. The intermediate enhanced image is subjected to median filtering to remove impulse noise and obtain the detail enhanced image.

4. The method for detecting surface defects of a fixed-focus lens based on image enhancement technology according to claim 3, characterized in that, The gradient direction field is obtained by performing gradient field reconstruction processing on the enhanced detail image, specifically as follows: The Sobel gradient operator is used to convolve the detail-enhanced image to obtain an initial gradient matrix. The gradient magnitude of the initial gradient matrix is ​​then thresholded to obtain an effective gradient mask. For each pixel within the coverage area of ​​the effective gradient mask, its eight-neighbor gradient direction histogram is calculated. The dominant gradient direction is extracted from the eight-neighbor gradient direction histogram to obtain the local dominant gradient direction. Based on the local dominant gradient direction, the initial gradient matrix is ​​corrected by orientation constraint to obtain the gradient direction field.

5. The method for detecting surface defects of a fixed-focus lens based on image enhancement technology according to claim 4, characterized in that, The gradient direction field is fitted with an integral surface to generate an integral reconstructed surface, specifically as follows: The first row and first column of the gradient direction field are selected as the integration starting point. An initial integration value is assigned to the integration starting point. The gradient direction field is scanned row by row. The gradient direction of the currently scanned pixel and the pixel to its left are differentially calculated to obtain the horizontal direction increment. The horizontal direction increment is added to the integration value of the pixel to its left to obtain the horizontal direction integration value of the current pixel. The gradient direction field is scanned column by column. The gradient direction of the currently scanned pixel and the pixel above it are differentially calculated to obtain the vertical direction increment. The vertical direction increment is added to the integration value of the pixel above it to obtain the vertical direction integration value of the current pixel. The horizontal direction integration value and the vertical direction integration value are weighted and averaged to obtain the integrated reconstructed pixel value. The integrated reconstructed surface is constructed based on the integrated reconstructed pixel values ​​of all pixels.

6. The method for detecting surface defects of a fixed-focus lens based on image enhancement technology according to claim 5, characterized in that, The curvature response map is obtained by calculating the second-order partial derivative of the integral reconstructed surface, specifically as follows: The horizontal curvature matrix is ​​obtained by performing second-order difference calculation in the horizontal direction on the integral reconstructed surface. The vertical curvature matrix is ​​obtained by performing second-order difference calculation in the vertical direction on the integral reconstructed surface. The diagonal curvature matrix is ​​obtained by performing second-order difference calculation in the diagonal direction on the integral reconstructed surface. The curvature intensity matrix is ​​obtained by summing the absolute values ​​of the horizontal curvature matrix, the vertical curvature matrix, and the diagonal curvature matrix. The curvature response map is obtained by performing local contrast stretching enhancement on the curvature intensity matrix.

7. The method for detecting surface defects of a fixed-focus lens based on image enhancement technology according to claim 6, characterized in that, The curvature response map is subjected to local extremum point detection to generate a set of candidate defect coordinates, specifically as follows: For each pixel in the curvature response map, the curvature values ​​within its eight neighborhood range are extracted to form a local curvature sequence. The local curvature sequence is sorted to obtain the maximum and minimum values. It is determined whether the curvature value of the current pixel is equal to the maximum or minimum value. If so, the current pixel is marked as a local extreme value candidate point. The coordinates corresponding to all local extreme value candidate points are sorted to obtain an extreme value coordinate list. Non-maximum suppression is performed on the extreme value coordinate list to remove adjacent redundant points and obtain the candidate defect coordinate set.

8. The method for detecting surface defects of a fixed-focus lens based on image enhancement technology according to claim 7, characterized in that, The candidate defect coordinate set is spatially aggregated to generate a defect region marking map, specifically as follows: Select an unmarked coordinate point from the candidate defect coordinate set as a seed point. Perform an eight-neighbor expansion search on the seed point to obtain adjacent candidate coordinate points. Perform connectivity judgment on the adjacent candidate coordinate points to obtain connected regions. Assign the same region number to all coordinate points within the connected regions. Repeat the selection of the seed point and the connectivity judgment until all candidate coordinate points are assigned region numbers. Generate an initial defect region marking map based on the region numbers. Perform morphological closing operation on the initial defect region marking map to fill small holes to obtain the defect region marking map.

9. The method for detecting surface defects of a fixed-focus lens based on image enhancement technology according to claim 8, characterized in that, Connectivity analysis is performed on the defect region marker map to output the surface defect detection results, specifically: The area parameter is obtained by counting pixels in each connected region of the defect region marking map. The boundary of each connected region is extracted to obtain a set of boundary pixels. The length and width parameters of the region are obtained by fitting the minimum bounding rectangle of the boundary pixel set. The area parameter and the length and width parameters of the region are jointly judged. The connected regions that simultaneously satisfy the area threshold range and the aspect ratio threshold range are determined as valid defect regions. A defect boundary line map is generated based on the contour coordinates of all valid defect regions. The defect boundary line map is superimposed on the original grayscale image to output the surface defect detection result.

10. The method for detecting surface defects of a fixed-focus lens based on image enhancement technology according to claim 9, characterized in that, The initial defect region marking map is subjected to morphological closing operations to fill small holes, resulting in the defect region marking map. Specifically: A circular structural element is constructed to dilate the initial defect region marking map to obtain an dilated image. An erosion operation is then performed on the dilated image to obtain an eroded image. The connected component numbers of the eroded image are updated to obtain an updated region marking map. Holes in the updated region marking map with areas smaller than a preset hole threshold are filled with pixels to obtain a filled region marking map. Finally, the filled region marking map and the initial defect region marking map are logically ORed to obtain the defect region marking map.