A method and apparatus for high-precision focusing of part images based on improved gradient weighting

CN117252915BActive Publication Date: 2026-08-11JIANGSU UNIV OF TECH
View PDF 3 Cites 0 Cited by

Patent Information

Authority / Receiving Office
CN · China
Patent Type
Patents(China)
Current Assignee / Owner
Filing Date
2023-10-08
Publication Date
2026-08-11

AI Technical Summary

Technical Problem

[0010]本发明针对环形光源照射下的零件图像易出现倒角特征成像存在宽边缘,手动调焦缺乏相机聚焦的客观性而导致图像聚焦不精确等问题,提供一种基于改进梯度加权的零件图像高精度聚焦方法及装置,通过优化光照方式采集序列“离焦-聚焦”零件图像,应用改进梯度加权的聚焦评价函数完成图像清晰度评价,获取精确聚焦图像,从而实现零件高精度尺寸测量

Benefits of technology

[0064]本发明能够高精度准确聚焦最清晰零件图像,相较于Tenengrad函数、Brenner函数、Roberts能量函数、平方梯度函数、绝对梯度函数、曾海飞等于2021年提出的Improved-Tenengrad函数和潘宏亮等于2023年提出的Proposed-Tenengrad函数,改进梯度加权的聚焦评价函数清晰度比率平均提升7512.4%,灵敏度因子平均提升503.7%,陡峭度平均提升106.0%,具有更高的灵敏度、更强的抗噪性和更好的稳定性。

✦ Generated by Eureka AI based on patent content.

Smart Images

  • Figure CN117252915B_ABST
    Figure CN117252915B_ABST
Patent Text Reader

Abstract

This invention discloses a high-precision focusing method and apparatus for part images based on improved gradient weighting. First, the Otsu adaptive segmentation threshold is improved to enhance edge extraction accuracy. Next, the gradient values ​​of edge pixels are obtained based on a 4-directional Sobel operator to improve gradient accuracy. Then, the pixel gradient weighting coefficients are obtained based on the difference in grayscale distribution between the edge pixel and its 8 neighboring pixels, enhancing the sensitivity and noise resistance of the gradient weighting algorithm. Finally, the image sharpness is evaluated by improving the gradient weighting focusing evaluation function, thereby improving the focusing accuracy of the part image. This invention effectively improves the accuracy of image focusing, which is of great significance for improving the accuracy of visual measurement of part dimensions.
Need to check novelty before this filing date? Find Prior Art

Description

Technical Field

[0001] This invention relates to a high-precision focusing method and apparatus for part images based on improved gradient weighting. Background Technology

[0002] Industrial parts are crucial components of automated equipment, typically featuring characteristics such as chamfers, rings, rectangles, and slots. The dimensional accuracy of these features directly impacts the equipment's lifespan and stability. Therefore, high-precision measurement of industrial parts is of paramount importance. Currently, vision measurement technology is widely used due to its high precision and efficiency. This method uses part images as the inspection object for dimensional measurement, employing pixel equivalents from a part calibration system to convert the pixel dimensions of the part image into actual dimensions. Acquiring high-quality images is beneficial for improving the accuracy of dimensional measurements. High-quality images can usually be obtained by optimizing the light source and improving image focusing accuracy. Using a ring-shaped light source illuminating vertically downwards results in wide edges in the imaging of chamfered features, hindering edge extraction. To optimize the lighting method, the optical simulation software TracePro is used for lighting simulation analysis, which efficiently and intuitively reflects the illuminance of the light source. Acquiring high-quality part images requires not only appropriate lighting to obtain accurate image edges but also precise focusing. Manual focusing lacks the objectivity of industrial camera focusing and cannot guarantee precisely focused part images; therefore, an ideal focus evaluation function is needed to evaluate image sharpness.

[0003] Illumination methods are generally divided into front illumination and back illumination. Front illumination can highlight the surface features and details of the object being measured, and is often used for surface defect detection. Back illumination can highlight the edge contour information of the object being measured, and is generally used for dimensional measurement. Since parts have diverse dimensions, and large-sized objects may be involved in the measurement process, it is necessary to stitch images together using surface feature point information. To ensure the versatility of illumination methods for dimensional measurement, front illumination is chosen after comprehensive consideration.

[0004] Patent CN201910935426.9 proposes a mask alignment device and a mask alignment method. The device uses a coaxial light source and a ring light source to illuminate and position the groove feature. This illumination method can effectively improve the accuracy of the positioning mark. However, the groove chamfer imaging effect has a wide edge, which is not suitable for size measurement.

[0005] Patent CN201911092164.0 proposes an illumination method, illumination structure and detection device for surface defect detection. It illuminates the surface of the object under test by a ring light source and sets a light blocking plate along the inner periphery of the ring light source, which effectively solves the problem of light reflection forming bright spots and makes the surface defects of the object under test clear images. However, this illumination method cannot accurately obtain the edge information of image features.

[0006] Image sharpness evaluation functions are typically based on spatial, frequency, and information entropy domains. Spatial domain-based functions primarily describe image sharpness through gray-level gradients; they are computationally simple and inexpensive, but lack robustness to noise. Frequency domain-based functions are computationally intensive, time-consuming, and sensitive to noise. Information entropy-based functions are greatly affected by illumination, exhibiting low sensitivity and noise robustness. Therefore, spatial domain-based gray-level gradient evaluation functions are generally widely used.

