Lens edge detection method and system based on image generation

CN121962182BActive Publication Date: 2026-09-22GUANGDONG JIAXUAN OPTICAL TECHNOLOGY CO LTD
View PDF 2 Cites 0 Cited by

Patent Information

Application Number
CN202512050270.4
Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2025-12-31
Publication Date
2026-09-22
Estimated Expiration
2045-12-31

AI Technical Summary

Technical Problem

[0005]为了解决现有镜片边缘检测依赖单一灰度梯度变化判定边界位置,在复杂光照与背景反射条件下,像素亮度受成像噪声与局部反射影响显著,阈值判定结果随区域变化而波动,真实边缘与干扰边缘难以区分,逐行或逐列扫描形成的边界点缺乏方向与空间一致性约束,边缘点分布呈离散状态,轮廓连接依赖经验规则,曲率变化区域易出现断裂与偏移,导致边缘轮廓稳定性不足,影响后续几何拟合与检测一致性的技术问题,本发明实施例提供了基于图像生成的镜片边缘检测方法

Benefits of technology

本发明中,通过在边缘提取过程中引入像素邻域灰度差的有效性约束,削弱随机噪声与局部反射对边缘判定的影响,并结合梯度方向与光源入射方向之间的相位关系,对符合成像方向特征的像素进行筛选,使边缘特征具备方向一致性,在此基础上依据空间连续性与梯度强度进行聚类处理,将分散像素整合为结构明确的像素簇,轮廓构建依托像素簇空间分布进行连续拟合,从而提升复杂光照条件下镜片边缘表达的完整性与几何一致性。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN121962182B_ABST
    Figure CN121962182B_ABST
Patent Text Reader

Abstract

The application relates to the technical field of image processing, in particular to a lens edge detection method and system based on image generation, which comprises the following steps: collecting a lens image through an industrial camera and weighting and gray-scale processing, extracting edge coordinates by using a Laplace operator, constructing an edge pixel coordinate set, screening edge effectiveness mark results in combination with a gray-scale difference threshold, calculating a gradient direction and a light source incidence phase difference based on a Sobel operator, extracting consistent direction pixels and performing spatial clustering, generating lens edge pixel clusters, fitting a continuous curve to construct a complete lens edge contour, and restraining noise and reflection interference through pixel neighborhood gray-scale difference constraints in the application, screening effective pixels in combination with the relationship between the gradient direction and the light source incidence phase, enhancing the consistency of the edge direction, clustering pixels according to spatial continuity and gradient intensity, fitting the contour based on pixel cluster distribution continuity, and improving the completeness and geometric consistency of the lens edge under complex illumination.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to the field of image processing technology, and in particular to a lens edge detection method and system based on image generation. Background Technology

[0002] Image processing technology involves technologies related to the acquisition, preprocessing, analysis, and representation of digital images. Its core aspects include image acquisition and imaging conversion, grayscale and brightness normalization, pixel-level numerical operations, spatial neighborhood operations, feature extraction, and pixel-based structural description. This technology focuses on fundamental issues such as distinguishing target and background regions in an image, geometric morphology description, and boundary location determination. It is widely used in industrial inspection, optical measurement, and visual analysis scenarios.

[0003] Traditional lens edge detection methods refer to a type of processing that determines the position of the outer contour of a lens by analyzing pixel brightness changes in a lens image. The technical issue it addresses is determining the position of the lens boundary in an image containing background interference and illumination changes. The methods include converting the original lens image into a grayscale image and performing brightness equalization processing, calculating gradient values ​​based on the brightness difference of pixels in the horizontal or vertical direction, binarizing the gradient results by setting a fixed threshold or a local threshold, scanning row by row or column by column along pixels with significant gradient changes to form a continuous set of boundary points, and finally connecting the obtained boundary points sequentially to describe the edge contour of the lens.

[0004] Current edge detection methods rely on a single gray-level gradient change to determine the boundary position. Under complex lighting and background reflection conditions, pixel brightness is significantly affected by imaging noise and local reflection. The threshold determination results fluctuate with the region, making it difficult to distinguish between real edges and interference edges. Boundary points formed by row-by-row or column-by-column scanning lack directional and spatial consistency constraints, resulting in a discrete distribution of edge points. Contour connections rely on empirical rules, and areas with curvature changes are prone to breakage and displacement, leading to insufficient edge contour stability and affecting the consistency of subsequent geometric fitting and detection. Summary of the Invention

[0005] To address the technical problems of existing lens edge detection methods that rely on a single gray-level gradient change to determine the boundary position, pixel brightness is significantly affected by imaging noise and local reflection under complex lighting and background reflection conditions, threshold determination results fluctuate with region changes, it is difficult to distinguish between real edges and interference edges, boundary points formed by row-by-row or column-by-column scanning lack directional and spatial consistency constraints, edge point distribution is discrete, contour connection relies on empirical rules, and curvature change areas are prone to breakage and displacement, resulting in insufficient edge contour stability and affecting the consistency of subsequent geometric fitting and detection, this invention provides a lens edge detection method based on image generation.

[0006] To achieve the above objectives, this invention employs an image-based lens edge detection method, comprising the following steps: S1: Obtain the original image of the lens through an industrial camera, convert the red, green and blue channel values ​​of the pixels to grayscale according to the weight coefficients, input the grayscale values ​​into the Laplacian operator to extract the edge region, and construct a set of edge pixel coordinates; S2: Calculate the absolute value of the gray level difference between each pixel and its eight neighboring pixels based on the set of edge pixel coordinates, compare it with the noise intensity threshold to mark valid edge pixels, and generate edge validity marking results; S3: Call the edge validity marking result to input the Sobel gradient operator to calculate the gradient direction angle, calculate the phase difference based on the incident angle of the light source and the gradient direction angle, and filter the pixel points whose gradient direction is consistent with the incident direction of the light source based on the phase difference to construct the lens edge feature pixel set; S4: Call the set of feature pixels at the edge of the lens, filter pixels with gradient intensity greater than the gradient threshold and spatial continuity, and cluster them according to their coordinate positions to generate a cluster of pixels at the edge of the lens. S5: Perform edge contour fitting based on the pixel clusters at the edge of the lens, calculate the coordinates of the curve control points according to the spatial distribution characteristics of the pixel clusters, connect the fitted curve segments end to end according to the principle of continuity, and construct the complete edge contour of the lens.

[0007] As a further aspect of the present invention, the set of edge pixel coordinates includes the spatial location of edge points, the edge distribution range, and the grayscale gradient magnitude; the edge validity marking result includes the effective edge category, noise suppression status, and edge confidence; the set of lens edge feature pixels includes gradient direction consistency features, phase difference features, and edge direction stability features; the lens edge pixel cluster includes spatially continuous regions, local edge structure units, and high gradient regions; and the complete edge contour of the lens specifically includes the overall contour shape, boundary continuity characteristics, and contour curvature distribution.

