Image edge detection algorithm based on LSSVMCA
Construction of least squares support vector machine and its kernel function
The basic idea of SVM is to select a set of feature subsets of the training set (called support vector machine), which can separate classes and provide favorable conditions for classifier generation. At the same time, the complexity of operation is reduced while the classification accuracy is guaranteed. Compared with classical classification algorithms, SVM has obvious advantages in many aspects, such as preventing trained learning and computing speed, but it also has some limitations. So researchers put forward a lot of deformation algorithms of support vector machine; these deformation algorithms are mainly by adding function items, variables, or coefficients to deform the formula, so this chapter mainly describes the deformation algorithm.
Least squares support vector machine (LSSVM)
Let the sample be an ndimensional vector and l samples, and their values in a region be represented as (x_{1}, y_{1}), ⋯⋯(x_{l}, y_{l}) ∈ R^{n} × R. First, a nonlinear map ψ(⋅) is used to map samples from the original space R^{n} to the feature space ψ(x) = (φ(x_{1}), φ(x_{2}), ⋯φ(x_{l})). The optimal decision function y(x) = w ⋅ φ(x) + b is constructed in this high dimensional feature space. In this way, the nonlinear estimation function is transformed into the linear estimation function in the high dimensional feature space. Using the principle of structural risk minimization, finding the extremum of the weight vector w and the offset b is minimized:
$$ R=\frac{1}{2}\cdot {\left\Vert w\right\Vert}^2+c\cdot {R}_{\mathrm{emp}} $$
(1)
Among them, ‖w‖^{2} is the complexity of the control model, c is the regularization parameter, and R_{emp} is the error control function, that is, insensitive loss function.
Commonly used loss functions are linear ε loss function, quadratic ε loss function, and Huber loss function. Different types of support vector machines can be constructed by selecting different loss functions. The loss function of the least squares support vector machine in the optimization target is the quadratic term of the error ζ_{i}. Therefore, the optimization problem is:
$$ \min J\left(w,\zeta \right)=\frac{1}{2}w\cdot w+c\sum \limits_{i=1}^l{\zeta}_i^2 $$
(2)
s.t: y_{i} = φ(x_{i}) ⋅ w + b + ζ_{i}, i = 1, ⋯⋯, l.
The Lagrangian method is used to solve this optimization problem.
$$ L\left(w,b,a,\gamma \right)=\frac{1}{2}w\cdot w+c\sum \limits_{i=1}^l{\zeta}_i^2\sum \limits_{i=1}^l{a}_i\left(w\cdot \varphi \left({x}_i\right)+b+\zeta {y}_i\right) $$
(3)
among which a_{i}, i = 1, . . … , l, is the Lagrange multiplier.
According to the optimization conditions,
$$ \frac{\partial L}{\partial w}=0,\frac{\partial L}{\partial b}=0,\frac{\partial L}{\partial \zeta }=0,\frac{\partial L}{\partial a}=0 $$
(4)
acquirability \( w=\sum \limits_{i=1}^l{a}_i\phi \left({x}_i\right) \), \( \sum \limits_{i=1}^l{a}_i=0 \), a_{i} = cζ_{i}, and
$$ w\cdot \phi \left({x}_i\right)+b+{\zeta}_i{y}_i=0. $$
(5)
Defining kernel function K(x_{i}, x_{j}) = ϕ(x_{i}) ⋅ ϕ(x_{j}), K(x_{i}, x_{j}) is a symmetric function satisfying the Mercer condition. According to (5), the optimization problem is transformed into solving linear equations:
$$ \left[\begin{array}{cccc}0& 1& \cdots & 1\\ {}1& K\left({x}_1,{x}_1\right)+1/c& \cdots & K\left({x}_1,{x}_1\right)\\ {}\vdots & \vdots & \ddots & \vdots \\ {}1& K\left({x}_l,{x}_l\right)& \cdots & K\left({x}_l,{x}_l\right)+1/c\end{array}\right]\;\left[\begin{array}{c}b\\ {}{a}_1\\ {}\vdots \\ {}{a}_l\end{array}\right]=\left[\begin{array}{c}0\\ {}{y}_1\\ {}\vdots \\ {}{y}_l\end{array}\right] $$
(6)
Finally, the nonlinear model is obtained as follows:
$$ f(x)=\sum \limits_{i=1}^l{a}_iK\left(x,{x}_i\right)+b $$
(7)
The image fitting takes the M × N neighborhood of the pixel as the processing unit. Same as 3 ≤ M = N ≤ 9. The distance between the pixels in the neighborhood is expressed as Δr and Δc in the horizontal direction and the vertical direction, respectively. Δr ≤ \( \left\lfloor \frac{M}{2}\right\rfloor \) and \( \Delta c\le \left\lfloor \frac{M}{2}\right\rfloor \),因.
The coordinates of all pixels in the neighborhood can be expressed as (r Δ ROC Δ c),) and used as the input of LSSVM. The input of LSSVM can also be subtracted from the coordinate by (r + Δr, c + Δc) and replaced by (Δr, Δc), which is subtracted from the former coordinate.
If M and N are known, the constant vector space as input can be obtained. {(Δr,Δc)Δr ≤ \( \left\lfloor \frac{M}{2}\right\rfloor \) and \( \Delta c\le \left\lfloor \frac{M}{2}\right\rfloor \)}. The nonlinear relationship between input vectors and pixels can be constructed by LSSVM. Formula (3) is considered as a set of linear equations with a and B as unknown elements.
$$ \left\{\begin{array}{l}a={\left(K\left({x}_i,{x}_j\right)+{\gamma}^{1}I\right)}^{1}\left(y\Theta b\right)\\ {}b=\frac{\Theta^T{\left(K\left({x}_i,{x}_j\right)+{\gamma}^{1}I\right)}^{1}y}{\Theta^T{\left(K\left({x}_i,{x}_j\right)+{\gamma}^{1}I\right)}^{1}\Theta}\end{array}\right. $$
(8)
The matrices A and B are defined as follows:
$$ \left\{\begin{array}{l}A={\left(K\left({x}_i,{x}_j\right)+{\gamma}^{1}I\right)}^{1}\\ {}B=\frac{\Theta^T{\left(K\left({x}_i,{x}_j\right)+{\gamma}^{1}I\right)}^{1}}{\Theta^T{\left(K\left({x}_i,{x}_j\right)+{\gamma}^{1}I\right)}^{1}\Theta}\end{array}\right. $$
(9)
Then, the expression can be expressed as follows:
$$ \left\{\begin{array}{l}a=A\left(y\Theta b\right)\\ {}b= By\end{array}\right. $$
(10)
It can be seen from the above derivation that the calculation of matrices A and B is independent of the output y, that is, independent of the gray value of the pixel, related to the input quantity, the type of kernel function, and γ. From the above, the number of samples in the constant vector space is known and fixed, and γ is constant, so once the kernel function is determined, the matrices A and B can be obtained in advance. The matrices A and B only need to be solved once, and the matrix is globally universal, which is essentially a constant matrix. Next, the selected kernel function can be used for image fitting. Let Row × Col be the constant vector space of a pixel symmetric neighborhood of the image to be processed. Like Row = {− 1,0,1}, Col = {− 1,0,1}. The kernel function constructed by the formula is represented as the image gray fitting function in the constant vector space as follows:
$$ f\left(r,c\right)=\sum \limits_{i=1}^n{a}_i\left(\exp \left(\left({\leftr{r}_i\right}^2+{\leftc{c}_i\right}^2\right)/{\sigma}^2\right)+{\left(r\cdot {r}_i+c\cdot {c}_i+1\right)}^d\right)+b $$
(11)
In the formula, f (ROC) is the gray level estimate of the corresponding point (ROC), and (ri, ci) is the pixel coordinate as input. For the point (RFC), the firstorder partial derivative of the image gray fitting function in horizontal and vertical direction can be obtained:
$$ \frac{\partial f}{\partial r}=\sum \limits_{i=1}^n\Big(\frac{2}{\sigma^2}\left(r{r}_i\right)\exp \left(\left({\leftr{r}_i\right}^2+{\leftc{c}_i\right}^2\right)/{\sigma}^2\right)+{dr}_i{\left(r\cdot {r}_i+c\cdot {c}_i\right)}^{d1}A\left(1\Theta B\right)y $$
(12)
$$ \frac{\partial f}{\partial r}=\sum \limits_{i=1}^n\Big(\frac{2}{\sigma^2}\left(c{c}_i\right)\exp \left(\left({\leftr{r}_i\right}^2+{\leftc{c}_i\right}^2\right)/{\sigma}^2\right)+{dc}_i{\left(r\cdot {r}_i+c\cdot {c}_i\right)}^{d1}A\left(1\Theta B\right)y $$
(13)
The matrix W_{r} and W_{c} calculations are introduced.
$$ {W}_r=\sum \limits_{i=1}^n\Big(\frac{2}{\sigma^2}\left(r{r}_i\right)\exp \left(\left({\leftr{r}_i\right}^2+{\leftc{c}_i\right}^2\right)/{\sigma}^2\right)+{dr}_i{\left(r\cdot {r}_i+c\cdot {c}_i\right)}^{d1}A\left(1\Theta B\right)y $$
(14)
$$ {w}_c=\sum \limits_{i=1}^n\Big(\frac{2}{\sigma^2}\left(c{c}_i\right)\exp \left(\left({\leftr{r}_i\right}^2+{\leftc{c}_i\right}^2\right)/{\sigma}^2\right)+{dc}_i{\left(r\cdot {r}_i+c\cdot {c}_i\right)}^{d1}A\left(1\Theta B\right)y $$
(15)
It can be seen from the above derivation that the matrices W_{r} and W_{c} are similar to the matrices A and B and independent of the gray value y of the pixels, and related to the input quantity and the type of kernel function, so they can be obtained in advance and become a constant matrix. They are transformed into square arrays with the same size as the pixel (rc) neighborhood Row × Col, and W_{r} and W_{c} become gradient operators of the image. The gradient operators W_{r}, W_{c}, and the image matrix I (ROC) are used for convolution calculation, and the gradient value matrices GH (ROC) and GV (ROC) in the horizontal and vertical directions of the image are obtained.
$$ {G}_H={W}_H\times I $$
$$ {G}_V={W}_c\times I $$
An algorithm of image edge detection based on CA
You might as well keep in mind: ▽f(x, y) = \( \frac{\partial f}{\partial x}i \) + \( \frac{\partial f}{\partial y}j \) is the gradient of the image, ▽f(x, y) contains grayscale change information: as ▽f(x, y)’s g radient, and e(x, y) can be used as edge detection operator. To simplify the calculation, e(x, y) can also be defined as the sum of the absolute derivatives of partial derivatives f_{x} and f_{y}:
$$ e\left(x,y\right)=\mid {f}_x\left(x,y\right)\mid +\mid {f}_y\left(x,y\right)\mid $$
(16)
On the basis of the above formula theory, many algorithms are proposed. The commonly used edge detection methods are the Roberts edge detection operator, Sobel edge detection operator, Prewitt edge detection operator, Canny edge detection operator, Laplace edge detection operator, and so on. However, the traditional method of edge detection has some drawbacks in time and complexity, so this paper uses CA to detect the image edge.
According to the characteristics of the edge, the gradient value of the pixel on the edge has its particularity (which should be the largest in its corresponding neighborhood), so it is an important information for edge detection. When using 2D CA to detect the edge of gray image, the image gradient value of the matrix obtained from the above formula is regarded as the processing object, and the image gradient value is mapped to the cellular space as the initial state value, so the finite state set is S = {0, …,255} neighborhood selection Von Neumann type, so the size of cell space vector N is 4. Evolution rule R is the key to the algorithm, using evolutionary rules to operate; when the evolution stops, we get the final results of edge detection. First, according to the gradient value, the cells are divided into four categories, expressed as GCi, I ∈{1, 2, 3, 4}.
The rules of evolution are as follows:

1)
Classifies all the cells in the central cell neighborhood into the corresponding category.

2)
The number of cells belonging to the GCi class in the neighborhood is calculated and expressed as Num (GCi).

3)
Call the maximum value algorithm to get the class that contains the maximum number of cells in the neighborhood and assign it to GCmajority.

4)
St (GCmajority) is defined to record the cellular state of the neighborhood cell belonging to the GCmajority class at t time.

5)
Seeking st (GCmajority) and Sum (st (GCmajority).

6)
Find the value of the Boolean expression Bool = (max (Num(GCi)) = GCmajority) and (Sum(st(GCmajority)) > 254)

7)
According to the result of Bool, we give different gray values of T + 1 time center cell (C_{cx}, C_{cy}).
$$ {\displaystyle \begin{array}{l}{N}^{t+1}\left({C}_{\mathrm{cx}},{C}_{\mathrm{cy}}\right)=R\left({N}^t\left({C}_{\mathrm{cx}},{C}_{\mathrm{cy}}\right)\right)\\ {}=R\left({{S^t}_C}_{\mathrm{cx}}+{0}_{,}{C}_{\mathrm{cy}}+0,{{S^t}_C}_{\mathrm{cx}}+{0}_{,}{C}_{\mathrm{cy}}+1,{{S^t}_C}_{\mathrm{cx}}+{1}_{,}{C}_{\mathrm{cy}}+0,{{S^t}_C}_{\mathrm{cx}}+{0}_{,}{C}_{\mathrm{cy}}1,{{S^t}_C}_{\mathrm{cx}}{1}_{,}{C}_{\mathrm{cy}}+0\right)\\ {}={{S^t}_C}_{\mathrm{cx}}+{0}_{,}{C}_{\mathrm{cy}}+0\end{array}} $$
(17)

8)
It is not until Nt 1 (cx, C_{cy}) = Nt (C_{cx}, C_{cy}) that the evolution reaches a stable state and ends, and the edge pixel set of the image is obtained.
Application of LSSVMCA model in image dimension measurement
In recent years, image measurement technology has been developed rapidly at home and abroad. It has been widely used in part of geometric parameter measurement, microsize measurement and appearance detection of precision parts, aerial remote sensing images, light wave interferogram, and the stress and strain field distribution map analysis and many other aspects. The high resolution, high sensitivity, wide spectral response, and large dynamic range of image size measurement system are difficult to compare with traditional measurement methods. Different image processing and analysis methods as well as different detection methods and calculation formulas will bring different errors. In this paper, the LSSVMCA model is applied to measure the image size of precision parts to verify whether the appearance size is up to standard. On the basis of edge detection of LSSVMCA model, Gao Si curve fitting interpolation method in gradient direction can be used to locate subpixel level, and the accuracy is improved significantly.
Surface fitting is a method with high accuracy, low computation, and strong antinoise performance, which has been widely used in various scenarios. Such as rock deformation measurement, electronic deformation measurement, and palmprint image correlation matchingbased repeat location technology. The premise that the subpixel displacement can be successfully calculated by surface fitting method is that the whole pixel matching point of the template can be correctly searched in the whole pixel search stage, and once there is an error in the whole pixel matching point search, then the displacement distance from the subpixel measurement phase will be meaningless. Using different fitting functions to fit the correlation coefficient matrix will have a certain influence on the results. The commonly used fitting functions include quadratic function, cubic function, and Gao Si function. In this paper, Gao Si function is used for surface fitting.
The binary Gao Si function can be represented as follows:
$$ f\left(x,y\right)=A\bullet \exp \left[\frac{{\left(x{c}_0\right)}^2}{2{\sigma_0}^2}\frac{{\left(y{c}_1\right)}^2}{2{\sigma_1}^2}\right] $$
(18)
where A is the amplitude,c_{0}, c_{1} and σ_{0}, σ_{1} are the mean and standard deviation in the xaxis and yaxis, respectively. On solving functions f(x, y) coefficient in the logarithms on the two sides of the upper equal sign can be obtained:
$$ Inf= InA\frac{{\left(x{c}_0\right)}^2}{2{\sigma_0}^2}\frac{{\left(y{c}_1\right)}^2}{2{\sigma_1}^2} $$
(19)
$$ Inf= InA\frac{{c_0}^2}{2{\sigma_0}^2}\frac{{c_1}^2}{2{\sigma_1}^2}+\frac{{c_0}^2}{{\sigma_0}^2}x+\frac{{c_1}^2}{{\sigma_1}^2}y\frac{1}{2{\sigma_0}^2}{x}^2\frac{1}{2{\sigma_1}^2}{y}^2 $$
(20)
Bring the following into
$$ {\lambda}_0= InA\frac{{c_0}^2}{2{\sigma_0}^2}\frac{{c_1}^2}{2{\sigma_1}^2},{\lambda}_1=\frac{{c_0}^2}{{\sigma_0}^2},{\lambda}_2=\frac{{c_1}^2}{{\sigma_1}^2},{\lambda}_3=\frac{1}{2{\sigma_0}^2},{\lambda}_3=\frac{1}{2{\sigma_1}^2} $$
(21)
The formula can be transformed into:
$$ Inf={\lambda}_0+{\lambda}_1x+{\lambda}_2y+{\lambda}_3{x}^2+{\lambda}_4{y}^2 $$
(22)
Using the position in the fitting window and the corresponding correlation coefficient, n × n equations can be obtained. Using the least squares method, the coefficient λ_{0}, λ_{1}, λ_{2}, λ_{3}, λ_{4}, λ_{5}, of the equation can be calculated and the coefficients of the Gaussian function can be obtained.