[0007] In 2018, Lü Meini et al. proposed a novel autofocus algorithm. This algorithm first sets a threshold to remove a large number of useless image sub-blocks to determine the focus window. Then, it calculates the gradient, variance, and pixel weights of the window sub-blocks as the focus evaluation function. This algorithm has advantages in noise resistance, sensitivity, and stability, and is typically used for feature-rich images. In 2021, Zeng Haifei et al. proposed an improved gradient threshold image sharpness evaluation algorithm. This algorithm extracts edge pixels from the entire image through adaptive segmentation thresholding and uses a multi-directional Tenengrad operator to perform image evaluation operations. It has strong noise resistance and improved stability compared to traditional algorithms. In 2023, Pan Hongliang et al. proposed an improved Tenengrad weighted image sharpness evaluation algorithm. This algorithm calculates the gradient of the image based on the multi-directional Sobel operator and weights the gradient by setting weighting coefficients. The algorithm's noise resistance and sensitivity are improved, but its adaptability is poor.

[0008] Patent CN201911232590.X proposes a method and apparatus for evaluating the sharpness of microscopic images. It creates an image evaluation model by selecting the product of at least two sharpness evaluation functions. This method can improve the sensitivity of the evaluation algorithm, but it depends on the performance of various selected evaluation functions and is not very stable.

[0009] To achieve high-precision measurement of part dimensions, improvements to the hardware and software algorithms of the vision measurement platform are necessary. On the hardware side, to address the issue of wide edges appearing in the imaging of chamfered features of parts under ring light illumination, it is necessary to optimize the light source and adopt an illumination method using strip light sources arranged at a 45° angle to obtain accurate image edges. On the software side, to address the problem of insufficient focus of the target image in traditional vision measurement processes, an improved gradient-weighted focus evaluation function is used to evaluate image sharpness, obtaining highly focused part images, thereby improving the accuracy of visual measurement of part dimensions. Summary of the Invention

[0010] This invention addresses the problems of wide edges in chamfered feature imaging and inaccurate image focusing caused by the lack of objectivity in camera focusing when manually adjusting the focus of part images under ring light source illumination. It provides a high-precision focusing method and device for part images based on improved gradient weighting. By optimizing the illumination method, a sequence of "defocus-focus" part images is acquired, and the improved gradient weighting focus evaluation function is applied to complete the image sharpness evaluation, thereby obtaining a precisely focused image and realizing high-precision dimensional measurement of parts.

[0011] The technical solutions adopted in this invention are as follows:

[0012] A high-precision focusing method for part images based on improved gradient weighting includes the following steps:

[0013] 1) Obtain a sequence of images showing the defocusing and focusing of the part, and extract the feature edge pixels of the images;

[0014] 2) Improve the Tenengrad gradient algorithm based on the 4-direction Sobel operator template to obtain the gradient values ​​of pixel points at the feature edges of the image;

[0015] 3) Improve the gradient weighting algorithm to obtain adaptive gradient weighting coefficients;

[0016] 4) Use gradient weighting coefficients to weight the gradient values ​​of image feature edge pixels, evaluate the image sharpness through the weighted gradient values, obtain a precisely focused part image, and realize high-precision dimensional measurement of the part.

[0017] Further, in step 1), image feature edge pixels are extracted by improving the Otsu adaptive segmentation threshold. The expression is:

[0018] ,

[0019] in: For pixels grayscale value, Image pixel size The threshold is the traditional Otsu adaptive segmentation threshold.

[0020] Furthermore, image feature edge pixels are extracted by improving the Otsu adaptive segmentation threshold. The specific process is as follows:

[0021] The characteristics of image feature edge pixels are analyzed using local gray-level variance analysis, with pixel values ​​as the basis. Centered on the pixel, a 3×3 window is used to calculate the local grayscale variance of that pixel. ;

[0022] Improve Otsu adaptive segmentation threshold As a filtering boundary for edge pixels of image features, and related to the local gray-level variance of pixels. Comparison, retaining effective pixels at image feature edges The specific formula is as follows:

[0023] ,

[0024] ,

[0025] in, This represents the local grayscale average value.

[0026] Furthermore, in step 2), the 4-direction Sobel operator template is:

[0027] ,

[0028] ,

[0029] ,

[0030] ,

[0031] in, , , , Templates for horizontal, 45°, vertical, and 135° directions are used respectively. The gradient of the pixel is obtained by convolution of the templates with Sobel operators in four directions.

[0032] Furthermore, the formula for calculating the gradient value of feature edge pixels is as follows:

[0033] ,

[0034] ,

[0035] ,

[0036] ,

[0037] ,

[0038] in, , , and These are the effective edge pixels. Gradient values ​​in the 0°, 45°, 90° and 135° directions, This is a convolution operation;

[0039] The gradients are calculated by convolving the image edge pixels with Sobel operator templates in four directions, and the squared gradient values ​​in the four directions are summed. As the overall gradient value of edge pixels.

[0040] Traditional gradient weighting algorithms typically obtain weighting coefficients based on the differences in gray values ​​within the four-neighborhood of pixels at image feature edges, considering only the horizontal and vertical directions in the image spatial domain, thus exhibiting limitations in terms of comprehensive neighborhood orientation. This invention improves the gradient weighting algorithm by proposing an improved algorithm based on the differences in gray-level distribution within an eight-neighborhood, effectively enhancing the accuracy and stability of gradient weighting coefficient acquisition. Specifically:

[0041] (31) Traverse and compare the gray values ​​of the 8-neighborhood of the effective edge pixels to obtain the maximum gray value. and minimum gray value It then uses the maximum and minimum gray values ​​as boundaries to determine the effective gray values ​​in the neighborhood, and filters out the maximum gray value. and a minimum gray value Eliminate the interference caused by noise points leading to abrupt changes in the grayscale values ​​of neighboring areas;

[0042] The optimal mean value of the neighborhood grayscale is obtained by averaging the effective grayscale values ​​of the selected neighborhood. The specific formula is as follows:

[0043] ,

[0044] in, The grayscale value of a pixel. For the set of 8 neighboring points, , These are the x and y coordinates of the 8-neighborhood points of the pixel.

[0045] To obtain the normalized gradient weighting coefficients, it is necessary to calculate the average gray value of the neighborhood and perform correlation analysis between the pixel and its neighborhood. Considering that random salt-and-pepper noise may cause abrupt changes in the gray value of neighboring pixels, leading to misjudgments in sharpness evaluation, a method is proposed to select the optimal average gray value of the neighborhood. This method filters out the largest and smallest gray values ​​from the 8-neighborhood, thereby eliminating the interference of noise points. The optimal average is obtained by averaging the 6 effective gray values ​​selected from the neighborhood, ensuring the reliability of the neighborhood gray value average.

[0046] Traditional gray-level gradient evaluation functions suffer from poor sensitivity and are susceptible to noise interference. Gradient weighting algorithms can improve the sensitivity, noise resistance, and stability of these functions. To adaptively obtain gradient weighting coefficients, the correlation between the gray values ​​of image feature edge pixels and their 8-neighbor pixels is analyzed. When the gray value of an effective edge pixel differs significantly from the average gray value of its neighboring pixels, the correlation is low, and the gradient weight of that pixel is large; conversely, when the difference is small, the correlation is high, and the gradient weight of that pixel is small. By weighting the gradient values ​​of image feature edge pixels using the derived adaptive gradient weighting coefficients, the sensitivity and noise resistance of the evaluation function can be effectively improved. Specifically:

[0047] (32) Obtain the gradient weighting coefficient by the correlation between the effective edge pixel and the optimal mean gray level of its neighborhood. A large difference in grayscale values ​​between the two indicates a low correlation and a high gradient weight. The specific formula is as follows:

[0048] ,

[0049] in, The grayscale value of a pixel. It is the optimal mean of the neighborhood gray level.

[0050] Furthermore, step 4) specifically includes:

[0051] (41) Using gradient weighting coefficients The gradient values ​​at image edges are weighted using the following formula:

[0052] ,

[0053] in, This is an evaluation value for image sharpness. These are the gradient weighting coefficients. , , and These are the effective edge pixels. Gradient values ​​in the 0°, 45°, 90° and 135° directions;

[0054] (42) The sharpness evaluation of sequential part images is completed by improving the focusing evaluation function of the gradient weighting algorithm;

[0055] (43) Normalize the sharpness values ​​of the sequence images and use MATLAB to plot the focus characteristic curves;

[0056] (44) Select the maximum image clarity value in the focusing characteristic curve, find the corresponding part image, move the industrial camera to the corresponding shooting position, and realize the focusing of the part image and high-precision dimension measurement.

[0057] Furthermore, step (43) specifically includes:

[0058] The normalized sharpness value is obtained by proportionally calculating the sharpness values ​​of all images to the maximum sharpness value of the focused image. The specific formula is as follows:

[0059] ,

[0060] in, To focus on the image with the highest sharpness, They are respectively A sequence of image sharpness values.

[0061] This invention also discloses a high-precision focusing device for part images based on improved gradient weighting, including an experimental platform, a stage, a Z-axis slide, an industrial camera, a lens, a light source, a part, and a support. The Z-axis slide and the support are both fixed on the experimental platform. The industrial camera is set at the free end of the Z-axis slide and can move vertically through the Z-axis slide. The lens is set on the industrial camera. The stage is horizontally placed below the lens. The part is placed on the stage. The light source is fixed on the support. The height of the light source from the experimental platform is 100mm, the horizontal distance of the light source from the part is 100mm, and the angle between the light-emitting surface of the light source and the upper surface of the part is 45 degrees.

[0062] Furthermore, the Z-axis slide drives the industrial camera to move, so that the industrial camera changes the working distance between the industrial camera and the surface of the part in 1 mm steps to acquire sequential images of the part in a defocus-focus sequence.

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

[0064] This invention can accurately focus on the clearest part image with high precision. Compared with the Tenengrad function, Brenner function, Roberts energy function, square gradient function, absolute gradient function, Improved-Tenengrad function proposed by Zeng Haifei et al. in 2021 and Proposed-Tenengrad function proposed by Pan Hongliang et al. in 2023, the improved gradient-weighted focusing evaluation function improves the sharpness ratio by an average of 7512.4%, the sensitivity factor by an average of 503.7%, and the steepness by an average of 106.0%, exhibiting higher sensitivity, stronger noise resistance, and better stability.

[0065] The method of this invention, which uses focused part images, achieves high-precision dimensional measurement. Compared to the improved Zernike moment sub-pixel circular hole measurement method proposed by Liu Liping et al. in 2023, the dimensional accuracy is higher, with a relative error of less than 0.0024% compared to manual measurements. The experimental acquisition device uses a strip light source arranged at a 45° angle for illumination, effectively eliminating the wide edges of chamfer features in the image and obtaining accurate image edges. Attached Figure Description

[0066] Figure 1 A schematic diagram of the experimental acquisition device for a sequence of "defocus-focus" part images.

[0067] Figure 2 This is a flowchart illustrating the specific implementation of a high-precision focusing method for part images based on improved gradient weighting.

[0068] Figure 3 A flowchart illustrating the specific implementation of part dimension measurement.

[0069] Figure 4a This is an illuminance diagram of the upper surface of the gauge block under ring light source illumination.

[0070] Figure 4b This is an illuminance diagram of the chamfered surface of a gauge block under ring light source illumination.

[0071] Figure 4c Illumination diagram of the upper surface of the gauge block under illumination by a bar light source arranged at a 45-degree angle.