[0008] As a further aspect of the present invention, the specific steps of S1 are as follows: S101: Acquires the original image of the lens through an industrial camera, collects sensor array data frames, retrieves the red channel value, green channel value, and blue channel value of the pixel, performs channel alignment and matrix rearrangement according to the pixel index, and generates a pixel channel value matrix. S102: Based on the pixel channel value matrix, determine the channel weight coefficients according to the pixel channel value distribution relationship, perform pixel-by-pixel weighting on the red channel value, green channel value, and blue channel value, map them into a single-channel pixel index structure and verify the index consistency, and generate a grayscale pixel value matrix. S103: Based on the grayscale pixel value matrix, construct the pixel neighborhood Laplacian operator convolution relationship, perform second-order spatial difference operation on the pixel index, obtain the Laplacian response value and perform neighborhood change judgment, aggregate the corresponding pixel spatial coordinates, and establish an edge pixel coordinate set.

[0009] As a further aspect of the present invention, the specific steps of S2 are as follows: S201: Based on the set of edge pixel coordinates, retrieve the grayscale pixel value corresponding to the pixel coordinate and locate the coordinates of eight adjacent pixels. Extract the corresponding grayscale value according to the spatial adjacency relationship. Perform difference operation and absolute value transformation on the grayscale value of the center pixel and the adjacent grayscale values ​​to generate a set of absolute values ​​of grayscale difference in the pixel neighborhood. S202: Based on the set of absolute values ​​of grayscale differences in the pixel neighborhood, for multiple absolute values ​​of grayscale differences under the same pixel coordinate, compare them one by one with the noise intensity threshold. Pixel coordinates that are greater than the threshold are determined to be valid, and an edge candidate pixel determination mapping table is generated. S203: Based on the edge candidate pixel determination mapping table, perform logical merging on the valid determination states of pixel coordinates, mark the pixel coordinates that are determined to be valid as edge valid states, and mark the pixel coordinates that do not meet the requirements as non-edge states, and generate edge validity marking results.

[0010] As a further aspect of the present invention, the noise intensity threshold is statistically determined based on the set of absolute values ​​of gray-level differences in the pixel neighborhood. Specifically, for the set of absolute values ​​of gray-level differences in the pixel neighborhood corresponding to all pixel coordinates within the same image frame, the numerical distribution is extracted and statistical features are calculated. The noise intensity threshold is the value obtained by linear combination of the median and standard deviation in the statistical features.

[0011] As a further aspect of the present invention, the specific steps of S3 are as follows: S301: Call the edge validity marking result, locate the gray matrix index corresponding to the pixel coordinates marked as valid, use the Sobel gradient operator to calculate the horizontal and vertical gradient components for the index position, and perform direction mapping operation to generate a set of pixel gradient direction angles. S302: Based on the set of pixel gradient direction angles, obtain the set of light source incident angle parameters, perform angle difference calculation on the gradient direction angle and the light source incident angle under the same pixel coordinates, and perform interval mapping processing on the difference results to generate a gradient light source phase difference dataset. S303: Based on the gradient light source phase difference dataset, perform logical judgment on the consistency judgment criteria between the phase difference value and direction corresponding to the pixel coordinates, extract the pixel coordinates that are judged to be consistent and perform index aggregation, perform structured encoding on the aggregated pixel coordinates, and establish a set of lens edge feature pixels.

[0012] As a further aspect of the present invention, the specific steps of S4 are as follows: S401: Call the set of feature pixels at the edge of the lens, read the gradient intensity value corresponding to the pixel coordinate, perform item-by-item comparison and judgment based on the numerical relationship between the gradient intensity value and the gradient threshold, filter and collect the pixel coordinates that are greater than the threshold, and form a set of effective pixel coordinates for the gradient threshold. S402: Based on the effective pixel coordinate set of the gradient threshold, extract the spatial position parameters of the pixel coordinates, calculate the distance parameters between adjacent pixel coordinates, and perform logical judgment with the spatial continuity determination rules to associate and aggregate the pixel coordinates that meet the continuity relationship to obtain a spatially continuous pixel coordinate group. S403: Based on the spatial continuous pixel coordinate group, obtain the position distribution parameters of the pixel coordinates in the two-dimensional coordinate system, calculate the relative position difference between pixel coordinates in the same coordinate group, and perform clustering determination to group pixel coordinates with consistent positional relationships into the same group to generate a lens edge pixel cluster.

[0013] As a further aspect of the present invention, the gradient threshold is based on the gradient intensity values ​​corresponding to all pixel coordinates in the set of feature pixels at the edge of the lens. After sorting the gradient intensity values ​​according to their magnitude, the gradient intensity value at a preset sorting ratio position is selected as the fixed threshold.

[0014] As a further aspect of the present invention, the specific steps of S5 are as follows: S501: Based on the pixel clusters at the edge of the lens, analyze the distribution data of pixel coordinates in the two-dimensional coordinate system, arrange the pixel coordinates in order according to the spatial adjacency relationship, calculate the curve direction parameters based on the changes in the positions of adjacent coordinates, and generate a set of coordinates for edge curve control points. S502: Based on the coordinate set of control points of the edge curve, extract the spatial positional relationship parameters between adjacent control points, perform a judgment on the consistency of the connection direction between control points, filter the connectable control point pairs according to the endpoint correspondence, and construct a set of continuous edge curve segments; S503: Based on the set of continuous edge curve segments, extract the start and end position parameters of the curve segments in a unified coordinate system, perform matching judgment on the coordinates of the endpoints of adjacent curve segments, and perform sequential splicing calculation based on the relationship of endpoint overlap and direction consistency to establish the complete edge contour of the lens.

[0015] A lens edge detection system based on image generation includes: The image grayscale generation module acquires the original image of the lens through an industrial camera, converts the red, green and blue channel values ​​of the pixels into grayscale according to weight coefficients, inputs the grayscale values ​​into the Laplacian operator to extract the edge region, and constructs a set of edge pixel coordinates. The edge response construction module calculates the absolute value of the grayscale difference between each pixel and its eight neighboring pixels based on the set of edge pixel coordinates, compares it with the noise intensity threshold to mark valid edge pixels, and generates edge validity marking results. The direction consistency filtering module calls the edge validity labeling result as input to the Sobel gradient operator to calculate the gradient direction angle, calculates the phase difference based on the incident angle of the light source and the gradient direction angle, and filters pixels whose gradient direction is consistent with the incident direction of the light source based on the phase difference to construct a set of lens edge feature pixels; The edge pixel clustering module calls the set of feature pixels on the edge of the lens, filters pixels with gradient intensity greater than the gradient threshold and spatial continuity, and clusters them according to their coordinate positions to generate lens edge pixel clusters. The contour fitting generation module performs edge contour fitting based on the pixel clusters at the edge of the lens, calculates the coordinates of the curve control points according to the spatial distribution characteristics of the pixel clusters, and connects the fitted curve segments end to end according to the principle of continuity to construct the complete edge contour of the lens.

