# An Improved Canny-Zernike Subpixel Detection Algorithm

Authors: Zhicheng Wang; Zhe Wang; Nanhai Huang; Jie Zhao
Journal: Wireless Communications and Mobile Computing
 (2022)

---

## Abstract

This paper proposed a new subpixel detection method that detects subpixel edges directly, as opposed to the previous method, which requires crossing the entire image. It shows superior subpixel detection on the edge directly, which enhances subpixel edge detection speed significantly. In order to overcome the problem of noise reduction, this paper employs bilateral filtering. The method first performed coarse localization with the improved operator to determine the coordinates and gradient direction of the edge points. Then, the Zernike moment algorithm was used for subpixel repositioning of edge points. Finally, subpixel level edge positioning of the image is obtained. The detection algorithm is used to identify the edges of large-size workpieces, and the results reveal that the approach has superior positioning accuracy, noise immunity, and fast detection speed.


---

## Body

## 1. Introduction

Vision is the most significant mechanism through which humans perceive their surroundings and acquire information, particularly in the area of industrial inspection [1]. For the target identification system with more complex background, the accurate acquisition of edge information is more important.Traditional pixel detection methods are based on the presence of grayscale variations at the image edges; the first- and second-order derivative operators are used to localize the edges, such as Roberts, Prewitt, Sobel, Laplacian, and Canny operators [2]. With the improvement of image refinement, this edge detection can no longer meet the requirements of subsequent processing, requiring an accuracy of less than one pixel, so subpixel edge detection is applied; subpixel detection can enhance pixel detection quality from the margins to the inside [3, 4].Researchers have paid more attention to it. The corresponding improvement works were made. The commonly used subpixel edge detection algorithms are usually divided into the fitting method [5, 6], interpolation method [7, 8], and moment method [9, 10]. Among them, the interpolation method is relatively simple, but vulnerable to noise; the fitting method can obtain better edges, but the computational effort is relatively large, and the required model is more complicated. The method of moments has better noise immunity and efficiency than the interpolation and fitting methods. The method of moments has better noise immunity and efficiency than the interpolation and fitting methods and is widely used in high-accuracy detection systems.Kisworo et al. [11] proposed a new method to extract edge features to subpixel accuracy using edge models and local energy functions. Although this method provides good results for 1-D and 2-D edge types of images, the type of edges must be known to use the correct model, so there are limitations in practical applications. Ye et al. [12] introduced a high-precision subpixel edge detection algorithm based on Gaussian edge model. Bouchara and Ramdani [13] established a variable model for edge detection, but the results are easily affected by the gradient direction and position.Hermosilla et al. [14] combined ENO (Essentially None Oscillation) interpolation with gradient detection algorithms for edge detection. Xie et al. [15] first used the Canny algorithm to process and then applied Hermitian interpolation for precise positioning and realized the calculation of the edge area. Jensen and Anastassiou [16] proposed a nonlinear interpolation scheme, which presents lower reconstruction errors than linear techniques in sharper images. Pap and Zou [17] proposed a nonlinear fourth-order interpolation combined with Canny operator to achieve edge location.Tabatabai and Mitchell [18] firstly achieved subpixel detection accuracy by using a third-order gray moment edge detection method, which provides edge positions in closed form without interpolation or iteration and is not affected by additive and multiplicative gray scale variations. Lyvers et al. [19] proposed a method based on spatial moments, using spatial moments and edge step parameters to determine the edge position. These two approaches are highly accurate, but they are computationally costly and are only appropriate for images with limited information. On the basis of summarizing traditional edge detection methods, Canny [20] proposed the Canny algorithm; its accuracy of identifying image edges is much higher compared to those of other edge detection algorithms. Ghosal and Mehrotra [21] proposed the ZOM (Zernike orthogonal moments) method, but this method is not suitable for detecting small objects accurately. Yang et al. [22] proposed an algorithm combined with Otsu’s [23] and a traditional Zernike moment method; the optimal gray threshold can be obtained directly for edge detection. The inspection time is shortened, and the inspection quality is also very good. Shan and Boon [24] used a moment algorithm based on the fuzzy edge model, which is more in line with the actual situation than the ideal step model. This method has a very high computational accuracy in a noise-free ideal image, but the error in the noise image is very high. Da and Zhang [25] used the Sobel operator to perform moment operation on the region of interest and realized the initial rough localization of the edge. Zhao et al. [26] proposed a new algorithm that utilizes combinatorial kernels to improve resource utilization. In addition, it optimizes the radial polynomial of Zernike moments to reduce computation. Deng and Gwo [27] proposed a generalized Zernike moments method to calculate high-order generalized Zernike moment; the corresponding improvement is made to get the solution that the algorithm was slow in determining the edge point.To address the above limitations, this paper proposes an improved Canny-Zernike moment subpixel edge detection algorithm. The Zernike moment in the algorithm has stable size before and after rotation, so the positioning accuracy is high and the antinoise performance is strong. It has obvious advantages and is widely used in subpixel detection. In this paper, the subpixel edge detection algorithm based on Zernike moments is studied to locate the edge of the image, and the corresponding improvements are made in solving the problem that the algorithm is slow in determining edge points. The results show that the method has high accuracy, stronger robustness, and faster detection speed for subpixel edge detection.