[0072] Figure 4d Illumination diagram of the chamfered surface of the gauge block under illumination by a bar light source arranged at a 45-degree angle.

[0073] Figure 5a This is an image showing the actual imaging effect of the gauge block under ring light source illumination.

[0074] Figure 5b The actual imaging effect of the gauge block under illumination by a bar light source arranged at a 45-degree angle.

[0075] Figure 6a This is a defocused image of the gauge blocks.

[0076] Figure 6b Focus the image for the volume block.

[0077] Figure 7 The image shows the focus characteristic curves for evaluating the sharpness of 25 part sequence images using the Tenengrad function, Brenner function, Roberts energy function, squared gradient function, absolute gradient function, Improved-Tenengrad function, Proposed-Tenengrad function, and the Weighted-Gradient function of this invention, respectively.

[0078] Figure 8a for Figure 7 The focus characteristic curves of 25 part sequence images with added 3000 salt-and-pepper noise are evaluated using 8 focus evaluation functions.

[0079] Figure 8b for Figure 7 The focus characteristic curves of 25 part sequence images with added salt-and-pepper noise using 8 focus evaluation functions are shown.

[0080] Figure 8c for Figure 7 The focus characteristic curves of 25 part sequence images with added Gaussian noise of variance 3, evaluated by eight focus evaluation functions.

[0081] Figure 8d for Figure 7 The focus characteristic curves of 25 part sequence images with added Gaussian noise of variance of 5, evaluated by 8 focus evaluation functions. Detailed Implementation

[0082] The invention will now be further described with reference to the accompanying drawings.

[0083] like Figure 1 To achieve high-precision focusing of part images and high-precision measurement of part dimensions, this invention discloses a high-precision focusing device for part images, which includes an experimental platform 1, a stage 2, a Z-axis slide 3, an industrial camera 4, a lens 5, a light source 6, a part 7, a light source controller, a support, and a host computer.

[0084] Z-axis slide 3 is set on the experimental platform for the industrial camera 4 to move in the Z-axis direction (i.e., vertical direction). Part 7 is placed on the white background stage 2 directly below the lens 5. Light source 6 is fixed on stage 2 by a bracket. The height and angle of light source 6 are adjusted by the bracket. The light intensity of light source 6 is adjusted by the light source controller. The host computer communicates with the industrial camera 4 via serial port and manually controls the Z-axis movement slide 3 to change the working distance between the industrial camera 4 and part 7 in 1 mm increments to perform "defocus-focus" sequence image acquisition.

[0085] The support system includes a base plate 8 for the light source support, a connecting shaft 9, a connecting block 10, fixing bolts 11, and a light source fixing plate 12. The base plate 8 is placed on the experimental platform 1 and is used to fix the longitudinal connecting shaft 9. The connecting block 10 is fitted onto the longitudinal connecting shaft for height adjustment, and the fixing bolts 11 fix the height of the connecting block. One side of the transverse connecting shaft passes through the connecting block 10 for horizontal distance adjustment of the light source support, and the other side is fitted with the connecting block for fixing the light source fixing plate 12. The light source fixing plate 12 can be adjusted at any angle when fitted onto the connecting block, and the fixing bolts on the connecting block fix the angle of the light source fixing plate. The strip light source is fixed to the light source fixing plate by two fixing bolts.

[0086] Part 7 in this embodiment is used as the experimental object. This part is manufactured by SHAHE measuring instruments and has lateral dimensions of 20 mm and 30 mm, with an accuracy of 0.001 mm. In this embodiment, the 30 mm part is used as the system calibration object to obtain pixel equivalents; the 20 mm part is used as the dimensional measurement object to verify the dimensional measurement accuracy.

[0087] The industrial camera 4 is an imaging device that uses a lens to focus light onto an imaging plane to acquire an image. The quality of the captured part image directly affects the accuracy of dimensional measurement. The host computer sends an image acquisition command to the industrial camera 4. After the image acquisition card acquires the image captured by the industrial camera, it stores and processes the image on the host computer. In this embodiment, a Hikvision MV-CS200-10UM 20-megapixel monochrome area array CMOS industrial camera is selected, with a resolution of 5472×3648 and a sensor size of [missing information]. The longest side field of view is 32mm, and the maximum frame rate is 19.2fps.

[0088] Lens 5 is a crucial component of the image acquisition system, and its quality directly impacts the overall system performance. In this embodiment, a Dehong Vision M150-04XMPW dual telecentric lens is selected, with a target surface size... Magnification: 0.4, Depth of field: 5mm, Telecentricity: Optical distortion The working distance is 150 mm. The low distortion rate of the dual telecentric lens meets the requirements for high-precision measurement of part dimensions, and the field of view remains basically unchanged when the working distance between the industrial camera and the object being measured is changed for zoom image acquisition.

[0089] Choosing the ideal lighting method is crucial for high-quality image acquisition, and light source 6 is a key factor determining the accuracy of edge extraction for the part image. This embodiment uses a white background to effectively distinguish image feature edges from the background. To address the issue of wide edges in chamfered feature imaging when the ring light source illuminates vertically downwards, the lighting method is optimized by using a strip light source for forward illumination of the part. Light source 6 is a uniformly illuminated white LED strip light source with adjustable intensity. Light source 6 is fixed by a bracket, with its height set to 100 mm and its horizontal distance from part 7 set to 100 mm. The angle between the emitting surface of light source 6 and the upper surface of part 7 is changed in increments of 5°. The intensity of light source 6 is adjusted using a light source controller until the shadow at the boundary between part 7 and the background disappears. The imaging effect on the surface and chamfered surfaces of the gauge block is observed. When the angle between the emitting surface of light source 6 and the upper surface of part 7 is 45°, the image boundary of the gauge block is sharp, and the imaging effect is optimal.