[0016] Compared with the prior art, the advantages and positive effects of the present invention are as follows: In this invention, by introducing the effective constraint of the gray-level difference of the pixel neighborhood during the edge extraction process, the influence of random noise and local reflection on edge determination is weakened. In addition, by combining the phase relationship between the gradient direction and the incident direction of the light source, pixels that conform to the imaging direction characteristics are screened to make the edge features have directional consistency. On this basis, clustering is performed based on spatial continuity and gradient intensity to integrate scattered pixels into pixel clusters with clear structures. Contour construction relies on the spatial distribution of pixel clusters for continuous fitting, thereby improving the integrity and geometric consistency of the lens edge expression under complex lighting conditions. Attached Figure Description

[0017] To more clearly illustrate the technical solutions in the embodiments of the present invention, the accompanying drawings used in the description of the embodiments will be briefly introduced below. Obviously, the accompanying drawings described below are only some embodiments of the present invention. For those skilled in the art, other drawings can be obtained based on the accompanying drawings without creative effort.

[0018] Figure 1 This is a schematic diagram of the steps of the present invention; Figure 2 This is a detailed schematic diagram of S1 of the present invention; Figure 3 This is a detailed schematic diagram of S2 of the present invention; Figure 4 This is a detailed schematic diagram of S3 of the present invention; Figure 5 This is a detailed schematic diagram of S4 of the present invention; Figure 6 This is a detailed schematic diagram of S5 of the present invention; Figure 7 This is a system module diagram of the present invention. Detailed Implementation

[0019] The technical solution of the present invention will now be described with reference to the accompanying drawings.

[0020] In embodiments of the present invention, words such as "exemplarily," "for example," etc., are used to indicate that something is an example, illustration, or description. Any embodiment or design described as "exemplary" in the present invention should not be construed as being more preferred or advantageous than other embodiments or designs. Specifically, the use of the word "exemplary" is intended to present the concept in a concrete manner. Furthermore, in embodiments of the present invention, the meaning expressed by "and / or" can be both, or either one.

[0021] In the embodiments of this invention, the terms "image" and "picture" may sometimes be used interchangeably. It should be noted that, without emphasizing the distinction between them, they convey the same meaning. Similarly, the terms "of," "corresponding (relevant)," and "corresponding" may sometimes be used interchangeably. It should be noted that, without emphasizing the distinction between them, they convey the same meaning.

[0022] In this embodiment of the invention, sometimes the subscript such as W1 is written in a non-subscript form such as W1. When the difference is not emphasized, the meaning they express is the same.

[0023] To make the technical problems, technical solutions and advantages of the present invention clearer, a detailed description will be given below in conjunction with the accompanying drawings and specific embodiments.

[0024] Please see Figure 1 This invention provides a lens edge detection method based on image generation, comprising the following steps: S1: Obtain the original image of the lens through an industrial camera, convert the red, green and blue channel values ​​of the pixels to grayscale according to the weight coefficients, input the grayscale values ​​into the Laplacian operator to extract the edge region, and construct a set of edge pixel coordinates; S2: Calculate the absolute value of the gray level difference between each pixel and its eight neighboring pixels based on the set of edge pixel coordinates, compare it with the noise intensity threshold to mark the effective edge pixels, and generate the edge validity marking result; S3: Call the edge validity labeling result to input the Sobel gradient operator to calculate the gradient direction angle, calculate the phase difference based on the incident angle of the light source and the gradient direction angle, and filter the pixels whose gradient direction is consistent with the incident direction of the light source based on the phase difference to construct the lens edge feature pixel set; S4: Call the set of feature pixels on the lens edge, filter pixels with gradient strength greater than the gradient threshold and spatial continuity, and cluster them according to their coordinate positions to generate lens edge pixel clusters; S5: Perform edge contour fitting based on the pixel clusters at the lens edge, calculate the coordinates of the curve control points according to the spatial distribution characteristics of the pixel clusters, connect the fitted curve segments end to end according to the principle of continuity, and construct the complete edge contour of the lens.

[0025] The edge pixel coordinate set includes the spatial location of edge points, the edge distribution range, and the gray-level gradient magnitude. The edge validity labeling results include the effective edge category, noise suppression status, and edge confidence. The lens edge feature pixel set includes gradient direction consistency features, phase difference features, and edge direction stability features. The lens edge pixel cluster includes spatially continuous regions, local edge structural units, and high gradient regions. The complete edge contour of the lens specifically includes the overall contour shape, boundary continuity characteristics, and contour curvature distribution.

[0026] Please see Figure 2 The specific steps of S1 are as follows: S101: Acquires the original image of the lens through an industrial camera, collects sensor array data frames, retrieves the red channel value, green channel value, and blue channel value of the pixel, performs channel alignment and matrix rearrangement according to the pixel index, and generates a pixel channel value matrix. The original image of the lens is acquired using an industrial camera, with a selected configuration... An industrial camera with a 10-megapixel CMOS sensor, with an exposure time set to... And the gain value is dB, for a diameter of [missing value] under LED coaxial light source illumination. The camera uses a plano-convex lens to capture images. The camera transmits the raw data frames of the Bayer pattern to the image processing unit via the GigE interface. The processing unit first allocates memory with a size of [missing information]. The buffer receives the data stream and then performs a demosaicing operation, interpolating the original grayscale value of each pixel according to the pixel arrangement rules of even-numbered and odd-numbered rows. , , Three independent components, traversing the coordinates in the image ,in and Extract the red channel values ​​at the corresponding positions. Green channel values and blue channel values For those located at coordinates The pixels in the central region of the lens were read, and their values ​​were respectively... , , For those located at coordinates The pixels in the edge region of the lens were read, and their values ​​were respectively , , The pixel's three channel values ​​are stored into three independent two-dimensional arrays in row-major order. Channel alignment is performed, and the dimensions of the three two-dimensional arrays are checked to ensure they are strictly consistent. The three two-dimensional arrays are then stacked and rearranged along the depth direction to construct a dimensionless array. The three-dimensional tensor structure is used to generate pixel channel numerical matrices.

