Cross image center positioning method based on unsupervised machine learning
Patent Information
- Application Number
- CN202411211851.0
- Authority / Receiving Office
- CN · China
- Patent Type
- Applications(China)
- Current Assignee / Owner
- Filing Date
- 2024-08-30
- Publication Date
- 2024-11-08
AI Technical Summary
但是这类算法由于在实际处理图像时,因为其复杂性会遇到多个特征点,从而具有鲁棒性差的特点
[0050] The cross image center positioning method based on unsupervised machine learning provided by the present invention is proposed in view of the characteristics of poor robustness and high noise of the cross image of the center deviation meter and autocollimator during the positioning measurement process, and has high real-time performance. And high robustness, it has good computing power for noisy pictures in various situations, and has the advantage of achieving high-precision aiming of cross images under non-uniform illumination conditions.
Smart Images

Figure CN118918191A_ABST
Abstract
Description
Technical Field
[0001] The invention belongs to the technical field of optical metrology, and in particular relates to a cross image center positioning method based on unsupervised machine learning. Background Art
[0002] Autocollimator and center offset meter are optical instruments that measure the optical axis center offset of optical elements. Such instruments generally measure the optical axis offset by calculating the center coordinates of the returned cross image. For such instruments, the better the repeatability of the target image positioning and the higher the accuracy, the higher the measurement accuracy of such measuring instruments. Therefore, how to accurately and quickly obtain the center coordinates of the cross image through image processing has always been a hot topic in the research of such instruments.
[0003] At present, the accuracy of cross-image positioning is trained by artificial calibration using convolutional neural networks (CNN). Alternatively, the image center is located using a support vector machine (SVM) for supervised machine learning. The above methods all require algorithm training and calibration, but in the actual measurement process, due to the influence of lens distortion and pupil function diffraction, the image captured by the camera cannot be completely consistent with the previously trained image, resulting in measurement accuracy errors.
[0004] There are many traditional algorithms for locating the center of the cross image, including accumulating the horizontal and vertical coordinates, calculating the centroid by region and fitting, and directly using Hough transform line detection. However, these algorithms have poor robustness because they encounter multiple feature points due to their complexity when processing images. Summary of the invention
[0005] The purpose of the present invention is to solve one or more of the above-mentioned problems, and to this end we propose a cross image center positioning method based on unsupervised machine learning on the basis of traditional algorithms, so as to achieve good positioning of the center of the cross target.
[0006] To achieve the above purpose, the technical solution provided by the present invention is:
[0007] A method for locating the center of a cross image based on unsupervised machine learning comprises the following steps:
[0008] Step 1: Obtain a cross image and convert the cross image into a grayscale image;
[0009] Step 2: Use the adaptive threshold method to perform a binarization operation on the grayscale image to obtain a binary image;
[0010] Step 3: Use the morphological method of first corrosion and then expansion to process the binary image to remove white noise and dark noise of the binary image;
[0011] Step 4: Use the Canny algorithm to extract the edge of the binary image processed in step 3 to obtain an edge image;
[0012] Step 5: Use Hough transform to detect the corner points of the edge image and obtain the coordinates of the corner points;
[0013] Step 6: Use the K-mean algorithm of unsupervised machine learning to cluster the corner point coordinates and finally calculate the coordinates of the cross center point.
[0014] Furthermore, the target image is converted into a grayscale image by using the sensitivity of the photoreceptor cells of the human eye to the colors of each RGB component, which is expressed as:
[0015] GRAY=0.3R+0.59G+0.1B
[0016] Among them, GRAY represents the single channel pixel value of the grayscale image, R represents the red channel pixel value of the target image, G represents the green channel pixel value of the target image, and B represents the blue channel pixel value of the target image.
[0017] Furthermore, in step 2, a block area including the target image is taken around the target pixel, and a pixel threshold is calculated based on the average grayscale value of the pixels in the block area;
[0018] Compare the pixel value of the pixel point with the pixel threshold. If the pixel value is greater than the pixel threshold, the pixel value is assigned to 225; if the pixel value is less than the pixel threshold, the pixel value is assigned to 0; traverse the pixel values of each area position in the grayscale image to complete the grayscale image binarization.
[0019] Furthermore, the pixel threshold is calculated by the following formula:
[0020]
[0021] Among them, T represents the pixel threshold, C represents the parameter threshold set manually, and L ij represents the pixel value at position (i, j) of the block area, Represents the average grayscale value of the pixels in the block area, and r and c represent the number of rows and columns of the block area matrix.
[0022] Furthermore, the size of the block region is an odd number.
[0023] Furthermore, in step 3, the structure matrix is used to perform an erosion operation on the binary image using the following formula:
[0024] (fΘb)(x,y)=min{f(x=x',y=y')-b(x',y')|(x',y')∈D b}
[0025] Among them, (fΘb)(x,y) represents the pixel value of the binary image at position (x,y) after the corrosion operation, fΘb represents grayscale corrosion, f represents the binary image, and b represents the structure matrix. D b The domain of b is the image area to be calculated. The structure matrix is translated to cover each position (x', y') in the binary image. The pixel value of each structural element in the structure matrix is subtracted from the corresponding pixel value of the binary image, and the minimum value of the obtained value is taken as the pixel value of the binary image at the position (x, y) after the corrosion operation.
[0026] Furthermore, in step 3, the binary image is expanded using the structural element by the following formula:
[0027]
[0028] in, Represents the pixel value of the binary image at position (x, y) after the dilation operation, represents grayscale expansion, b represents the structural matrix, D b Represents the image area to be calculated, and the structure matrix is translated to cover each position (x', y') in the image. In each position area where the structure matrix moves, the maximum value of the product of the sum of the pixel values of each element in the matrix and the pixel values at the corresponding coordinates of the binary image matrix is taken as the pixel value of the binary image at the position (x, y) after the expansion operation.
[0029] Furthermore, in step 4, the binary image processed in step 3 is first smoothed using a Gaussian filter, and then the gradient of each pixel is calculated. The pixel point with the maximum amplitude in the block area where each gradient Sobel matrix moves is removed using a non-maximum suppression algorithm. Strong and weak edges are divided according to the double threshold method, and finally isolated weak edges are eliminated to obtain an edge image.
[0030] Furthermore, the specific steps in step 4 are:
[0031] Step 4-1: The specific operation is to first use Gaussian filtering to smooth the binary image processed in step 3:
[0032] h(x,y)=G(x,y)*I(x,y)
[0033] G(x, y) is a Gaussian filter, I(x,y) is the image to be calculated. * represents the convolution operation, and h(x,y) represents the image after calculation;
[0034] Step 4-2, then use the Sobel operator to calculate the image gradient M(x, y) and direction θ(x, y):
[0035]
[0036] Step 4-3: Use the non-maximum suppression algorithm to remove the extreme points with the maximum value:
[0037]
[0038] Among them, M L is an artificially set low threshold, which is related to the calculated average gradient value of image pixels. x , δ y is the offset value in the gradient direction (δ x =cosθ(x, y),δ y = sinθ(x, y));
[0039] Step 4-4, finally use the double threshold method to eliminate isolated weak edges:
[0040]
[0041] M H is the high threshold set, Strong, Weak and Non-edge represent strong edge, weak edge and no edge respectively, and finally the weak edge and no edge are eliminated to extract the edge.
[0042] Furthermore, in step 6, the specific steps for calculating the coordinates of the cross center point are:
[0043] Step 6-1: Randomly generate k center point coordinates from the corner point coordinates;
[0044] Step 6-2: Traverse all corner points and classify each corner point into a different center according to the positional relationship between the corner point and the center point (Euclidean distance between coordinates);
[0045]
[0046] In the formula, x1, y1 represent the coordinates of point 1, x2, y2 represent the coordinates of point 2, and D represents the Euclidean distance between two random points. Based on the calculated Euclidean distance, points with similar Euclidean distances to the center point coordinates are grouped together.
[0047] Step 6-3: Calculate the average value of the corner point coordinates of each cluster, and use the corner point coordinates of the average value as the new center point coordinates;
[0048] Step 6-4: Determine whether the new center point coordinates converge; if the center point coordinates do not converge, repeat steps 6-2 and 6-3 until the new center point coordinates converge, output the clustering results, and calculate the average value of several cluster center coordinates according to the clustering results to finally obtain the cross center point coordinates.
[0049] The advantages of the present invention are:
[0050] The cross image center positioning method based on unsupervised machine learning provided by the present invention is proposed to address the characteristics of poor robustness and high noise of the cross images of the center deviation meter and the autocollimator during the positioning measurement process. It has high real-time performance and high robustness, good computing power for noise images in various situations, and the advantage of being able to achieve high-precision aiming of the cross image under conditions of non-uniform lighting. BRIEF DESCRIPTION OF THE DRAWINGS
[0051] The features and advantages of the present invention will become more readily understood through the following description with reference to the accompanying drawings, which are not drawn to scale and in which some features are exaggerated or minimized to show details of particular components:
[0052] Figure 1 is a flow chart of a method for locating the center of a cross image according to an embodiment of the present invention;
[0053] Figure 2 is a flow chart of the K-mean algorithm of an embodiment of the present invention;
[0054] Figure 3 A diagram showing the effect of calculation and recognition in an embodiment of the present invention. DETAILED DESCRIPTION
[0055] The present invention will be described in detail below with reference to the accompanying drawings by means of exemplary embodiments of the present invention. It should be noted that the following detailed description of the present invention is only for the purpose of illustration, and is not intended to limit the present invention.
[0056] A method for locating the center of a cross image based on unsupervised machine learning, such as Figure 1 As shown, the following steps are included:
[0057] Step 1: Obtain a cross image and convert the cross image into a grayscale image.
[0058] The target image is converted into a grayscale image by using the sensitivity of the human eye's photoreceptor cells to the colors of each RGB component, expressed as:
[0059] GRAY=0.3R+0.59G+0.1B
[0060] Among them, GRAY represents the single channel pixel value of the grayscale image, R represents the red channel pixel value of the target image, G represents the green channel pixel value of the target image, and B represents the blue channel pixel value of the target image.
[0061] Step 2: Use the adaptive threshold method to binarize the grayscale image to extract the morphological feature information of the grayscale image and obtain a binary image.
[0062] And because the light source has a non-uniform illumination effect on the target, we use the uniform value method in the adaptive threshold method.
[0063] Specifically:
[0064] A block area including the target image is taken around the target pixel, and the pixel threshold is calculated based on the average grayscale value of the pixels in the block area.
[0065] The size of the block area is an odd number, and since the image area is generally an even number, such as 1080*1048, 2048*1080, the odd number area can generally just cover the image area during the block area moving scanning process.
[0066] Compare the pixel value of the pixel point with the pixel threshold. If the pixel value is greater than the pixel threshold, the pixel value is assigned to 225; if the pixel value is less than the pixel threshold, the pixel value is assigned to 0; traverse the pixel values of each area position in the grayscale image to complete the grayscale image binarization.
[0067] The pixel threshold is calculated by the following formula:
[0068]
[0069] Among them, T represents the pixel threshold, C represents the manually set parameter threshold, which is set based on the pixel value of the image background, and L ij represents the pixel value at position (i, j) of the block area, Represents the average grayscale value of the pixels in the block area, and r and c represent the number of rows and columns of the block area matrix.
[0070] The binarization of the adaptive threshold algorithm can accurately reflect the shape information of the cross target. However, there are too many point noises in the binarized image, and further morphological operations are needed to remove the noise points.
[0071] Step 3: The binary image is processed using the erosion-then-dilation morphology to remove white noise and dark noise from the binary image.
[0072] First, use the opening operation to erode and then dilate to remove the dark noise of the image, then use the closing operation to dilate and then erode to remove the white noise of the image. Finally, dilate to connect the separated edge pixels.
[0073] The structure matrix is used to perform corrosion operation on the binary image using the following formula:
[0074] (fΘb)(x,y)=min{f(x=x',y=y')-b(x',y')|(x',y')∈D b}
[0075] Among them, (fΘb)(x,y) represents the pixel value of the binary image at position (x,y) after the corrosion operation, fΘb represents grayscale corrosion, f represents the binary image, and b represents the structure matrix. D b Represents the domain of b, that is, the image area to be calculated (i.e., the position of the structure matrix after each translation). The structure matrix is covered in each orientation (x', y') in the binary image through each translation. The pixel value of each structural element in the structure matrix is subtracted from the corresponding pixel value of the binary image, and the minimum value of the obtained value is taken as the pixel value of the binary image at the position (x, y) after the corrosion operation. The result is to eliminate the isolated boundary points of the object, reduce the cross image, and remove the noise smaller than the area of the structure matrix, so the bright details in the area smaller than the structure element will be removed after corrosion. It can be used to remove small objects and burrs on the image. Smooth the boundaries of larger objects and remove noise.
[0076] The binary image is expanded using the structural element using the following formula:
[0077]
[0078] in, Represents the pixel value of the binary image at position (x, y) after the dilation operation, represents grayscale expansion, b represents the structural matrix, D b Represents the image area to be calculated, and the structure matrix is translated to cover each position (x', y') in the image. In each position area where the structure matrix moves, the maximum value of the product of the pixel value of each element in the structure matrix and the pixel value at the corresponding coordinate of the binary image matrix is taken as the pixel value of the binary image at the position (x, y) after the expansion operation.
[0079] Step 4: Use the Canny algorithm to extract the edge of the binary image processed in step 3 to obtain an edge image.
[0080] First, use Gaussian filtering to smooth the binary image after step 3, then calculate the gradient of each pixel, use the non-maximum suppression algorithm to remove the pixel with the largest amplitude in the block area where each gradient sobel matrix moves (the area after each translation of the structure matrix), and divide the strong and weak edges according to the double threshold method (those less than the smaller threshold are removed, those greater than the smaller and less than the larger are weak edges, and those greater than the larger are strong edges), and finally eliminate the isolated weak edges to obtain the edge image. The result is that the cross image is enlarged, the black holes are reduced, and the black holes in the area smaller than the structure matrix will be reduced or removed.
[0081] The specific steps are:
[0082] Step 4-1: First, use Gaussian filtering to smooth the binary image processed in step 3:
[0083] h(x,y)=G(x,y)*I(x,y)
[0084] G(x, y) is a Gaussian filter, I(x,y) is the image to be calculated, * represents the convolution operation, and h(x,y) represents the image after calculation.
[0085] Step 4-2, then use the Sobel operator to calculate the image gradient M(x, y) and direction θ(x, y):
[0086]
[0087] Thus, the image gradient M(x, y) and direction θ(x, y) are calculated.
[0088] Step 4-3: Use the non-maximum suppression algorithm to remove the extreme points with the maximum value:
[0089]
[0090] Among them, M L is an artificially set low threshold, which is related to the calculated average gradient value of image pixels. x , δ y is the offset value in the gradient direction (δ x =cosθ(x, y),δ y =sinθ(x, y)).
[0091] Step 4-4, finally use the double threshold method to eliminate isolated weak edges:
[0092]
[0093] M His the high threshold set, Strong, Weak and Non-edge represent strong edge, weak edge and no edge respectively, and finally the weak edge and no edge are eliminated to extract the edge.
[0094] Step 5: Use Hough transform to detect the corner points of the edge image and obtain the coordinates of the corner points.
[0095] The basic operation of Hough transform is to regard the intercept of the line equation as the dependent variable and the slope as the independent variable, and establish a parameter space coordinate system. That is, the points in the rectangular coordinate system correspond to the lines in the parameter space coordinate system, and the lines in the rectangular coordinate system correspond to the points in the parameter space coordinate system. Therefore, the problem of counting the number of pixels on which known straight line in the rectangular coordinate system is transformed into the problem of calculating which point in the parameter space has the most intersecting straight lines. The equation of the line can be detected by computer loop iteration.
[0096] Since the vertical line in the rectangular coordinate system cannot find its corresponding point in the parameter space due to its infinite slope, it is necessary to convert the straight line equation in the rectangular coordinate system into the form of the polar coordinate system.
[0097] R = xsin(theta) + ycos(theta)
[0098] In the formula, x and y represent the horizontal and vertical coordinates of the pixel point, theta represents the rotation angle in polar coordinates, and R represents the radius.
[0099] The points in the rectangular coordinate system are mapped to the polar coordinate system as sine curves. Therefore, the problem of counting the number of pixels on a known straight line in the rectangular coordinate system is transformed into the problem of solving the problem of which point in the polar coordinate space has the most intersecting sine curves. After detecting the equation of the line, the coordinates of the four corner points of the cross image can be calculated.
[0100] Step 6: Use the K-mean algorithm of unsupervised machine learning to cluster the corner point coordinates and finally calculate the coordinates of the cross center point.
[0101] like Figure 2 As shown, the specific steps for calculating the coordinates of the cross center point are:
[0102] Step 6-1: Randomly generate k center point coordinates from the corner point coordinates;
[0103] Step 6-2: Traverse all corner points and classify each corner point into a different center according to the positional relationship between the corner point and the center point (Euclidean distance between coordinates);
[0104]
[0105] In the formula, x1, y1 represent the coordinates of point 1, x2, y2 represent the coordinates of point 2, and D represents the Euclidean distance between two random points. Based on the calculated Euclidean distance, points with similar Euclidean distances to the center point coordinates are grouped together.
[0106] Step 6-3: Calculate the average value of the corner point coordinates of each cluster, and use the corner point coordinates of the average value as the new center point coordinates;
[0107] Step 6-4: Determine whether the new center point coordinates converge; if the center point coordinates do not converge, repeat steps 6-2 and 6-3 until the new center point coordinates converge, output the clustering results, and calculate the average value of several cluster center coordinates according to the clustering results to finally obtain the cross center point coordinates.
[0108] Finally, we get Figure 3 The calculation recognition effect diagram is shown.
[0109] Finally, it should be noted that the features mentioned and / or shown in the above description of the exemplary embodiments of the present invention may be combined in the same or similar manner into one or more other embodiments, combined with the features in other embodiments or substituted for the corresponding features in other implementations. The technical solutions obtained by these combinations or substitutions shall also be deemed to be included in the protection scope of the present invention.
Claims
1. A cross image center positioning method based on unsupervised machine learning, characterized in that: The following steps are involved: Step 1: Obtain a cross image and convert the cross image into a grayscale image; Step 2: Use the adaptive threshold method to perform a binarization operation on the grayscale image to obtain a binary image; Step 3: Use the morphological method of first corrosion and then expansion to process the binary image to remove white noise and dark noise of the binary image; Step 4: Use the Canny algorithm to extract the edge of the binary image processed in step 3 to obtain an edge image; Step 5: Use Hough transform to detect the corner points of the edge image and obtain the coordinates of the corner points; Step 6: Use the K-mean algorithm of unsupervised machine learning to cluster the corner point coordinates and finally calculate the coordinates of the cross center point.
2. The method for locating the center of a cross image according to claim 1, characterized in that: In step 1, the target image is converted into a grayscale image, expressed as: GRAY=0.3R+0.59G+0.1B Among them, GRAY represents the single channel pixel value of the grayscale image, R represents the red channel pixel value of the target image, G represents the green channel pixel value of the target image, and B represents the blue channel pixel value of the target image.
3. The method for locating the center of a cross image according to claim 1, characterized in that: In step 2, a block area including the target image is taken around the target pixel, and the pixel threshold is calculated based on the average grayscale value of the pixel points in the block area; Compare the pixel value of the pixel point with the pixel threshold. If the pixel value is greater than the pixel threshold, the pixel value is assigned to 225; if the pixel value is less than the pixel threshold, the pixel value is assigned to 0; traverse the pixel values of each area position in the grayscale image to complete the grayscale image binarization.
4. The method for locating the center of a cross image according to claim 3, characterized in that: The pixel threshold is calculated by the following formula: Among them, T represents the pixel threshold, C represents the parameter threshold set manually, and L ij represents the pixel value at position (i, j) of the block area, Represents the average grayscale value of the pixels in the block area, and r and c represent the number of rows and columns of the block area matrix.
5. The method for locating the center of a cross image according to claim 3, characterized in that: The size of the block area is an odd number.
6. The method for locating the center of a cross image according to claim 1, characterized in that: In step 3, the structure matrix is used to perform corrosion operation on the binary image using the following formula: (fΘb)(x,y)=min{f(x=x',y=y')-b(x',y')|(x',y')∈D b } Among them, (fΘb)(x,y) represents the pixel value of the binary image at position (x,y) after the corrosion operation, fΘb represents grayscale corrosion, f represents the binary image, b represents the structure matrix, D b Represents the image area to be calculated, and the structure matrix is translated to cover each position (x', y') in the binary image. The pixel value of each structural element in the structure matrix is subtracted from the corresponding pixel value of the binary image, and the minimum value of the obtained value is taken as the pixel value of the binary image at the position (x, y) after the corrosion operation.
7. The method for locating the center of a cross image according to claim 1, characterized in that: In step 3, the binary image is expanded using the structural element by the following formula: in, Represents the pixel value of the binary image at position (x, y) after the dilation operation, represents grayscale expansion, b represents the structural matrix, D b Represents the image area to be calculated, and the structure matrix is translated to cover each position (x', y') in the image. In each position area where the structure matrix moves, the maximum value of the product of the sum of the pixel values of each element in the matrix and the pixel values at the corresponding coordinates of the binary image matrix is taken as the pixel value of the binary image at the position (x, y) after the expansion operation.
8. The method for locating the center of a cross image according to claim 1, characterized in that: In step 4, the binary image processed in step 3 is first smoothed using Gaussian filtering, and then the gradient of each pixel is calculated. The non-maximum suppression algorithm is used to remove the pixel with the maximum amplitude in the block area where each gradient Sobel matrix moves. The strong and weak edges are divided according to the double threshold method, and finally the isolated weak edges are eliminated to obtain the edge image.
9. The method for locating the center of a cross image according to claim 8, characterized in that: The specific steps in step 4 are: Step 4-1: First, use Gaussian filtering to smooth the binary image processed in step 3: h(x,y)=G(x,y)*I(x,y) G(x, y) represents a Gaussian filter, I(x,y) represents the image to be calculated, * represents the convolution operation, and h(x,y) represents the calculated image; Step 4-2, then use the Sobel operator to calculate the binary image gradient M(x, y) and direction θ(x, y) after step 4-1: Step 4-3: Use the non-maximum suppression algorithm to remove the extreme points with the maximum value: Among them, M L represents the artificially set low threshold, which is related to the calculated average gradient value of the image pixels, δ x , δ y Represents the offset value in the gradient direction (δ x =cosθ(x, y),δ y = sinθ(x, y)); Step 4-4, finally use the double threshold method to eliminate isolated weak edges: M H It represents the high threshold set, Strong, Weak and Non-edge represent strong edge, weak edge and no edge respectively, and finally the edge is extracted by eliminating weak edge and no edge.
10. The method for locating the center of a cross image according to claim 1, characterized in that: In step 6, the specific steps for calculating the coordinates of the cross center point are: Step 6-1: Randomly generate k center point coordinates from the corner point coordinates; Step 6-2: Traverse all corner points and classify each corner point into a different center according to the Euclidean distance between the coordinates of the corner point and the center point; In the formula, x1, y1 represent the coordinates of point 1, x2, y2 represent the coordinates of point 2, and D represents the Euclidean distance between two random points. Based on the calculated Euclidean distance, the points with the closest Euclidean distance to the center point coordinates are grouped into one category; Step 6-3: Calculate the average value of the corner point coordinates of each cluster, and use the corner point coordinates of the average value as the new center point coordinates; Step 6-4: Determine whether the new center point coordinates converge; if the center point coordinates do not converge, repeat steps 6-2 and 6-3 until the new center point coordinates converge, output the clustering results, and calculate the average value of several cluster center coordinates according to the clustering results to finally obtain the cross center point coordinates.
Citation Information
Cited By
Jaw clutch pull-in detection method and equipment based on machine vision and medium
CN119672357A
Method and device for positioning cross directrix of display screen image and storage medium
CN120259433A
Method, device and storage medium for positioning crosshairs of display screen images
CN120259433B
Cross target center positioning method and device
CN120747213A