## 2. Theory of Subpixel Edge Detection

The commonly used subpixel edge detection algorithms are usually divided into a fitting method, interpolation method, and moment method. According to the rotation invariance of the moment, it performs well in complex environments and is not sensitive to noise. So it is an effective subpixel image edge detection method at present. The commonly used moments are grayscale moment, space moment, Zernike moment, etc. Especially the Zernike moment has a stable size before and after rotation, so the positioning accuracy is high and the antinoise performance is strong.The principle of subpixel edge localization based on Zernike moments is the 4 parameters of the model calculated by Zernike moments at 3 different orders of the image, comparing these parameters with a set threshold to accurately locate the edges of the image. Zernike moments are orthogonalized functions based on Zernike polynomials, and the set of orthogonal polynomials utilized is a complete orthogonal set in the unit circle; Zernike moments are rotationally invariant. ZernikeN-order polynomial is defined as
(1)Vnmρ,θ=Rnmeimθ,where ρ is radial distance, θ is azimuth and meets the following condition: 0≤ρ≤1; nm is an integer and satisfies the condition: n≥0，n−m is an even number, m≤n, i is the imaginary unit, and Rnm is given by
(2)Rnmρ=∑s=0n‐m/2−1sn−s!ρn−2ss!n+m/2−s!n−m/2−s!.


## 3. Improved Canny-Zernike Moment Subpixel Edge Detection Algorithm

When a traditional algorithm is used to calculate Zernike moments, the centroid of the picture is recognized to be the coordinate origin and the total picture is projected inside the unit circle. The improved moment method does not need to cross the entire image. Therefore, the subpixel edge detection method can improve the detection speed.In this paper, we use a bilateral filter to replace the Gaussian filter so as to reduce noise. The output pixel numeral value is determined by the weighted combination of adjacent pixel numeral values of the bilateral filtering, so pixel-level edge localization can be obtained. The calculation formulas of bilateral filtering for input pixels are(3)pi,j=∑k,lfk,lwi,j,k,l∑k,lwi,j,k,l,wdi,j,k,l=exp−i−k2+j−l22δ2,wri,j,k,l=exp−pi,j+pk,l22δ2,where fk,l (the input image) is the value of each pixel of the image, wi,j is the weight of the pixel center point 2N+12 in pi,j, which contains location-domain Gaussian function wd and luminance Gaussian Function ws.This paper chooses a3∗3 detection template and increases 45° and 135° directions on it to improve detection precision. The gradient templates are as follows:
(4)Hx=−101−202−101,Hy=−1−2−1000121,H45°=−101−202−101,H135°=−101−202−101.In formula (4), Hx,Hy,H45°, and H135°, represent the horizontal directions, vertical directions, 45°orientation, and 135°orientation of the gradient template, respectively. After filtering, the original image, the gradient components in four directions are obtained using the plane convolution of the multidirectional Canny template. The procedure for calculating gradients is as follows:
(5)Pxi,j=Gi,j+1−Gi,j−1,Pyi,j=Gi+1,j−Gi−1,j,P45°i,j=Gi−1,j+1−Gi+1,j−1,P135°i,j=Gi+1,j+1−Gi−1,j−1,(6)fxi,j=Pxi,j+P45°i,j+P135°i,j2,fyi,j=Pyi,j+P45°i,j−P135°i,j2,Mi,j=α⋅fxi,j2+β⋅fyi,j2,M=Mx2+My2+M45°2+M135°2.Equation (5) is the partial derivative of the gradient template in each direction, and in formula (6), the gradients fxi,j and fyi,j represent the horizontal and vertical directions, respectively. The gradient weighting coefficients are represented by α and β, respectively. The gradients in each direction are Mx,My,M45°,andM135°, respectively. At last, we can get the final gradient M.Based on the above principles of pixel-level edge operators, Zernike moments are recommended, and subpixel edge detection can be achieved without traversing the full image. The models of the second-order pixel are shown in Figure1. The unit circle is an ideal edge region, k denotes step gray level, h denotes background gray level, and h+k denotes the normal case of gray level edge area. l is the distance from center perpendicular to the edge, the angle ∅is between the edge normal, and the x-axis direction.Figure 1
Principles of Zernike edge detection.When we calculate the edge parameters∅, h, k, and l, 3 moments Z00,Z11, and Z20need to be calculated at first; the integral kernel formulas are: V00=1, V11=x+iy, and V20=2x2+2y2−1.On the basis of moment definition, the parameters of step edge can be represented by∅, h, k, and l. Compare the obtained parameters with the set threshold, and determine the image edges accurately. According to the rotational invariance of the Zernike moment, introduce a fully orthonormal basis by using complex polynomials. We can calculate and get the above four parameters by the following formula:
(7)ϕ=tan−1ImZ11ReZ11,l=Z20Z11′=Z20Z11e−jϕ,k=3Z11′21−l23/2=3Z1121−l23/2ejϕ,h=Z00−kπ/2+ktan−1l+kl1−l2π.The moments are determined using convolution of the template and picture gray scale because to the discreteness. If the unit circle is sampled within theN∗N pixel area, the template effect is taken into account. Because the stencil spans N2 pixels around the center of the stencil, the radius must be lowered by half for convolution. As a result, the predicted vertical distance l must be cut in half. As a result, the pixel point’s subpixel coordinates formula is
(8)xsys=xy+N2cosϕsinϕ.