[0027] S102: Based on the pixel channel value matrix, determine the channel weight coefficients according to the distribution relationship of pixel channel values, perform pixel-by-pixel weighting on the red channel values, green channel values, and blue channel values, map them into a single-channel pixel index structure and verify the index consistency, and generate a grayscale pixel value matrix. Based on the pixel channel value matrix, statistical functions are used to calculate the standard deviation of pixel values ​​in the red, green, and blue channel planes respectively. Let the standard deviation of the red channel be denoted as... The standard deviation of the green channel is The standard deviation of the blue channel is The formula for calculating channel weights is set as follows: ; in This formula uses standard deviation to measure the information richness of a channel. A larger standard deviation indicates a stronger contrast between the lens edge and the background in that channel, thus assigning it a higher weight. If the calculation yields... , , The total standard deviation is Then calculate the weight coefficient of the red channel. Green channel weighting coefficient Blue channel weighting coefficient Select a local area at the edge of the lens Neighborhood pixel data is used as an example, as shown in Table 1, with the center pixel as the reference. coordinates For example, read its Value , Value , Value Substitute into the weighted formula The calculation process is as follows: Round down to obtain the grayscale value. Similarly, for Table 1... Point calculation yields grayscale value , Point to obtain grayscale value , Point to obtain grayscale value , Point to obtain grayscale value The calculated grayscale values ​​are mapped back to the corresponding two-dimensional coordinate indices. In the middle, and verify whether each generated grayscale value is in the middle. The system checks for overlaps or omissions in the range and coordinate indices, and generates a grayscale pixel value matrix.

[0028] Table 1: Pixel Channel Values ​​and Weighting Results for Local Areas at Lens Edge

[0029] As shown in Table 1, the table lists the pixel values. Centered The original channel values ​​within the neighborhood and the grayscale results after dynamic weighting calculation reflect the grayscale jump phenomenon at the lens edge.

[0030] S103: Based on the grayscale pixel value matrix, construct the pixel neighborhood Laplacian operator convolution relationship, perform second-order spatial difference operation on the pixel index, obtain the Laplacian response value and judge the neighborhood change, aggregate the corresponding pixel spatial coordinates, and establish the edge pixel coordinate set.

[0031] Based on the grayscale pixel value matrix, define the template for the second-order differential Laplacian operator: ; The parameters in this operator formula include the center pixel weight. And the weights of the four orthogonal adjacent pixels: top, bottom, left, and right. The formula is expressed as The logic behind using the discrete Laplacian operator for convolution here lies in capturing regions of drastic grayscale changes in the image by calculating the difference between the mean grayscale values ​​of the center pixel and its four neighboring pixels. This operation is sensitive to the second derivative passing through intersection points, enabling precise edge location. The grayscale values ​​calculated in Table 1 are then substituted into the formula for actual calculation. Using a point as the center, substitute its four neighboring pixels. , , , and center pixel The calculation formula is: The detailed derivation is as follows , , ,as well as Finally, the Laplace response value was obtained. Set edge detection threshold This threshold is obtained by calculating the gray-level variance of the background region, and the upper left corner of the image is selected. For a pure background region, calculate the root mean square error (RMSE) of the grayscale values ​​in that region. ,Pick Using RMSE as a threshold, i.e., setting The calculated response values With threshold Perform absolute value comparison and execute the judgment logic. If the result is determined to be true, this result indicates that the current pixel is... The grayscale change rate at this location is significantly higher than the background noise level, indicating it is a valid pixel on the lens edge. The spatial coordinates of this pixel are then extracted. The edge coordinates are stored in a dynamic array, and the convolution and judgment process is repeated throughout the entire image to establish a set of edge pixel coordinates.

[0032] Please see Figure 3 The specific steps of S2 are as follows: S201: Based on the set of edge pixel coordinates, retrieve the grayscale pixel value corresponding to the pixel coordinates and locate the coordinates of the eight adjacent pixels. Extract the corresponding grayscale value according to the spatial adjacency relationship. Perform difference operation and absolute value transformation on the grayscale value of the center pixel and the adjacent grayscale values ​​to generate a set of absolute values ​​of grayscale difference in the pixel neighborhood. Based on the set of edge pixel coordinates, the program first iterates through the spatial coordinates of each edge pixel to be detected stored in the set to determine the center pixel point. For example, its coordinate index is By directly accessing the grayscale pixel value matrix through a memory pointer, the grayscale value at that coordinate can be read. Then define an eight-neighbor offset array: ; Add the offset to the center coordinates sequentially. The coordinates of the eight adjacent pixels are used to locate the top left corner. Directly above Top right corner Directly to the left Directly to the right Bottom left corner Directly below and the bottom right corner Before reading, the coordinate boundary conditions need to be verified to ensure... and All in image size Within the range, read the grayscale data corresponding to the above coordinates, respectively. , , , , , , , Next, the absolute value of the difference between the center pixel and its neighboring pixels is calculated using the following formula: ,in and The specific calculation process is as follows: , , , , , , , This operation transforms the directional gray-level gradient into a scalar form of difference intensity, encapsulates the eight calculated values ​​in neighborhood order, and constructs a set of absolute gray-level differences in the neighborhood of the corresponding center pixel. This set quantifies the degree of grayscale abrupt change of the current pixel in different directions, and generates a set of absolute values ​​of grayscale differences in the pixel neighborhood.

[0033] S202: Based on the set of absolute values ​​of grayscale differences in the neighborhood of pixels, for multiple absolute values ​​of grayscale differences under the same pixel coordinate, compare them one by one with the noise intensity threshold. Pixel coordinates that are greater than the threshold are determined to be valid, and an edge candidate pixel determination mapping table is generated. Based on the set of absolute values ​​of gray-level differences in the pixel neighborhood, a dynamic threshold that can distinguish between background noise and real edges needs to be determined. Therefore, the noise intensity threshold calculation formula is introduced: ; In the formula Represents a random sample within the current image frame. A sample set of absolute values ​​of gray-level differences in the neighborhood of each pixel. The median function is used to characterize the baseline level of background noise, avoiding extreme value interference. The sample arithmetic mean is given by the square root term, and the standard deviation of the sample is given by the square root term. Used to reflect the degree of dispersion and fluctuation in data. The coefficients are linear combinations. The advantage of this formula lies in combining the robustness of the median with the volatility sensitivity of the standard deviation to construct an adaptive threshold that dynamically adjusts with the overall signal-to-noise ratio of the image. This allows for the suppression of minor gray-level fluctuations in smooth regions while preserving high-contrast edge signals, selecting representative values ​​from the image. A sample set is constructed from data points. A practical example is demonstrated, and detailed data is shown in Table 2. First, the data recorded in Table 2... The sequence is obtained by sorting the absolute values ​​of the grayscale differences in ascending order. Sequence length The median is taken as the th and the The average of the terms, i.e. Calculate the arithmetic mean Next, calculate the sum of squared deviations of the multiple terms from the mean. ,For example , The sum of squared total deviations is approximately Calculate the standard deviation Set linear combination coefficients Then the noise intensity threshold Round down Then the collection The values ​​within are compared one by one with the threshold. The comparison and judgment process is as follows: (invalid), (efficient), (invalid), (Valid) This result indicates that there are gradient changes in the set that are higher than the background noise level. Statistical comparison results show that index positions greater than a threshold are marked as... Those less than or equal to the threshold are marked as The binarized sequence is obtained. Generate an edge candidate pixel determination mapping table.

