Subpixel-based image size determination method
By employing a subpixel-based image sizing method, utilizing the Canny operator for edge detection and correction, and combining it with a fitting formula, the accuracy and stability issues of image measurement in existing technologies are resolved, achieving high-precision and high-stability image measurement.
Patent Information
- Application Number
- CN202110984639.8
- Authority / Receiving Office
- CN · China
- Patent Type
- Patents(China)
- Current Assignee / Owner
- Filing Date
- 2021-08-25
- Publication Date
- 2026-03-06
- Estimated Expiration
- 2041-08-25
AI Technical Summary
Existing technologies suffer from poor accuracy and stability in image measurement, especially in subpixel detection, where edge fitting is affected by conditions such as lighting, leading to inaccurate measurement results.
This paper proposes a subpixel-based image size determination method, uses the Canny operator for edge detection, corrects pixel-level edges, records the number of inner pixels, generates features, fits subpixel edges using a fitting formula, corrects the final result, and avoids the influence of lighting conditions.
It improves measurement accuracy and stability, reduces algorithm complexity, enhances detection adaptability, directly obtains the actual distance in the image, and has high accuracy and high stability.
Smart Images

Figure CN115731254B_ABST
Abstract
Description
Technical fields:
[0001] This invention relates to the field of image processing technology, specifically to a subpixel-based image size determination method that can effectively improve measurement accuracy and has high adaptability and stability. Background technology:
[0002] With the rapid development of artificial intelligence, especially image processing algorithms, non-contact machine vision-based industrial measurement products have seen significant improvements in measurement accuracy, content, and speed. Image-based detection offers advantages in rapid detection of multiple parameters, such as the ability to simultaneously and quickly detect length, curvature, angle, spacing, and different hole spacings, which traditional single measurement tools cannot achieve simultaneously and quickly online.
[0003] To measure the diameter, the key is to determine the number of pixels contained in the image (accurate to the sub-pixel level). Then, multiplying this number by the distance represented by each individual pixel yields the optimal distance. Currently, popular methods include mature pixel-level edge detection algorithms such as the Canny operator and the Sobel operator. Obviously, their accuracy can only reach the pixel level. There are also algorithms that use the Zernike moment method, fitting methods, and interpolation methods for sub-pixel detection, finding the sub-pixel contours of each boundary. However, these methods require finding accurate sub-pixel edges and the precise number of sub-pixel points to determine the final detection size, and their accuracy is greatly affected by the boundaries.
[0004] In existing technologies, when measuring dimensions, subpixel algorithms are mostly used to calculate the true boundaries on both sides separately, then calculate the number of pixels contained in each boundary, and then multiply by the single-pixel distance to obtain the true distance. If the two boundaries are fitted separately to obtain the optimal fitting curves on both sides, the curves will be affected by conditions such as lighting, resulting in inaccurate fitting curves and thus inaccurate results. Summary of the Invention:
[0005] This invention addresses the problems of poor accuracy and stability in existing technologies by proposing a sub-pixel-based image size determination method that can effectively improve measurement accuracy and has high adaptability and stability.
[0006] This invention achieves its purpose through the following measures:
[0007] A method for determining the size of an image based on subpixels, characterized by comprising the following steps:
[0008] Step 1: Use the device to acquire an image of the object to be detected;
[0009] Step 2: Perform coarse localization using edge detection operators. Use edge detection operators to perform pixel-level edge detection on the image of the object to be detected, and obtain the coordinate positions of the pixel edges in the original image.
[0010] Step 3: Perform pixel-level edge correction: Correct the outliers found in the pixel-level edges in Step 2, and calculate the number of inner pixels after correction;
[0011] Step 4: Determine n points on each side of the image. On both sides of the corrected image edge, find n points inwards from the image edge and record the gray values of the n points.
[0012] Step 5: Feature derivation, using the grayscale values of the found pixels to generate features;
[0013] Step 6: Fitting and calculating values, substitute into the fitting formula to fit, and obtain the true distance represented by the sub-pixel edge, which is the true distance represented by the n points on the outside of the image;
[0014] Step 7: Result correction. Add the pixel-level edge correction inner distance to the true distance obtained by fitting, and then correct the result to obtain the size of the workpiece to be inspected.
[0015] In step 2 of this invention, edge detection is performed using Canny, specifically as follows:
[0016] Step 2-1: Perform Gaussian smoothing on the image, specifically through Gaussian convolution;
[0017] Step 2-2: Calculate the gradient intensity and direction of each pixel in the image. Use four gradient operators to calculate the gradients in the horizontal, vertical, and diagonal directions respectively. Use common edge difference operators (such as Rober, Prewitt, Sobel) to calculate the differences Gx and Gy in the horizontal and vertical directions, and calculate the gradient magnitude and direction according to the following formula:
[0018]
[0019] θ=atan2(G y G x )
[0020] Steps 2-3: Then, the "non-maximum suppression" algorithm is used to find possible edge points in the image, and finally, the image edge points are found through double threshold values.
[0021] Step 4 of this invention corrects the found pixel-level edges and records the number of inner pixels, specifically as follows:
[0022] Step 3-1: Using the pixel-level edge points obtained in Step 2, the edge points are corrected. The specific correction method is as follows: assuming that the gray value distribution of the image is 1-255 (from black to white), find the first all-white data point with a gray value slightly less than 255 by looking outwards. If the edge found by Canny is the second gray line on the outside, then it needs to be moved outwards by one pixel, that is, the corrected boundary is the outermost gray edge.
[0023] Step 3-2: Assuming that the boundary found by Canny is the possible outermost boundary, and the outermost column of pixels is an uncertain sub-pixel boundary, then the difference between the newly found left and right boundary points is calculated and subtracted by 1 to obtain the true inner distance. Here, the inner boundary is based on the above assumption, that is, it is assumed that the distance represented by the pixels inside the boundary will not be segmented again.
[0024] In step 7 of this invention, the pixel-level edge correction specifically involves obtaining the pixel-level edge by using the coordinates of the pixels on both sides of the edge to obtain the horizontal dimension of the object at the pixel level. Then, by adding the true distance of the outer sub-pixel obtained in the fitting calculation, the horizontal dimension of the workpiece to be measured can be obtained. By correcting and converting the horizontal dimension, the required true dimension of the object to be measured can be obtained.
[0025] Compared with existing technologies, this invention does not require the determination of the outer contour of the image and can directly obtain the actual distance of the image, which has significant advantages such as high accuracy, good stability and high adaptability. Attached image description:
[0026] Appendix Figure 1 This is a flowchart of the present invention.
[0027] Appendix Figure 2 This is a schematic diagram of step 3 in Embodiment 1 of the present invention.
[0028] Appendix Figure 3 This is a schematic diagram of the result correction in step 7 of embodiment 1 of the present invention.
[0029] Appendix Figure 4 This is a schematic diagram of slope correction in step 7 of embodiment 1 of the present invention. Detailed implementation method:
[0030] The present invention will be further described below with reference to the accompanying drawings and embodiments.
[0031] Example 1:
[0032] This example presents a method for determining image size based on sub-pixel processing, which includes the following steps:
[0033] S1: Use the device to acquire an image of the object to be detected. The acquired data is a grayscale image, with full white set to 255 and black set to 1 (the algorithm is also applicable to data formats such as 0-1), and the acquired data is transmitted to the Canny detection algorithm.
[0034] S2: Perform pixel-level edge detection using edge detection operators. Here, Canny is used for edge detection. The specific steps are as follows:
[0035] S2-1: Perform Gaussian smoothing on the image, specifically through Gaussian convolution;
[0036] S2-2: Calculate the gradient intensity and direction of each pixel in the image. Use four gradient operators to calculate the gradients in the horizontal, vertical, and diagonal directions respectively. Commonly used edge difference operators (such as Rober, Prewitt, and Sobel) calculate the differences Gx and Gy in the horizontal and vertical directions. Thus, the gradient magnitude and direction can be calculated as follows:
[0037]
[0038] θ=atan2(G y G x )
[0039] S2-3: Then, the 'non-maximum suppression' algorithm is used to find possible edge points in the image, and finally, the image edge points are found through double threshold values;
[0040] S3: Correct the found pixel-level edges and record the number of inner pixels. Specifically: S3-1: Use the pixel-level edge points obtained in S2 to correct the edge points. The specific correction method is to find the first non-pure white (grayscale value slightly less than 255) data point by searching outwards, and use it as the new boundary point. Figure 2 As shown, the edge found by Canny is the second gray line from the outside. Therefore, it needs to be moved outward by one pixel, that is, the boundary needs to be corrected to the outermost gray edge.
[0041] S3-2: Assuming that the boundary found by Canny is the possible outermost boundary, and the outermost column of pixels is an uncertain sub-pixel boundary, then the difference between the newly found left and right boundary points is subtracted by 1 to obtain the true inner distance. Here, the inner boundary is based on the above assumption, that is, it is assumed that the distance represented by the pixels inside the boundary will not be segmented again.
[0042] S4: Based on the corrected edges, find three points inwards from each side. Given an image with dimensions defined as the left and right sides, define the coordinate feature points of the left and right sides as follows:
[0043] l1, l2, l3, r1, r2, r3, where l represents left and r represents right, and the larger the subscript, the closer it is to the inside of the image;
[0044] S5: Generate features using the found pixels, specifically including:
[0045] S5-1: The difference characteristic is obtained by the following formula:
[0046] l 1-2 =l1-l2
[0047] l2-3=l2-l3
[0048] r 1-2 =r1-r2
[0049] r 2-3 =r2-r3;
[0050] S5-2: Add the squared term of the original feature
[0051] S5-3: Normalize the features, where x represents the original feature data, mean(x) represents the mean of the feature, max(x) represents the maximum value of the feature, min(x) represents the minimum value of the feature, and x′ represents the normalized data. The following values use l1, l2, l3, r1, r2, r3, ... These features are all normalized features.
[0052]
[0053] S6: Substitute into the fitting formula to perform fitting, and obtain the fitted value of the true distance represented by the sub-pixel edge, which is the true distance represented by the outer point;
[0054] S7: Add the actual distance obtained from S6 to the inner distance determined by the inner pixel-level edge to obtain its horizontal dimension. If the diameter of the object is required, the result needs to be corrected. That is, using the principle of triangle symmetry, the hypotenuse dimension is used to obtain the right-angle side dimension. The corrected result is the diameter of the workpiece to be measured. Figure 3 As shown.
[0055] S7-1: Assume the actual size of the device is L, and the predicted value is... The true distance represented by a subpixel is L o The fitted value is inner L i ,but The result is:
[0056]
[0057] S7-2: Specifically, if the object to be detected is a cylinder, its diameter needs to be measured, and the resulting image is as follows. Figure 4 As shown, the solid line represents the diameter of the object being measured, and the dashed line represents the dimensions of the horizontal cross-section. As obtained in S7-1, if the diameter of the workpiece to be measured is required, then it is necessary to... The slope correction process is as follows:
[0058] a) Fit the pixel-level edge points obtained in S2, where the dashed line-boundary line in the figure below is the fitting line, and calculate the slope S of the fitting line.
[0059] b) Let the diameter to be measured be D. Using the Pythagorean theorem and the principle of similar triangles, then...
[0060] So
[0061]
[0062] Compared with existing technologies, this invention does not distinguish the distances represented by the left and right sides during the measurement of the workpiece object. Instead, it treats the two as a whole and utilizes the data from both sides. Therefore, the fault tolerance rate for single pixel distance is twice that of calculating the distances from both sides separately, and the requirements for single pixel distance are much lower than those of existing technologies. As a result, this method effectively improves the adaptability and stability of detection and reduces the complexity of the algorithm.
Claims
1. A method of sub-pixel based image sizing, characterized by, The method comprises the following steps: Step 1: collecting an image of the object to be detected by using a device; Step 2: performing coarse positioning of an edge detection operator, performing pixel-level edge detection on the image of the object to be detected by using the edge detection operator to obtain the coordinate position of the pixel edge of the image in the original image; Step 3: performing pixel-level edge correction: correcting the abnormal values existing in the pixel-level edge found in step 2, and calculating the number of pixel points on the inside after correction; Step 4: determining n points on each side of the image: finding n points on the inside of the image on each side of the edge of the image after correction, and recording the gray values of the n points; Step 5: feature derivation: generating features by using the gray values of the found pixel points, generating the square term of the original features and the difference feature of each two adjacent coordinates; Step 6: fitting and evaluation: bringing the derived features into a fitting formula for fitting to obtain the real distance represented by the sub-pixel edge; Step 7: result correction: adding the pixel-level edge size to the real distance obtained by fitting and evaluation to correct the result, that is, to obtain the size of the workpiece to be detected; The step 4 determines 3 points on each side of the image, specifically: records the gray value of each point as wherein represents the left, represents the right, and the subscript is larger, the closer to the inside of the image; The pixel-level edge correction in step 7 is specifically that, after obtaining the pixel-level edge, the coordinates of the pixel points on the two sides of the edge are used to obtain the inside size of the object to be detected, and then the real distance of the outside sub-pixel obtained in the fitting and evaluation is added to obtain the size of the object to be detected in the horizontal direction, and then the Pythagorean theorem and the principle of triangle similarity are used to obtain the diameter size of the object to be detected; Step 7-1: Assume the real size of the device is , the predicted value is , the real distance represented by the sub-pixel is , and the fitted value is , The result is: , l1 2 , l2 2 are square terms of the original features, respectively, the difference feature l 1-2= l1-l 2、 is the difference of two gray values; Step 7-2: Correction processing for the diameter size measurement of the cylindrical object to be detected, the following steps are executed on the predicted value The slope correction is performed as follows: Step 7-2-1: fitting is performed by using the obtained pixel-level edge points to obtain the slope S of the fitting line; Step 7-2-2: assuming that the diameter to be detected is D, the Pythagorean theorem and the principle of triangle similarity are used, and then , then .
2. The method of sub-pixel based image sizing according to claim 1, wherein, In step 2, Canny is used for edge detection, which is specifically: Step 2-1: Gaussian smoothing is performed on the image, which is specifically realized by Gaussian convolution; Step 2-2: the gradient strength and direction of each pixel point in the image are calculated, four gradient operators are used to calculate the gradients in the horizontal, vertical and diagonal directions respectively; the edge difference operator is used to calculate the horizontal and vertical differences Gx and Gy, and the gradient modulus and direction are calculated according to the following formula: ; Step 2-3: the "non-maximum suppression" algorithm is used to find the possible edge points in the image, and finally the image edge points are found by using double threshold values.
3. The method of sub-pixel based image sizing of claim 1, wherein, In step 3, the found pixel-level edge is corrected, and the number of pixel points on the inside is recorded, which is specifically: Step 3-1: the pixel-level edge points obtained in step 2 are corrected, and the specific correction method is that the first data which is not all white, that is, the gray value is 255, is found as a new boundary point; Step 3-2: assuming that the boundary found by Canny is the outermost boundary, the outermost column of pixels is an uncertain sub-pixel boundary, and then the inner real distance is obtained by using the newly found left and right boundary points to perform subtraction and subtraction by 1, wherein the inner boundary is under the premise of the above assumption, that is, it is considered that the distance represented by the pixel points on the inside of the boundary will not appear again.
Citation Information
Patent Citations
Measurement method for image Gaussian Blur
CN103353985A
Automobile glass sub-pixel contour extraction method and automobile glass detection method
CN111415376A