## 4. Experimental and Analysis

### 4.1. Experimental Setup

As illustrated in Figure2, a large-scale workpiece image acquisition hardware platform based on machine vision is created to test the increased subpixel edge localization detection accuracy. Industrial computer, high-precision vision module, high-precision three-axis motion platform, and other mechanical structures make up the system.Figure 2
3C product shell workpiece image collection device.
(a)
Designed diagram(b)
PrototypeSelect the 3C product shell workpiece as the detecting object, and locate the round hole on the workpiece. Figure3 depicts the detection workpiece drawing. The workpiece measures 1718 mm in length and 58 mm in width and contains 39 threaded holes.Figure 3
Detection workpiece drawing.
(a)
Outer surface of the workpiece(b)
Inter surface of the workpiece


### 4.2. Image Preprocessing

The vision system is driven by a high-precision motion platform to collect comprehensive pictures on the super-long detection workpiece. The source image takes up a lot of storage space due to its high color dimension, which slows down image processing. Meanwhile, Gaussian and Poisson noises are easily generated in the workshop due to electromagnetic signals, light interference, and system internal operation, affecting the extraction of workpiece information in the image. When the picture is being preprocessed, the source image is grayed, filtered denoising, and thresholded in order to accurately extract the critical information of the original image and improve image processing speed.As shown in Figure4, the channel information of the original image with a resolution of 8192∗8192 was grayed according to weighted average. The grayscale image keeps the critical edge outline information, and the storage data is a quarter of the original image. In image processing, the running memory of the system is less, and the processing speed is faster than the original image.Figure 4
Grayscale.
(a)
Original image(b)
Grayscale imageIn view of the requirements of 3C workpiece detection, it is necessary to remove noise in the workpiece image during the image denoising process when we measure the position and size of screw holes on the source image of the target detection workpiece in this paper, but the edge features of the workpiece image and threaded hole features cannot be filtered out. Furthermore, median filtering is an excellent image denoising method [28]. Both iterative threshold segmentation and the OTSU threshold segmentation technique preserve the form of the picture contour better, as seen in Figure 5, but the former one is time-consuming. The OTSU is faster, and the segmentation is more precise. As a result, the OTSU approach is utilized to calculate thresholds.Figure 5
Threshold segmentation.
(a)
Original image(b)
Iterative threshold segmentation(c)
OTSU threshold segmentation


### 4.3. Result Analysis

On the basis of image preprocessing, an improved subpixel edge detection method is adopted to process local image of the target detecting workpiece. The findings are shown in Figure6 in comparison to the traditional Canny algorithm method. The presented approach has more evident local features for the detection of edge contours (line, circle) and is more in line with the edge of the genuine detected object, as is seen in the image comparison.Figure 6
Comparative study on the effect of improved subpixel detection algorithm.
(a)
Original image(b)
Traditional Canny edge detection(c)
Improved subpixel edge detectionTo further characterize the accuracy of pixel edge localization and subpixel edge localization, take the coordinates (1331.5, 1469.5) as the starting point on the edge contour of the detecting workpiece. Pick 6 points with a 1-pixel vertical coordinate step size and an unchanging horizontal coordinate. Each point is detected and located in the two approaches, and the detection results are displayed in Table1.Table 1
Pixel-level and subpixel-level edge positioning accuracy comparison.
Actual coordinatesx,yCanny detection coordinatesx,ySubpixel detection coordinatesx,y1331.51469.5133114691331.47281469.47421331.51470.5133114691131.38101469.37531331.51471.5133114711331.43991469.42281331.51472.5133114731331.39111469.40031331.51473.5133114731311.33231469.40101331.51474.5133114741311.35371469.3326It can be seen from Table1 that the detection accuracy of Canny edge detection just reaches pixel grade, but the positioning accuracy of improved Zernike moment subpixel edge method has greater improvement and can reach 0.1-0.3 pixels.