[0034] Table 2: Sample Statistics of Absolute Values ​​of Gray-Level Differences in Local Image Regions

[0035] As shown in Table 2, this table lists some of the sampled data used to calculate statistical characteristics, covering the typical numerical distributions of low-frequency background noise and high-frequency edge signals.

[0036] S203: Based on the edge candidate pixel determination mapping table, perform logical merging on the valid determination states of pixel coordinates, mark the pixel coordinates that are determined to be valid as edge valid states, and mark the pixel coordinates that do not meet the requirements as non-edge states, and generate edge validity marking results; Based on the edge candidate pixel determination mapping table, the program determines the center pixel. The edge attributes are used for final adjudication, and the binarized sequence in the judgment mapping table is called. Perform a logical merge operation, setting the merge logic rule as follows: if there are at least The number is If the item is specified, then the pixel is considered a valid edge; this is set here. The aim is to eliminate isolated high responses caused by single-point noise, for the sequence Perform summation operations and calculate The calculation result is compared with the threshold. If the condition is met, or if directional continuity logic is used, it checks whether there are spatially adjacent "1"s (e.g., indices 2 and 3 being 1 simultaneously represent continuous edges). In this example, indices 3 (corresponding to the upper right direction), 5 (corresponding to the right), and 8 (corresponding to the lower right direction) are all valid, showing continuous edge features in the right direction. The determination state is confirmed as "true," and then the pixel coordinates are... Marked in the result matrix as (White), if the summation result is less than For example, a sequence of pixels generated from a pure background region. Summation is Then it is marked as (Black) By traversing candidate pixels in the image and performing the above merging logic, discrete gradient responses are integrated into continuous edge contours, generating edge validity labeling results.

[0037] Please see Figure 4 The specific steps of S3 are as follows: S301: Call the edge validity marking result, locate the gray matrix index corresponding to the pixel coordinates marked as valid, use the Sobel gradient operator to calculate the horizontal and vertical gradient components for the index position, and perform direction mapping operation to generate a set of pixel gradient direction angles. First, parse the metadata in the tagging results and lock the tagged data. The index address of the valid edge pixels is used to calculate the confirmed edge points. For example, retrieve the data centered at that point from the memory buffer again. The grayscale matrix regions, whose values ​​are respectively in the first row The second line The third line Define the Sobel operator template for the horizontal direction: ; Sobel operator template in the vertical direction: ; This operator calculates gradient components by performing weighted differencing on the pixel neighborhood in different directions. The weights in the formula... To reduce the impact of smoothing noise, higher importance is given to the central neighborhood. To perform a convolution operation, first calculate the horizontal gradient components. Substitute the numerical values ​​into the calculation. The decomposition calculation items are as follows , , Summation yields Similarly, calculate the vertical gradient component. The operation formula is The calculation items are broken down into the first row. The third line Summation yields Then, the inverse trigonometric function is called to calculate the gradient direction angle, as shown in the formula. Substitute data ,calculate Given and The vector is located in the fourth quadrant and performs a full-circular direction mapping, converting the angle into a positive value. This angle precisely represents the direction of the most drastic change in pixel grayscale. This process is repeated for valid pixels to generate a set of pixel gradient direction angles.

[0038] S302: Based on the set of pixel gradient direction angles, obtain the set of light source incident angle parameters, perform angle difference calculation on the gradient direction angle and the light source incident angle under the same pixel coordinates, and perform interval mapping processing on the difference results to generate a gradient light source phase difference dataset. First, read the light source controller log at the time of image acquisition to obtain the light source incident angle parameters corresponding to the current frame. Assuming a time-division strobe ring light source is used, the LED sector triggered in the current frame is located at... Orientation (directly to the right), set the incident angle parameters of the light source. This parameter represents the theoretical direction that the edge gradient should present under ideal conditions. Then, the set of pixel gradient direction angles is traversed, for the aforementioned... Point calculation To perform angle difference calculation, the formula for calculating the phase difference of the gradient light source is introduced. The advantage of this formula is that it eliminates angular periodicity by calculating the shortest radian distance on the circumference. and The numerical discontinuity caused by overlap can accurately quantify the degree of deviation between the actual edge gradient and the expected light source direction. Substituting the values ​​into the calculation, the first absolute difference is... The second periodic supplementary angle is Take the minimum of the two, that is This indicates that the edge normal direction of this pixel is highly aligned with the direction of light illumination, which conforms to the physical characteristics of a high-reflectivity edge. Data from two other typical pixels were processed, as shown in Table 3. The gradient angle is Calculate the difference ,supplementary angle Take the minimum value Pixels The gradient angle is Calculate the difference Take the minimum value , calculate Value mapping to Within the interval, this dataset reflects the phase consistency of edge pixels relative to the light source direction, generating a gradient light source phase difference dataset.

[0039] Table 3: Calculation Table of Pixel Gradient Direction and Light Source Angle Phase Difference

[0040] As shown in Table 3, this table displays the phase difference calculation results under different gradient directions, where and The small phase difference suggests that it is a true edge excited by a light source at that angle. and A large phase difference corresponds to background texture or non-target edge.

[0041] S303: Based on the gradient light source phase difference dataset, logical judgment is performed on the consistency criteria between the phase difference value and direction corresponding to the pixel coordinates. The pixel coordinates that are judged to be consistent are extracted and indexed and aggregated. The aggregated pixel coordinates are structured and encoded to establish a set of lens edge feature pixels. Set a threshold for determining directional consistency The threshold value was set with reference to the distortion parameters of the industrial camera lens and the divergence angle of the light source. To tolerate minute angular deviations caused by manufacturing tolerances and uneven lighting, the program scans the phase difference values ​​in the dataset one by one, targeting the aforementioned pixels. of Execute logical judgment If the result is true, the pixel's orientation consistency is deemed acceptable, and the pixel index is retained; for the pixel... of Execute judgment If the result is false, it is determined to be stray light or a reverse edge, and is removed from the candidate set; for pixels... of Pixels that were also rejected were extracted; the coordinates of pixels judged as "true" were extracted, and the discrete coordinates were aggregated using the ChainCode algorithm, first locating the starting point. Then, search for the next matching pixel within its eight neighborhoods and record the movement direction code (e.g., ...). Represents moving to the right. (representing upward movement), forming a continuous edge trajectory data stream, for example, for a continuous edge... , encoded as The results show that the selected pixels are not only significant in grayscale, but also match the physical light source settings in terms of geometric optical features, thereby eliminating the false edge interference caused by scratches or dust and establishing a set of lens edge feature pixels.

