## 2 Traditional Canny Algorithm and Its Improvement
### Improved Canny Algorithm
#### 2.2.2 Multi-Scale Analysis  
Edges in an image may exist at different scales. Small scales can detect detailed edges in the image, but are more sensitive to noise; large scales can detect the main edge structures in the image, and are relatively less sensitive to noise, but may lose some details. The purpose of multi-scale analysis is to integrate edge information at different scales to obtain more comprehensive and accurate edge detection results. The image pyramid is a very intuitive multi-scale representation structure, and multi-scale analysis is obtained by analyzing a series of images with different resolutions.  
By constructing an image pyramid, images with different resolutions (scales) can be obtained. The Sobel operator is applied to these images at different scales for edge detection, and then the results of these edge detections are fused so that while retaining edge details, the main edge structures can also be obtained.  
For the original image \(\mathrm{I}_{0}(\mathrm{x},\mathrm{y})\), an image pyramid is constructed. The calculation method of the k-th layer image \(\mathrm{I}_{\mathrm{k}}(\mathrm{x},\mathrm{y})\) is shown in Equation (2).  
\[\mathrm{I}_{\mathrm{k}}(\mathrm{x},\mathrm{y})=\mathrm{I}^{\prime}_{\mathrm{k -1}}(\mathrm{x},\mathrm{y})=\mathrm{I}_{\mathrm{k-1}}(\mathrm{x},\mathrm{y})* \mathrm{B}(\mathrm{i},\mathrm{j},\mathrm{k},\mathrm{l}) \tag{2}\]  
In the equation, \(\mathrm{I}^{\prime}_{\mathrm{k-1}}(\mathrm{x},\mathrm{y})\) denotes the bilateral filtering of \(\mathrm{I}_{\mathrm{k-1}}(\mathrm{x},\mathrm{y})\), \(*\) denotes the convolution operation, and \(\mathrm{B}(\mathrm{i},\mathrm{j},\mathrm{k},\mathrm{l})\) is the bilateral filtering function.  
Downsampling is then performed to obtain \(\mathrm{I}_{\mathrm{k}}(\mathrm{x},\mathrm{y})\). Downsampling usually involves reducing the rows and columns of the image by a certain percentage, taking one pixel point per row and column. In general, as \(\mathrm{k}\) increases, the scale of the image becomes smaller.  
For each layer of the image \(\mathrm{I}_{\mathrm{k}}(\mathrm{x},\mathrm{y})\) in the pyramid, the Sobel operator is applied to compute the gradient magnitude and direction. The Sobel operator has a horizontal template \(\mathrm{G}_{\mathrm{x}}=\begin{bmatrix}-1&0&1\\ -2&0&2\\ -1&0&1\end{bmatrix}\) and a vertical template \(\mathrm{G}_{\mathrm{y}}=\begin{bmatrix}-1&-2&-1\\ 0&0&0\\ 1&2&1\end{bmatrix}\).  
For image \(\mathrm{I}_{\mathrm{k}}(\mathrm{x},\mathrm{y})\), calculate the horizontal gradient \(\mathrm{G}_{\mathrm{x},\mathrm{k}}=\mathrm{I}_{\mathrm{k}}(\mathrm{x},\mathrm{ y})*\mathrm{G}_{\mathrm{x}}\), the vertical gradient \(\mathrm{G}_{\mathrm{y},\mathrm{k}}=\mathrm{I}_{\mathrm{k}}(\mathrm{x},\mathrm{ y})*\mathrm{G}_{\mathrm{y}}\) (here \(*\) also indicates convolution operation), the gradient magnitude \(\mathrm{G}_{\mathrm{k}}(\mathrm{x},\mathrm{y})=\sqrt{\mathrm{G}_{\mathrm{x}, \mathrm{k}}^{2}+\mathrm{G}_{\mathrm{y},\mathrm{k}}^{2}}\), and the gradient direction \(\mathrm{\theta}_{\mathrm{k}}=\arctan\left(\frac{\mathrm{G}_{\mathrm{y},\mathrm{k }}}{\mathrm{G}_{\mathrm{x},\mathrm{k}}}\right)\).  
The gradient magnitudes obtained at different scales are weighted and summed. Set \(\mathrm{G}_{\mathrm{final}}(\mathrm{x},\mathrm{y})=\sum_{\mathrm{k=0}}^{\mathrm{ N}-1}\omega_{\mathrm{k}}\mathrm{G}_{\mathrm{k}}(\mathrm{x},\mathrm{y})\), where N is the number of layers of the image pyramid and \(\omega_{\mathrm{k}}\) is the weight of the k-th layer, so that images at larger scales (lower layers) are weighted more heavily to emphasize major edge structures, while images at smaller scales (higher layers) are weighted less heavily to preserve detailed edges.