# SNR Analysis for Quantitative Comparison of Line Detection Methods
## 3 Method--SNR of ED and SD for Line Detection
### Measure of Noise Strengths
#### 3.3.2 Measure of Noise in Derivatives  
To extract edges or lines, the calculation of the first and second derivatives is typically performed after smoothing. While calculating the first and second derivatives, the post-smoothing residual noise propagates, which should be quantified for computing the SNR of ED-based and SD-based line detections. Calculating the first and second derivatives in an image is implemented by applying a convolution of certain kernels to the image. In this study, the kernels with size \(3\times 3\) are used for the implementation. Accordingly, to investigate the propagation of noise, while calculating the first and second derivatives, it is necessary to consider the smoothed noises in the \(3\times 3\) neighborhood at each pixel as follows:  
\[(\mathbf{n}*\mathbf{s})_{3\times 3}=\begin{bmatrix}(\mathbf{n}*\mathbf{s})_{1}&( \mathbf{n}*\mathbf{s})_{2}&(\mathbf{n}*\mathbf{s})_{3}\\ (\mathbf{n}*\mathbf{s})_{4}&(\mathbf{n}*\mathbf{s})_{5}&(\mathbf{n}*\mathbf{s })_{6}\\ (\mathbf{n}*\mathbf{s})_{7}&(\mathbf{n}*\mathbf{s})_{8}&(\mathbf{n}*\mathbf{s })_{9}\end{bmatrix}, \tag{27}\]  
where \(i\) in \((\mathbf{n}*\mathbf{s})_{i}\) is the unique sequential number assigned to each pixel within a \(3\times 3\) kernel. After rearranging the pixels in a vector ordered by their sequential numbers, their correlations are calculated by Equation (26) by considering their distance, and transformed into a correlation matrix, \(\mathbf{R}_{(\mathbf{n}*\mathbf{s})_{3\times 3}}\) as follows:  
\[\begin{split}\mathbf{R}_{(\mathbf{n}*\mathbf{s})_{3\times 3}} \\ =&\begin{bmatrix}1&\rho_{1}&\rho_{2}&\rho_{1}&\rho_{\sqrt{2}}&\rho_{\sqrt{5}}&\rho_{2}&\rho_{ \sqrt{5}}&\rho_{2}\sqrt{2}\\ &1&\rho_{1}&\rho_{\sqrt{2}}&\rho_{1}&\rho_{\sqrt{2}}&\rho_{\sqrt{5}}&\rho_{2}&\rho_{ \sqrt{5}}\\ &&1&\rho_{\sqrt{5}}&\rho_{\sqrt{2}}&\rho_{1}&\rho_{2\sqrt{2}}&\rho_{\sqrt{5}}&\rho_{2}\\ &&1&\rho_{1}&\rho_{2}&\rho_{1}&\rho_{\sqrt{2}}&\rho_{\sqrt{5}}\\ &&&1&\rho_{1}&\rho_{\sqrt{2}}&\rho_{1}&\rho_{\sqrt{2}}\\ &&&1&\rho_{\sqrt{5}}&\rho_{\sqrt{2}}&\rho_{1}\\ &&\text{Sym.}&&1&\rho_{1}&\rho_{2}\\ &&&&&1&\rho_{1}\\ &&&&&&&1\end{bmatrix}.\end{split} \tag{28}\]To calculate the first derivative in the column direction, this study used a scaled Sobel operator such that it should produce the gradient for one pixel unit as follows:  
\[\mathbf{D_{c}}=\frac{1}{8}\begin{bmatrix}-1&0&1\\ -2&0&2\\ -1&0&1\end{bmatrix}. \tag{29}\]  
The kernel in Equation (29) can be rewritten in its vector form as follows:  
\[\mathbf{V_{D_{c}}}=\text{vec}\Big{(}\mathbf{D_{c}^{T}}\Big{)}. \tag{30}\]  
Then, the dispersion \(\sigma_{\mathbf{n_{s}s+D_{c}}}^{2}\) of the noise resulting from the convolution of the smoothed noise with the kernel in Equation (29) can be quantitatively derived as follows:  
\[\sigma_{\mathbf{n_{s}s+D_{c}}}^{2}=\sigma_{\mathbf{n_{s}s}}^{2}\mathbf{V_{D_{c }}^{T}}\mathbf{R_{(n_{s}s)_{3:3}}}^{2}\mathbf{V_{D_{c}}}=\frac{\sigma_{n}^{2} }{64\pi\sigma_{s}^{2}}(3+4\rho_{1}-2\rho_{2}-4\rho_{\sqrt{5}}-\rho_{2\sqrt{2}}). \tag{31}\]  
Moreover, to calculate the second derivative in the column direction, this study used the following kernel such that it should produce the second derivative for one pixel unit, defined as follows:  
\[\mathbf{D_{cc}}=\frac{1}{4}\begin{bmatrix}1&-2&1\\ 2&-4&2\\ 1&-2&1\end{bmatrix}. \tag{32}\]  
The kernel in Equation (32) can be represented in the vector form as follows:  
\[\mathbf{V_{D_{cc}}}=\text{vec}\Big{(}\mathbf{D_{cc}^{T}}\Big{)}. \tag{33}\]  
Then, the dispersion \(\sigma_{\mathbf{n_{s}s+D_{cc}}}^{2}\) of the noise resulting from the convolution of the smoothed noise with the kernel in Equation (32) can be quantitatively derived as follows:  
\[\sigma_{\mathbf{n_{s}s+D_{cc}}}^{2}=\sigma_{\mathbf{n_{s}s}}^{2}\mathbf{V_{D_{ cc}^{T}}}\mathbf{R_{(n_{s}s)_{3:3}}}^{2}\mathbf{V_{D_{cc}}}=\frac{\sigma_{n}^{2} }{16\pi\sigma_{s}^{2}}(9-16\rho_{\sqrt{2}}+6\rho_{2}+\rho_{2\sqrt{2}}). \tag{34}\]