[0042] Please see Figure 5 The specific steps of S4 are as follows: S401: Call the lens edge feature pixel set, read the gradient intensity value corresponding to the pixel coordinate, perform item-by-item comparison and judgment based on the numerical relationship between the gradient intensity value and the gradient threshold, filter and collect the pixel coordinates greater than the threshold, and form the effective pixel coordinate set of the gradient threshold. First, a temporary one-dimensional array buffer is initialized. The gradient intensity values ​​of candidate pixels are read one by one from the feature set. Assume the currently processed image region contains... The set of gradient intensity values ​​for a typical pixel sample is denoted as . The numerical values ​​reflect the drastic changes in grayscale of the pixels. A sorting operation is performed, using quicksort logic to arrange the set in descending order of numerical values, generating an ordered sequence. Set the preset sorting ratio parameter This parameter is determined based on an estimate of the approximate proportion of pixels at the lens edge in the field of view, with the aim of preserving the front edge. Strong gradient signals are used to eliminate weak texture interference, according to the formula Calculate the threshold cutoff position, where the total number of samples is... Calculations yielded Select the first element from the ordered sequence. The value of the bit is used as the dynamic gradient threshold, that is Then, this threshold is used to evaluate the original set. Perform a numerical comparison and judgment on each element in the table, starting with the first numerical value. Execution judgment The result is false, so it is marked as invalid; for the second value... Execution judgment If the result is true, retain the corresponding pixel coordinates; for numerical values... ,determination The result is true; regarding the numerical value ,determination The result is false; and so on, filtering out those that meet the criteria. The conditional pixels, in this example, are The corresponding five pixels are used, and the two-dimensional spatial coordinates corresponding to the gradient values ​​are extracted simultaneously from the original data structure. High-gradient, strong-edge pixels are aggregated into a new memory block to form the effective pixel coordinate set of the gradient threshold.

[0043] S402: Based on the effective pixel coordinate set of gradient threshold, extract the spatial location parameters of pixel coordinates, calculate the distance parameters between adjacent pixel coordinates, and perform logical judgment with the spatial continuity judgment rules. Then, associate and aggregate the pixel coordinates that meet the continuity relationship to obtain a spatially continuous pixel coordinate group. Iterate through each pixel coordinate in the set, establish a spatial neighborhood search mechanism, and set a distance threshold for spatial continuity determination. This threshold represents the maximum straight-line distance (i.e., diagonally adjacent) between pixels in an eight-neighborhood structure, used to determine whether two pixels are physically connected. Three example points from the coordinate set are selected. , and To illustrate with a calculation example, we first calculate... and The Euclidean distance between them, substituting into the distance formula The calculation result is compared with the threshold, and a judgment is performed. The condition is met, indicating that and Spatial continuity exists, Into The connected component group it belongs to; then calculate and The distance between them Compare with the threshold and perform a judgment. If the condition is not met, a judgment will be made. For isolated points that are disconnected or belong to another edge, a breadth-first search (BFS) logic is used. Starting from the first valid seed point, neighboring pixels that meet the distance threshold condition are continuously absorbed until no new pixels can be added to the current group, thus completing the construction of an independent connected region. Then, the process is repeated to the next unvisited pixel. Finally, the scattered pixels are divided into several independent connected subsets, resulting in a spatially continuous pixel coordinate group.

[0044] S403: Based on the spatial continuous pixel coordinate group, obtain the position distribution parameters of the pixel coordinates in the two-dimensional coordinate system, calculate the relative position difference between pixel coordinates in the same coordinate group, and perform clustering judgment to group pixel coordinates with the same positional relationship into the same group to generate the lens edge pixel cluster.

[0045] Geometric feature analysis is performed on each individual connected group of pixels to distinguish between real lens edges and noise clusters, assuming that two main pixel groups are identified. and First, obtain the coordinates of the image center. Using the reference origin, calculate the radial distance from the pixel within the group to this center. And count the number of pixels. Average radial distance and the standard deviation of radial distance The relevant calculation data are shown in Table 4. traverse its For each pixel, the standard deviation of the radial distance is calculated as follows: ,for traverse its For each pixel, the standard deviation of the radial distance is calculated as follows: Set clustering criteria: if the number of pixels And the standard deviation of radial distance If the result is consistent with the geometric consistency of the edge of a circular lens, then the group is determined to meet the requirements. Execute judgment and If both conditions are met, the group is confirmed as a valid lens edge cluster; Regarding Execute judgment and If it is determined to be non-edge noise (such as dust or scratches), then it will meet the criteria. The pixel coordinates within the array are finally aggregated and labeled, assigned a unified cluster ID, and a pixel cluster at the edge of the lens is generated.

[0046] Table 4: Statistical Table of Geometric Features of Spatially Continuous Pixel Groups

[0047] Table 4 shows the statistical characteristics of different connected sets. and Because of its high pixel density and low geometric dispersion, it is identified as a valid edge, while and It was rejected because it did not conform to the geometric distribution characteristics.

[0048] Please see Figure 6 The specific steps of S5 are as follows: S501: Based on the pixel clusters at the edge of the lens, analyze the distribution data of pixel coordinates in the two-dimensional coordinate system, arrange the pixel coordinates in order according to the spatial adjacency relationship, calculate the curve direction parameters based on the changes in the positions of adjacent coordinates, and generate the coordinate set of control points for the edge curve. First, a local coordinate system index is established for each individual pixel cluster, based on the previously identified main edge pixel clusters. For example, including For a set of discrete pixels, their disordered spatial distribution needs to be transformed into an ordered geometric sequence. First, a polar coordinate transformation is performed, with the centroid of the cluster as the reference point. Using the origin as the starting point, calculate the value for each pixel. polar angle The pixel set is then sorted clockwise according to the polar angle to obtain an ordered pixel chain. Then, the curve control point extraction operation is performed, and the sampling step size parameter is set. This parameter is set based on the ratio of the lens edge curvature radius to the pixel resolution, aiming to reduce data redundancy and smooth out minor jagged edges. Every [percentage missing] Extract one key point per pixel to generate the initial set of control points. For example, extracting three consecutive control points , , Next, the curve orientation parameters between adjacent control points are calculated, and the orientation vector is defined. Calculate the above coordinates , And further calculate the magnitude of the vector. and direction angle ,for , module length ,for , module length The parameters describe the extension trend and geometric shape of the edge within a local range. The calculated spatial coordinates, tangential vectors and curvature estimates are encapsulated in a data structure to generate a set of coordinates of the control points of the edge curve.