[0090] The experimental data acquisition setup described above allows for the verification of light source optimization effects and high-precision image focusing methods. The flowchart for the image focusing method implementation is as follows: Figure 2 As shown, the flowchart for the part dimension measurement implementation is as follows: Figure 3 As shown, the specific implementation steps are as follows:

[0091] (1) Optimize the light source by using a strip light source with the light-emitting surface of the light source arranged at a 45° angle to the surface of the gauge block to eliminate the wide edge of the chamfer feature in the image.

[0092] (2) The working distance between the industrial camera and the surface of the gauge block is changed by 1 mm step using the Z-axis slide to acquire a sequence of "defocus-focus" gauge block images and record the corresponding shooting position of the industrial camera.

[0093] (3) Apply the improved Otsu adaptive segmentation threshold to extract image feature edge points.

[0094] The characteristics of image feature edge points are analyzed using local gray-level variance analysis, with pixels as the basis. Centered on, select Window calculation of the local grayscale variance of the pixel Improved adaptive threshold As a screening boundary for image feature edges, it is related to the local gray-level variance of pixels. Comparison, retaining valid edge pixels The specific formula is as follows:

[0095] ,

[0096] ,

[0097] ,

[0098] in, For pixels grayscale value, This represents the local grayscale average value. Image pixel size The threshold is the traditional Otsu adaptive segmentation threshold.

[0099] (4) Improve the Tenengrad gradient algorithm based on the 4-direction Sobel operator template to obtain the gradient values ​​of feature edge pixels. The specific formula is as follows:

[0100]

[0101] ,

[0102] ,

[0103] ,

[0104] ,

[0105] ,

[0106] ,

[0107] ,

[0108] ,

[0109] in, , , and These are the effective edge pixels. Gradient values ​​in the 0°, 45°, 90° and 135° directions, This is a convolution operation. The gradients are calculated by convolving the image edge pixels with Sobel operator templates in four directions, and then the squared gradient values ​​in the four directions are summed. As the overall gradient value of edge pixels.

[0110] (5) Based on the difference in grayscale distribution between the effective edge pixel and its 8 neighboring pixels, improve the gradient weighting algorithm and obtain the adaptive gradient weighting coefficient. Iterate through and compare the grayscale values ​​of the 8-neighborhood of the effective edge pixels to obtain the maximum grayscale value. and minimum gray value Using this as a boundary, the effective gray values ​​in the neighborhood are judged, and the largest gray value is filtered out. and a minimum gray value This eliminates interference from noise points causing abrupt changes in neighborhood grayscale values. The optimal mean grayscale value for the selected neighborhood is obtained by averaging the effective neighborhood grayscale values. This ensures the reliability of the neighborhood grayscale mean. The gradient weighting coefficient is obtained by calculating the correlation between effective edge pixels and their neighborhood optimal grayscale mean. A large difference in grayscale values ​​between the two indicates a low correlation and a high gradient weight. The specific formula is as follows:

[0111] ,

[0112] ,

[0113] in, The grayscale value of a pixel. For the set of 8 neighboring points, , These are the x and y coordinates of the 8-neighborhood points of the pixel.

[0114] (6) Use gradient weighting coefficients Gradient values ​​at image edges Weighted values ​​are used to obtain image sharpness evaluation values. The specific formula is as follows:

[0115] ,

[0116] in, , , , Templates for horizontal, 45°, vertical, and 135° directions, respectively. , , and These are the effective edge pixels. Gradient values ​​in the 0°, 45°, 90° and 135° directions.

[0117] (7) The image sharpness of the sequence block is evaluated by improving the focusing evaluation function of the gradient weighting algorithm.

[0118] (8) Normalize the sharpness values ​​of the sequence images and use MATLAB to plot the focus characteristic curves.

[0119] (9) Select the maximum image clarity value in the focusing characteristic curve, find the corresponding block image, use the Z-axis slide to move the industrial camera to the corresponding shooting position, and complete the focusing of the block image.

[0120] (10) Use Zernike moment subpixel edge detection to extract the edge pixels of the block from the focused image.

[0121] (11) Traverse the extracted image edge pixels, search and save the outermost pixel of the edge as the effective pixel, fit the edge line by least squares method, and take the average distance from 500 random points on one edge line to the other edge line as the pixel size of the block width.

[0122] (12) Obtain the calibrated value of pixel equivalent by calculating the ratio of the pixel size of the block width to the actual size.

[0123] (13) Use the same algorithm as in steps (10) and (11) above to obtain the pixel size of the part, and obtain the actual size through the calibrated pixel equivalent.

[0124] To verify the effectiveness of the light source optimization, an illuminance analysis is first needed for both vertical downward illumination from a ring light source and angular illumination from a strip light source. The illuminance of the upper surface and chamfered surface of the gauge block under these two lighting conditions is then analyzed and compared using TracePro lighting simulation software. Industrial cameras determine image brightness by receiving the amount of light reflected from the gauge block surface; the chamfer reflects less light into the camera's target surface. Therefore, although the chamfered surface is illuminated in the lighting simulation analysis, the actual image captured is dark.

[0125] The simulation results of surface illuminance and chamfer illuminance of the gauge block under ring light are as follows: Figure 4a , 4b As shown, the simulation results of the surface illuminance and chamfer illuminance of the gauge block under striped lighting are as follows: Figure 4c , 4d As shown, the actual imaging effects of the gauge blocks under ring light and stripe light are respectively as follows: Figure 5a and 5b As shown, the specific analysis is as follows:

