Image edge detection algorithm based on LSSVM-CA
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 n-dimensional vector and l samples, and their values in a region be represented as (x1, y1), ⋯⋯(xl, yl) ∈ Rn × R. First, a nonlinear map ψ(⋅) is used to map samples from the original space Rn to the feature space ψ(x) = (φ(x1), φ(x2), ⋯φ(xl)). 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 Remp 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: yi = φ(xi) ⋅ 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 ai, 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 \), ai = cζi, and
$$ w\cdot \phi \left({x}_i\right)+b+{\zeta}_i-{y}_i=0. $$
(5)
Defining kernel function K(xi, xj) = ϕ(xi) ⋅ ϕ(xj), K(xi, xj) 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({\left|r-{r}_i\right|}^2+{\left|c-{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 first-order 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({\left|r-{r}_i\right|}^2+{\left|c-{c}_i\right|}^2\right)/{\sigma}^2\right)+{dr}_i{\left(r\cdot {r}_i+c\cdot {c}_i\right)}^{d-1}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({\left|r-{r}_i\right|}^2+{\left|c-{c}_i\right|}^2\right)/{\sigma}^2\right)+{dc}_i{\left(r\cdot {r}_i+c\cdot {c}_i\right)}^{d-1}A\left(1-\Theta B\right)y $$
(13)
The matrix Wr and Wc calculations are introduced.
$$ {W}_r=\sum \limits_{i=1}^n\Big(-\frac{2}{\sigma^2}\left(r-{r}_i\right)\exp \left(-\left({\left|r-{r}_i\right|}^2+{\left|c-{c}_i\right|}^2\right)/{\sigma}^2\right)+{dr}_i{\left(r\cdot {r}_i+c\cdot {c}_i\right)}^{d-1}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({\left|r-{r}_i\right|}^2+{\left|c-{c}_i\right|}^2\right)/{\sigma}^2\right)+{dc}_i{\left(r\cdot {r}_i+c\cdot {c}_i\right)}^{d-1}A\left(1-\Theta B\right)y $$
(15)
It can be seen from the above derivation that the matrices Wr and Wc 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 Wr and Wc become gradient operators of the image. The gradient operators Wr, Wc, 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 fx and fy:
$$ 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 (Ccx, Ccy).
$$ {\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, Ccy) = Nt (Ccx, Ccy) that the evolution reaches a stable state and ends, and the edge pixel set of the image is obtained.
Application of LSSVM-CA 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, micro-size 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 LSSVM-CA 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 LSSVM-CA model, Gao Si curve fitting interpolation method in gradient direction can be used to locate sub-pixel level, and the accuracy is improved significantly.
Surface fitting is a method with high accuracy, low computation, and strong anti-noise performance, which has been widely used in various scenarios. Such as rock deformation measurement, electronic deformation measurement, and palmprint image correlation matching-based repeat location technology. The premise that the sub-pixel 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 sub-pixel 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,c0, c1 and σ0, σ1 are the mean and standard deviation in the x-axis and y-axis, 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.