[0049] S502: Based on the coordinate set of control points of the edge curve, extract the spatial positional relationship parameters between adjacent control points, perform a judgment on the consistency of the connection direction between control points, filter the connectable control point pairs according to the correspondence of endpoints, and construct a set of continuous edge curve segments; Further verification of the connection logic between control points is needed to eliminate abnormal abrupt changes. Adjacent control point pairs should be read from the control point coordinate set of the edge curve. The spatial relationship parameters are examined, with a focus on the consistency of the connection direction. A formula for determining directional consistency is introduced: ; This formula quantifies the smoothness of a curve by calculating the cosine similarity of adjacent directional vectors, and sets a smoothness threshold. This threshold corresponds to approximately The angle deflection tolerance is used to ensure a smooth transition characteristic at the lens edge. Substituting the aforementioned data... , Perform calculations, dot product Modulus product Calculate similarity The result is compared with the threshold to determine... The result is true, indicating that , , The connections between them conform to the continuity requirement of the lens's physical contour, and they are marked as the same continuous segment. If any abnormal points are encountered... Cause the next vector If the similarity between the vector and the previous vector is significantly lower than the threshold, it is determined to be a breakpoint. The specific screening data is shown in Table 5. Based on the judgment results, the control point pairs that meet the connection conditions are sequentially connected to construct a set of continuous edge curve segments.

[0050] Table 5: Data Table for Determining Consistency of Control Point Connection Direction

[0051] As shown in Table 5, this table records the vector characteristics and consistency analysis results between control points, where... Because of cosine value Below the threshold It was identified as a discontinuous mutation, causing the curve to segment at this point.

[0052] S503: Based on a set of continuous edge curve segments, extract the start and end position parameters of the curve segments in a unified coordinate system, perform matching judgment on the coordinates of the endpoints of adjacent curve segments, and perform sequential splicing calculations based on the relationship of endpoint overlap and direction consistency to establish the complete edge contour of the lens. To repair and stitch together broken curves caused by occlusion, uneven lighting, or algorithm segmentation, the start and end coordinates of the curve segments in the set are first extracted. It is assumed that there are two curve segments to be stitched together. and ,in The endpoint is The tangential direction angle at that point is , The starting endpoint is The tangential direction angle is Perform a matching judgment of the coordinates of the endpoints of adjacent curve segments and set a threshold for the distance between the endpoints. Pixel and orientation deviation threshold First, calculate the Euclidean distance between the endpoints. Execute judgment If the distance condition is met, then calculate the direction angle deviation. Execute judgment If the directional conditions are met, it is confirmed that the two curve segments belong to the break at the same physical edge. Then, the cubic spline interpolation algorithm is called to generate a list of connection points. Fill the gap, Interpolation segment Merge them into a complete connected component; for isolated curve segments that cannot be matched (such as those more than [number] from the nearest neighbor), The noise segment of the pixel is removed as an artifact, and the merged coordinate sequence is reindexed in a clockwise direction to establish the complete edge contour of the lens.

[0053] Please see Figure 7 A lens edge detection system based on image generation includes: The image grayscale generation module acquires the original image of the lens through an industrial camera, converts the red, green and blue channel values ​​of the pixels into grayscale according to weight coefficients, inputs the grayscale values ​​into the Laplacian operator to extract the edge region, and constructs a set of edge pixel coordinates. The edge response construction module calculates the absolute value of the grayscale difference between each pixel and its eight neighboring pixels based on the set of edge pixel coordinates, compares it with the noise intensity threshold to mark valid edge pixels, and generates edge validity marking results. The orientation consistency filtering module calls the edge validity labeling result as input to the Sobel gradient operator to calculate the gradient direction angle, calculates the phase difference based on the incident angle of the light source and the gradient direction angle, and filters pixels whose gradient direction is consistent with the incident direction of the light source based on the phase difference to construct a set of lens edge feature pixels; The edge pixel clustering module calls the set of feature pixels on the lens edge, filters pixels with gradient strength greater than the gradient threshold and spatial continuity, and clusters them according to their coordinate positions to generate lens edge pixel clusters. The contour fitting and generation module performs edge contour fitting based on the pixel clusters at the edge of the lens. It calculates the coordinates of the curve control points according to the spatial distribution characteristics of the pixel clusters, and connects the fitted curve segments end to end according to the principle of continuity to construct the complete edge contour of the lens.

[0054] The above description is merely a specific embodiment of the present invention, but the scope of protection of the present invention is not limited thereto. Any variations or substitutions that can be easily conceived by those skilled in the art within the technical scope disclosed in the present invention should be included within the scope of protection of the present invention. Therefore, the scope of protection of the present invention should be determined by the scope of the claims.

Claims

1. A lens edge detection method based on image generation, characterized in that, Includes the following steps: S1: Obtain the original image of the lens through an industrial camera, convert the red, green and blue channel values ​​of the pixels to grayscale according to the weight coefficients, input the grayscale values ​​into the Laplacian operator to extract the edge region, and construct a set of edge pixel coordinates; The specific steps of S1 are as follows: S101: Acquires the original image of the lens through an industrial camera, collects sensor array data frames, retrieves the red channel value, green channel value, and blue channel value of the pixel, performs channel alignment and matrix rearrangement according to the pixel index, and generates a pixel channel value matrix. S102: Based on the pixel channel value matrix, determine the channel weight coefficients according to the pixel channel value distribution relationship, perform pixel-by-pixel weighting on the red channel value, green channel value, and blue channel value, map them into a single-channel pixel index structure and verify the index consistency, and generate a grayscale pixel value matrix. S103: Based on the grayscale pixel value matrix, construct the pixel neighborhood Laplacian operator convolution relationship, perform second-order spatial difference operation on the pixel index, obtain the Laplacian response value and perform neighborhood change judgment, aggregate the corresponding pixel spatial coordinates, and establish an edge pixel coordinate set. S2: Calculate the absolute value of the gray level difference between each pixel and its eight neighboring pixels based on the set of edge pixel coordinates, compare it with the noise intensity threshold to mark valid edge pixels, and generate edge validity marking results; The specific steps of S2 are as follows: S201: Based on the set of edge pixel coordinates, retrieve the grayscale pixel value corresponding to the pixel coordinate and locate the coordinates of eight adjacent pixels. Extract the corresponding grayscale value according to the spatial adjacency relationship. Perform difference operation and absolute value transformation on the grayscale value of the center pixel and the adjacent grayscale values ​​to generate a set of absolute values ​​of grayscale difference in the pixel neighborhood. S202: Based on the set of absolute values ​​of grayscale differences in the pixel neighborhood, for multiple absolute values ​​of grayscale differences under the same pixel coordinate, compare them one by one with the noise intensity threshold. Pixel coordinates that are greater than the threshold are determined to be valid, and an edge candidate pixel determination mapping table is generated. The noise intensity threshold is statistically determined based on the set of absolute values ​​of gray-level differences in the pixel neighborhood. Specifically, for the set of absolute values ​​of gray-level differences in the pixel neighborhood corresponding to all pixel coordinates within the same image frame, the numerical distribution is extracted and statistical features are calculated. The noise intensity threshold is the value obtained by linear combination of the median and standard deviation in the statistical features. S203: Based on the edge candidate pixel determination mapping table, perform logical merging on the valid determination states of pixel coordinates, mark the pixel coordinates that are determined to be valid as edge valid states, and mark the pixel coordinates that do not meet the requirements as non-edge states, and generate edge validity marking results; S3: Call the edge validity marking result to input the Sobel gradient operator to calculate the gradient direction angle, calculate the phase difference based on the incident angle of the light source and the gradient direction angle, and filter the pixel points whose gradient direction is consistent with the incident direction of the light source based on the phase difference to construct the lens edge feature pixel set; The specific steps for S3 are as follows: S301: Call the edge validity marking result, locate the gray matrix index corresponding to the pixel coordinates marked as valid, use the Sobel gradient operator to calculate the horizontal and vertical gradient components for the index position, and perform direction mapping operation to generate a set of pixel gradient direction angles. S302: Based on the set of pixel gradient direction angles, obtain the set of light source incident angle parameters, perform angle difference calculation on the gradient direction angle and the light source incident angle under the same pixel coordinates, and perform interval mapping processing on the difference results to generate a gradient light source phase difference dataset. S303: Based on the gradient light source phase difference dataset, perform logical judgment on the consistency judgment criteria between the phase difference value and direction corresponding to the pixel coordinates, extract the pixel coordinates that are judged to be consistent and perform index aggregation, perform structured encoding on the aggregated pixel coordinates, and establish a set of lens edge feature pixels. S4: Call the set of feature pixels at the edge of the lens, filter pixels with gradient intensity greater than the gradient threshold and spatial continuity, and cluster them according to their coordinate positions to generate a cluster of pixels at the edge of the lens. S5: Perform edge contour fitting based on the pixel clusters at the edge of the lens, calculate the coordinates of the curve control points according to the spatial distribution characteristics of the pixel clusters, connect the fitted curve segments end to end according to the principle of continuity, and construct the complete edge contour of the lens.