[0126] like Figure 4a and 4b As shown, under ring lighting, the surface illuminance of the gauge block is higher than that of the chamfer, making the gauge block surface brighter than the chamfer. Figure 4c and 4d As shown, the surface illuminance of the gauge block under striped lighting is slightly higher than the chamfer illuminance, but both are considered low illuminance, resulting in a darker image. Figure 4a and 4c As shown, the illuminance on the surface of the gauge block is higher under ring lighting than under strip lighting. The image is brighter under ring lighting and darker under strip lighting. Under both lighting conditions, the illuminance of the chamfer of the gauge block is lower than that of the surface, and the chamfer appears darker in the image.

[0127] To further analyze the actual imaging effect of the optimized light source, two illumination methods were used: vertical downward ring illumination and 45-degree stripe illumination, and block images were acquired, as shown below. Figure 5a and 5bAs shown. During image acquisition, white was chosen as the background to effectively distinguish image feature edges from the background. Considering both light source type and illumination angle, each illumination method has its own optimal imaging illuminance. When illuminating the gauge block using both illumination methods, shadows appeared in the background image at the gauge block edges. The brightness of the ring light source and the strip light source were adjusted until the shadows disappeared, resulting in a gauge block image with clearly defined feature edges and background.

[0128] like Figure 5a The surface of the block is brightly imaged under ring lighting, and the chamfered edges show wide edges of black pixels.

[0129] like Figure 5b The image of the gauge block surface appears dark under the striped light illumination shown. The chamfer is integrated into the overall surface of the gauge block, effectively avoiding the influence of wide edge phenomenon.

[0130] To verify the effectiveness of the method of this invention, comparative experiments and analyses were conducted, including measuring the size of gauge blocks under two different lighting conditions, measuring the size of gauge blocks using the method of this invention and the traditional method, and evaluating the performance of the focusing evaluation functions of this invention and the traditional method. The software experimental environment consisted of a Windows 11 host computer system, OpenCV 3.4.1 image processing software, TracePro 7.0.3 light source simulation analysis software, MATLAB R2022a curve plotting software, a 12th Gen Intel(R) Core(TM) i7-12700H 2.30 GHz processor, and 16 GB of memory.

[0131] (1) To verify the light source optimization effect of the method of the present invention, a 30 mm part was first used as the calibration experimental object, and images of the gauge block were acquired using two lighting methods: direct overhead illumination and 45-degree angled stripe illumination. Then, the system was calibrated using the focused images of the gauge block under different lighting conditions to obtain the transformation relationship between the pixel coordinate system and the world coordinate system. Finally, the dimensions of the 20 mm gauge block were measured using different calibration results, and the accuracy of the dimension measurement was used as the evaluation index of the light source optimization effect.

[0132] The block images under two different lighting conditions were measured 10 times each, and the average value was taken as the pixel width measurement result. The comparison of the measurement results is shown in Table 1.

[0133] Table 1

[0134]

[0135] Using the same measurement method described above, the lateral dimension of a 20 mm gauge block was determined using two different comparative pixel equivalent values. The gauge block accuracy was 0.001 mm, and the manually measured value was 20.000 mm. Table 2 shows a comparison of the dimensions obtained using the two calibrated pixel equivalent values ​​and the manually measured value, using the same measurement algorithm.

[0136] Table 2

[0137]

[0138] As can be seen from Table 1, the average pixel width of the block image measured under ring light is higher than that measured under strip light. In multiple measurements, the pixel width under ring light is about 1.2 pixels higher than that under strip light. The pixel equivalent value under ring light is 0.00000151 mm / pixel smaller than that under strip light.

[0139] As shown in Table 2, the measured dimensions of the gauge block using ring light and bar light calibration were 19.99456 mm and 19.99953 mm, respectively, with mean errors of 5 µm and 0.5 µm, and relative errors to manual measurements of 0.0272% and 0.0024%, respectively. This is because the gauge block image under ring light has a certain width of pixels at the chamfered edges, making it susceptible to noise and illumination effects when filtering edge pixels, thus reducing extraction accuracy. The 45-degree angled bar light illumination method proposed in this invention can eliminate the wide chamfered edges of the gauge block image, resulting in more accurate edge pixel filtering.

[0140] (2) To verify the effectiveness of the method of the present invention in high-precision measurement applications, the size measurement accuracy of the image focusing method of the present invention is compared with the size measurement accuracy of manual focusing in the improved Zernike moment method proposed by Liu Liping et al. in 2023 using the same measurement comparison method as above, as shown in Table 3.

[0141] Table 3

[0142]

[0143] As shown in Table 3, the measured dimensions of the gauge blocks obtained by the improved Zernike moment method proposed by Liu Liping et al. and the method of this invention are 19.99546 mm and 19.99953 mm, respectively, with mean errors of 4.54 µm and 0.47 µm, and relative errors compared to manually measured values ​​of 0.0227% and 0.0024%, respectively. The 0.8-pixel difference between the improved Zernike moment method proposed by Liu Liping et al. and the method of this invention is due to the fact that the gauge block image detected by the improved Zernike moment method is acquired through manual focusing, resulting in inaccurate image focusing, errors in feature edge extraction, and decreased Zernike moment edge detection accuracy, thus affecting the accuracy of actual size measurement. The high-precision focused image of the gauge block detected by the method of this invention provides more accurate edge extraction, effectively improving the Zernike moment edge detection accuracy and achieving high-precision size measurement.

[0144] (3) To verify the performance of the improved focus evaluation function of this invention, a comparative experiment was conducted with the Tenengrad function, Brenner function, Roberts energy function, squared gradient function, absolute gradient function, the Improved-Tenengrad function proposed by Zeng Haifei et al. in 2021, and the Proposed-Tenengrad function proposed by Pan Hongliang et al. in 2023. The experimental objects of this invention are 25 "defocus-focus" block sequence images with a resolution of 5472×3648. The defocus and focus block images are shown below. Figure 6a and 6b As shown.