## 4.1. Experimental Setup

As illustrated in Figure2, a large-scale workpiece image acquisition hardware platform based on machine vision is created to test the increased subpixel edge localization detection accuracy. Industrial computer, high-precision vision module, high-precision three-axis motion platform, and other mechanical structures make up the system.Figure 2
3C product shell workpiece image collection device.
(a)
Designed diagram(b)
PrototypeSelect the 3C product shell workpiece as the detecting object, and locate the round hole on the workpiece. Figure3 depicts the detection workpiece drawing. The workpiece measures 1718 mm in length and 58 mm in width and contains 39 threaded holes.Figure 3
Detection workpiece drawing.
(a)
Outer surface of the workpiece(b)
Inter surface of the workpiece


## 4.2. Image Preprocessing

The vision system is driven by a high-precision motion platform to collect comprehensive pictures on the super-long detection workpiece. The source image takes up a lot of storage space due to its high color dimension, which slows down image processing. Meanwhile, Gaussian and Poisson noises are easily generated in the workshop due to electromagnetic signals, light interference, and system internal operation, affecting the extraction of workpiece information in the image. When the picture is being preprocessed, the source image is grayed, filtered denoising, and thresholded in order to accurately extract the critical information of the original image and improve image processing speed.As shown in Figure4, the channel information of the original image with a resolution of 8192∗8192 was grayed according to weighted average. The grayscale image keeps the critical edge outline information, and the storage data is a quarter of the original image. In image processing, the running memory of the system is less, and the processing speed is faster than the original image.Figure 4
Grayscale.
(a)
Original image(b)
Grayscale imageIn view of the requirements of 3C workpiece detection, it is necessary to remove noise in the workpiece image during the image denoising process when we measure the position and size of screw holes on the source image of the target detection workpiece in this paper, but the edge features of the workpiece image and threaded hole features cannot be filtered out. Furthermore, median filtering is an excellent image denoising method [28]. Both iterative threshold segmentation and the OTSU threshold segmentation technique preserve the form of the picture contour better, as seen in Figure 5, but the former one is time-consuming. The OTSU is faster, and the segmentation is more precise. As a result, the OTSU approach is utilized to calculate thresholds.Figure 5
Threshold segmentation.
(a)
Original image(b)
Iterative threshold segmentation(c)
OTSU threshold segmentation


## 4.3. Result Analysis

On the basis of image preprocessing, an improved subpixel edge detection method is adopted to process local image of the target detecting workpiece. The findings are shown in Figure6 in comparison to the traditional Canny algorithm method. The presented approach has more evident local features for the detection of edge contours (line, circle) and is more in line with the edge of the genuine detected object, as is seen in the image comparison.Figure 6
Comparative study on the effect of improved subpixel detection algorithm.
(a)
Original image(b)
Traditional Canny edge detection(c)
Improved subpixel edge detectionTo further characterize the accuracy of pixel edge localization and subpixel edge localization, take the coordinates (1331.5, 1469.5) as the starting point on the edge contour of the detecting workpiece. Pick 6 points with a 1-pixel vertical coordinate step size and an unchanging horizontal coordinate. Each point is detected and located in the two approaches, and the detection results are displayed in Table1.Table 1
Pixel-level and subpixel-level edge positioning accuracy comparison.
Actual coordinatesx,yCanny detection coordinatesx,ySubpixel detection coordinatesx,y1331.51469.5133114691331.47281469.47421331.51470.5133114691131.38101469.37531331.51471.5133114711331.43991469.42281331.51472.5133114731331.39111469.40031331.51473.5133114731311.33231469.40101331.51474.5133114741311.35371469.3326It can be seen from Table1 that the detection accuracy of Canny edge detection just reaches pixel grade, but the positioning accuracy of improved Zernike moment subpixel edge method has greater improvement and can reach 0.1-0.3 pixels.


## 5. Conclusions

This research proposes an enhanced Canny-Zernike moment algorithm to improve the measurement accuracy of target detecting workpieces. This improved detection approach can detect the edge and will not traverse the entire image, thus improving subpixel edge detection speed. Bilateral filtering is more suitable for noise reduction compared with other filtering methods. The output pixel value is derived by a weighted mixture of nearby pixel values thus improving the capability of Subpixel exact placement. A hardware platform for capturing large-scale workpiece image was created. The edge is measured with the enhanced Canny-Zernike subpixel detection method with a 3C large-size workpiece as the detection object. The results show that measurement accuracy can reach 0.1-0.3 pixels, which enhances edge placement accuracy and efficiency.



---

*Source: 1488406-2022-06-20.xml*