# Fast Segmentation Algorithm for Cytoid Macular Edema Based on Omnidirectional Wave Operator
## 2 Methods
### Image Segmentation
#### 2.3.2 Contour Extraction by Omnidirectional Wave Operator  
The basic idea of the wave algorithm is to transform the gray value of pixels into the potential energy of fluid mechanics. By modifying the potential energy equation of fluid mechanics, it has good applicability in image applications. In the fluid potential energy equation (Formula (2)), \(g\) is gravity acceleration, \(h\) is fluid height, \(gh\) is gravity potential energy (\(\varphi_{g}\)), \(p\) is fluid pressure, \(\rho\) is the fluid density, \(p/\rho\) represents pressure potential energy, \(v\) is the fluid velocity, and \(v^{2}/2\) represents kinetic energy. \[\varphi=gh+(p/\rho)+(v^{2}/2) \tag{2}\]  
In the image, the pixel is analogized as fluid particles. Since the pixel is square, the density \(\rho=1\), and the z-axis of the image in three-dimensional space is set as a gray value, then the pressure \(p=0\) at H height, and the fluid pressure energy is \(p/\rho=0\). The traditional fluid potential energy equation evolves the wave potential energy equation (Formula (3)) and the wave correction equation (Formula (4)) for the image process. The fluid velocity (\(v\)) is replaced by the normalized gray difference value (\(v\) and \(v_{q}\)), \(v\) is the fluid velocity in the 3 \(\times\) 3 template, and \(v_{q}\) is the fluid velocity in the 3 \(\times\) 2 template which is located in front of the central pixel. \(\sigma\) is the speed regulation factor. A set of points containing boundary lines can be obtained by the wave potential energy equation, and the wave correction equation can extract boundary lines from the set of points. \[wave=\varphi_{v}+\varphi_{g}=v\cdot v_{q}\cdot\sigma+\varphi_{g} \tag{3}\]  
\[P_{energy}=\left\{ \begin{array}{cc}1&(K>1)\cap(C>1)\\ 0&\quad\text{\emph{other}}\end{array} \right. \tag{4}\]  
When extracting the contour of the target area, the wave algorithm can only extract curves whose tangent direction is vertical to the operation direction. In the segmentation of the ten-layer structure of the retina, the boundary line of the retinal inter-layer structure is approximately vertical to the operation direction, so the wave algorithm can effectively extract the retinal layer structure. However, for a vertical biconvex oval or transverse spindle-shaped structure such as CME, the wave algorithm can only extract the curve vertical to the operation direction, so it cannot obtain the complete contour. Aiming at the unidirectional problem of the wave algorithm, this paper puts forward an omnidirectional wave operator and adds a direction adjustment function, which makes the wave algorithm have the ability to extract closed curves. An omnidirectional wave operator can perform the omnidirectional operation on the target in four directions. Specifically, the parameters in the equation are transformed by the direction adjustment function (Formula (5)), \((i,j)\) is the pixel coordinate in the image, and \((i^{\prime},j^{\prime})\) is the pixel coordinate after direction adjustment. \(\theta\) is the rotation angle, and the positive angle is counterclockwise and the negative angle is clockwise. \(\theta\) is set to 0, \(\pi/2\), \(\pi\), \(3\pi/2\) in turn. \[\left( \begin{array}{c}i^{\prime}\\ j^{\prime}\\ 1\end{array} \right)=A\left( \begin{array}{c}i\\ j\\ 1\end{array} \right)=\left( \begin{array}{cc}\cos\theta&-\sin\theta&0\\ \sin\theta&\cos\theta&0\\ 0&0&1\end{array} \right)\left( \begin{array}{c}i\\ j\\ 1\end{array} \right) \tag{5}\]  
To give an example to gain a better understanding of the direction adjustment function, \(A\) rotates \(\theta\) degrees counterclockwise to \(A^{\prime}\) (Figure 4). The mathematical relationship between the coordinates of point \(A\), the coordinates of point \(A^{\prime}\), and the rotation angle \(\theta\) can be obtained by operating in polar coordinates. The mathematical relationship can be written as a matrix, as shown in Formula (5).