[0145] To verify the sensitivity, stability, and noise resistance of the improved algorithm, this invention uses quantitative indicators such as sharpness ratio, sensitivity factor, and steepness for evaluation.

[0146] The sharpness ratio represents the ratio of the maximum value to the minimum value in the focus characteristic curve. This ratio indicates the magnitude of the curve's variation; a larger magnitude indicates better focusing. The specific formula is as follows:

[0147]

[0148] in, For resolution ratio, and These are the maximum and minimum values ​​of the focusing characteristic curve, respectively.

[0149] The sensitivity factor represents the change in sharpness value near the focus position on the focus characteristic curve. It is calculated by taking the relative change between the maximum sharpness value at the focus position and the sharpness values ​​deviating from the focus position. The larger the change, the larger the sensitivity factor, and the better the image focusing effect. The specific formula is as follows:

[0150]

[0151] in, For sensitivity factor, and These represent the maximum value of the focusing characteristic curve and its corresponding x-axis. This represents the change in the horizontal axis of the focusing characteristic curve.

[0152] Kurtosis represents the rate of change of sharpness value in the steep region of the focus characteristic curve. A larger rate of change indicates more sensitive focusing and better image focusing. Kurtosis is divided into left and right kurtosis, centered on the focus position. The average of the two kurtosis values ​​is taken as the kurtosis of the focus characteristic curve. The specific formula is as follows:

[0153]

[0154] in, For the overall curve steepness, and These represent the steepness of the left and right sides of the curve, respectively. and These are the focus function values ​​at the critical points of the flat and steep regions on the left and right sides, respectively. and These represent the widths of the steep sections on the left and right sides, respectively.

[0155] Using MATLAB, the sharpness values ​​of the normalized image sequence are plotted as image focus characteristic curves, such as... Figure 7 As shown in the figure, the Weighted-Gradient function of this invention has better sensitivity and steepness than the Improved-Tenengrad function, and has a higher clarity ratio, sensitivity, and steepness than the Proposed-Tenengrad function, Tenengrad function, Brenner function, Roberts energy function, squared gradient function, and absolute gradient function.

[0156] To verify the noise robustness of the improved focusing evaluation function of this invention, random salt-and-pepper noise of 3000 and 5000 was added to the block sequence images, respectively. The variance... The focusing characteristic curves of the images after adding Gaussian noise of 3 and 5 are shown below. Figure 8a , 8bFigures 8c and 8d show the results. As can be seen from the figures, under salt-and-pepper noise, all evaluation functions show a decreasing trend in sharpness ratio, which decreases further with increasing salt-and-pepper noise. However, the sharpness ratio of the proposed focusing evaluation function remains higher than that of the comparative evaluation functions. The sensitivity and steepness of the proposed focusing evaluation function remain essentially unchanged, while the sensitivity and steepness of the other evaluation functions decrease. Under Gaussian noise, the sharpness ratio, sensitivity, and steepness of the proposed focusing evaluation function and the Improved-Tenengrad evaluation function remain essentially unchanged, and all three indicators are superior to the Improved-Tenengrad evaluation function. With increasing Gaussian noise, the focusing characteristic curves of the Proposed-Tenengrad evaluation function and the traditional evaluation function become flatter, with decreased sensitivity and steepness. Therefore, the proposed focusing evaluation function exhibits strong noise resistance to both salt-and-pepper and Gaussian noise.

[0157] Using the above resolution ratio Sensitivity factor and steepness The focusing effect, noise resistance, sensitivity, and steepness of the focusing evaluation function of this invention are verified, wherein the coordinate change of the sensitivity factor is measured. The value is 2, and the steepness boundary point is selected based on the focusing characteristic curve. The performance indicators of the focusing evaluation function and the comparative evaluation function of this invention are shown in Table 4 under noise-free conditions; the performance indicators are shown in Table 5 under noise conditions.

[0158] Table 4

[0159]

[0160] As shown in Table 4, in the absence of noise interference, the percentage difference between the three indicators of the focusing evaluation function of this invention and the mean values ​​of the three indicators of the corresponding comparative evaluation function is calculated. The sharpness ratio improves by an average of 7512.4%, the sensitivity factor by an average of 503.7%, and the steepness by an average of 106.0%. The improved gradient weighting algorithm based on grayscale distribution in this invention effectively improves the sensitivity and steepness of the focusing evaluation function.

[0161] Table 5

[0162]

[0163] As shown in Table 5, after adding salt-and-pepper noise and Gaussian noise, the performance of the contrast evaluation function decreases with the increase of noise energy. The sharpness ratio of the focusing evaluation function of this invention decreases when used with noise of different energy levels, but it still maintains good evaluation performance under salt-and-pepper noise; under Gaussian noise, it is much better than the contrast evaluation function. Similarly, the sensitivity factor and kurtosis of the focusing evaluation function of this invention are also higher than those of the contrast evaluation function, indicating that the focusing evaluation function of this invention has stronger noise resistance.

[0164] In the visual measurement of industrial parts dimensions, the working distance between the industrial camera and the part surface is varied to acquire a sequence of part images and record the corresponding shooting positions. Using the focus evaluation method proposed in this invention, the sharpness of the sequence of part images is evaluated to obtain precisely focused images. The industrial camera is then moved to the appropriate shooting position to achieve image focusing. Precisely focused part images have sharper feature edges, resulting in more accurate edge extraction and thus enabling high-precision measurement of part dimensions.

[0165] In summary, this invention provides a high-precision focusing method for part images that is highly sensitive, noise-resistant, and stable.

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