2. The lens edge detection method based on image generation according to claim 1, characterized in that, The set of edge pixel coordinates includes the spatial location of edge points, the edge distribution range, and the grayscale gradient magnitude. The edge validity labeling result includes the valid edge category, noise suppression status, and edge confidence. The set of lens edge feature pixels includes gradient direction consistency features, phase difference features, and edge direction stability features. The lens edge pixel cluster includes spatially continuous regions, local edge structure units, and high gradient regions. The complete edge contour of the lens specifically includes the overall contour shape, boundary continuity characteristics, and contour curvature distribution.

3. The lens edge detection method based on image generation according to claim 1, characterized in that, The specific steps of S4 are as follows: S401: Call the set of feature pixels at the edge of the lens, read the gradient intensity value corresponding to the pixel coordinate, perform item-by-item comparison and judgment based on the numerical relationship between the gradient intensity value and the gradient threshold, filter and collect the pixel coordinates that are greater than the threshold, and form a set of effective pixel coordinates for the gradient threshold. S402: Based on the effective pixel coordinate set of the gradient threshold, extract the spatial position parameters of the pixel coordinates, calculate the distance parameters between adjacent pixel coordinates, and perform logical judgment with the spatial continuity determination rules to associate and aggregate the pixel coordinates that meet the continuity relationship to obtain a spatially continuous pixel coordinate group. S403: Based on the spatial continuous pixel coordinate group, obtain the position distribution parameters of the pixel coordinates in the two-dimensional coordinate system, calculate the relative position difference between pixel coordinates in the same coordinate group, and perform clustering determination to group pixel coordinates with consistent positional relationships into the same group to generate a lens edge pixel cluster.

4. The lens edge detection method based on image generation according to claim 3, characterized in that, The gradient threshold is based on the gradient intensity values ​​corresponding to the coordinates of all pixels in the set of feature pixels at the edge of the lens. After sorting the gradient intensity values ​​according to their magnitude, the gradient intensity value at the preset sorting ratio position is selected as the fixed threshold.

5. The lens edge detection method based on image generation according to claim 3, characterized in that, The specific steps of S5 are as follows: S501: Based on the pixel clusters at the edge of the lens, analyze the distribution data of pixel coordinates in the two-dimensional coordinate system, arrange the pixel coordinates in order according to the spatial adjacency relationship, calculate the curve direction parameters based on the changes in the positions of adjacent coordinates, and generate a set of coordinates for edge curve control points. S502: Based on the coordinate set of control points of the edge curve, extract the spatial positional relationship parameters between adjacent control points, perform a judgment on the consistency of the connection direction between control points, filter the connectable control point pairs according to the endpoint correspondence, and construct a set of continuous edge curve segments; S503: Based on the set of continuous edge curve segments, extract the start and end position parameters of the curve segments in a unified coordinate system, perform matching judgment on the coordinates of the endpoints of adjacent curve segments, and perform sequential splicing calculation based on the relationship of endpoint overlap and direction consistency to establish the complete edge contour of the lens.

6. A lens edge detection system based on image generation, characterized in that, The system is used to implement the image-generated lens edge detection method according to any one of claims 1-5, the system comprising: The image grayscale generation module acquires the original image of the lens through an industrial camera, converts the red, green and blue channel values ​​of the pixels into grayscale according to weight coefficients, inputs the grayscale values ​​into the Laplacian operator to extract the edge region, and constructs a set of edge pixel coordinates. The edge response construction module calculates the absolute value of the grayscale difference between each pixel and its eight neighboring pixels based on the set of edge pixel coordinates, compares it with the noise intensity threshold to mark valid edge pixels, and generates edge validity marking results. The direction consistency filtering module calls the edge validity labeling result as input to the Sobel gradient operator to calculate the gradient direction angle, calculates the phase difference based on the incident angle of the light source and the gradient direction angle, and filters pixels whose gradient direction is consistent with the incident direction of the light source based on the phase difference to construct a set of lens edge feature pixels; The edge pixel clustering module calls the set of feature pixels on the lens edge, filters pixels with gradient intensity greater than the gradient threshold and spatial continuity, and clusters them according to their coordinate positions to generate lens edge pixel clusters; the contour fitting generation module performs edge contour fitting based on the lens edge pixel clusters, calculates the coordinates of curve control points according to the spatial distribution characteristics of the pixel clusters, and connects the fitted curve segments end to end according to the principle of continuity to construct the complete edge contour of the lens.

Citation Information

Patent Citations

  • Automatic typesetting and drawing method and system for lens laser cutting

    CN119918423A

  • Feature point detection method based on edge saliency and scale sensitivity

    CN120953244A