Claims

1. A high-precision focusing method for part images based on improved gradient weighting, characterized in that: Includes the following steps: 1) Obtain a sequence of images showing the defocusing and focusing of the part, and extract the feature edge pixels of the images; 2) Improve the Tenengrad gradient algorithm based on the 4-direction Sobel operator template to obtain the gradient values ​​of pixel points at the feature edges of the image; 3) Improve the gradient weighting algorithm to obtain adaptive gradient weighting coefficients; 4) Gradient weighting coefficients are used to weight the gradient values ​​of pixel points at the feature edges of the image. The image sharpness is evaluated by the weighted gradient values ​​to obtain a precisely focused image of the part and achieve high-precision dimensional measurement of the part. In step 1), image feature edge pixels are extracted by improving the Otsu adaptive segmentation threshold. The expression is: , in: For pixels grayscale value, Image pixel size The traditional Otsu adaptive segmentation threshold; The process of extracting image feature edge pixels by improving the Otsu adaptive segmentation threshold is as follows: The characteristics of image feature edge pixels are analyzed using local gray-level variance analysis, with pixel values ​​as the basis. Centered on the pixel, a 3×3 window is used to calculate the local grayscale variance of that pixel. ; Improve Otsu adaptive segmentation threshold As a filtering boundary for edge pixels of image features, and related to the local gray-level variance of pixels. Comparison, retaining effective pixels at image feature edges The specific formula is as follows: , , in, This represents the average local grayscale value. In step 2), the 4-direction Sobel operator template is: , , , , in, , , , Templates are used in the horizontal, 45°, vertical, and 135° directions, respectively. The gradient of the pixel is calculated in four directions based on the Sobel operator template convolution. The formula for calculating the gradient value of feature edge pixels is: , , , , , in, , , and These are the effective edge pixels. Gradient values ​​in the 0°, 45°, 90° and 135° directions, This is a convolution operation; The gradients are calculated by convolving the image edge pixels with Sobel operator templates in four directions, and the squared gradient values ​​in the four directions are summed. As the overall gradient value of the edge pixels; Step 3) specifically includes: (31) Traverse and compare the gray values ​​of the 8-neighborhood of the effective edge pixels to obtain the maximum gray value. and minimum gray value It then uses the maximum and minimum gray values ​​as boundaries to determine the effective gray values ​​in the neighborhood, and filters out the maximum gray value. and a minimum gray value Eliminate the interference caused by noise points leading to abrupt changes in the grayscale values ​​of neighboring areas; The optimal mean value of the neighborhood grayscale is obtained by averaging the effective grayscale values ​​of the selected neighborhood. The specific formula is as follows: , in, The grayscale value of a pixel. For the set of 8 neighboring points, , These are the x and y coordinates of the 8-neighborhood points of the pixel; (32) Obtain the gradient weighting coefficient by the correlation between the effective edge pixel and the optimal mean gray level of its neighborhood. A large difference in grayscale values ​​between the two indicates a low correlation and a high gradient weight. The specific formula is as follows: , in, The grayscale value of a pixel. It is the optimal mean of the neighborhood gray level.

2. The high-precision focusing method for part images based on improved gradient weighting as described in claim 1, characterized in that: Step 4) specifically includes: (41) Using gradient weighting coefficients The gradient values ​​at image edges are weighted using the following formula: , in, This is an evaluation value for image sharpness. These are the gradient weighting coefficients. , , and These are the effective edge pixels. Gradient values ​​in the 0°, 45°, 90° and 135° directions; (42) The sharpness evaluation of sequential part images is completed by improving the focusing evaluation function of the gradient weighting algorithm; (43) Normalize the sharpness values ​​of the sequence images and use MATLAB to plot the focus characteristic curves; (44) Select the maximum image clarity value in the focusing characteristic curve, find the corresponding part image, move the industrial camera to the corresponding shooting position, and realize the focusing of the part image and high-precision dimension measurement.

3. The high-precision focusing method for part images based on improved gradient weighting as described in claim 2, characterized in that: Step (43) specifically includes: The normalized sharpness value is obtained by proportionally calculating the sharpness values ​​of all images to the maximum sharpness value of the focused image. The specific formula is as follows: , in, To focus on the image with the highest sharpness, They are respectively A sequence of image sharpness values.

4. A high-precision focusing device for part images based on improved gradient weighting, characterized in that: The experimental platform (1), stage (2), Z-axis slide (3), industrial camera (4), lens (5), light source (6), part (7) and bracket are included. The Z-axis slide (3) and bracket are fixed on the experimental platform (1). The industrial camera (4) is set at the free end of the Z-axis slide (3) and can move vertically through the Z-axis slide (3). The lens (5) is set on the industrial camera (4). The stage (2) is horizontally placed below the lens (5). The part (7) is placed on the stage (2). The light source (6) is fixed on the bracket. The height of the light source (6) from the experimental platform (1) is 100mm, and the horizontal distance from the light source (6) to the part (7) is 100mm. The angle between the light-emitting surface of the light source and the upper surface of the part (7) is 45 degrees.

5. The high-precision focusing device for part images based on improved gradient weighting as described in claim 4, characterized in that: The Z-axis slide (3) drives the industrial camera (4) to move, so that the industrial camera (4) changes the working distance between the industrial camera and the surface of the part by 1 mm step to acquire sequential images of the part in the defocus-focus sequence.

Citation Information

Patent Citations

  • A lighting method, lighting structure and detection device for surface defect detection

    CN110736752B

  • Method and apparatus for evaluating the sharpness of microscopic images

    CN111062916B

  • Mask alignment apparatus and mask alignment method

    CN112575287A