# Image Interpolation Based on Spiking Neural Network Model
## 4 Proposed Method
### Image Interpolation with SNN-Based Edge Detection  
The method used for image interpolation in this study includes the steps shown in Figure 6. In general, these steps have been frequently included in recent studies in the field of interpolation in the literature. The most important difference of the proposed method is that it determines the edges and edge directions with an SNN model. In the first step, gray-level conversion is performed for \(I_{L}\). Then, the edges of the gray-level image in four different directions are determined by the proposed SNN model. Afterward, whether the pixel is an edge pixel or a non-edge pixel is checked. If the pixel is marked as an edge pixel, its direction is determined.  
While checking the edge or non-edge status of the pixel, it is needed to first examine whether it is included in one of the diagonal or linear edges.  
\[\theta(2i,2j)=\left\{\begin{matrix}45^{\circ}&\text{if }F_{45}(i,j)>F_{135}(i,j)\\ 135^{\circ}&\text{if }F_{45}(i,j)<F_{135}(i,j)\end{matrix}\right. \tag{13}\]  
Figure 5: Edge outputs of proposed SNN model for cameraman image \(I_{L}\). (**a**) \(F_{0}\): (**b**) \(F_{90}\); (**c**) \(F_{45}\); (**d**) \(F_{135}\).  
Figure 6: Flowchart of the proposed method.  
If there is no difference between the values of \(F_{45}(i,j)\) and \(F_{135}(i,j)\), which are the SNN outputs of the gray-level transform of the IL image in Equation (13), the pixel in \(I_{H}(2i,\) 2\(j)\) is considered a non-edge pixel and no assignment is performed. If \(F_{45}(i,j)\) is greater than \(F_{135}(i,j)\), \(\theta(2i,\) 2\(j)\) is assigned \(45^{\circ}\), whereas otherwise, it is assigned \(135^{\circ}\). The same procedure is then performed for the pixels \(I_{H}(2i-1,\) 2\(j)\) and \(I_{H}(2i,\) 2\(j-1)\) whose known neighbors are horizontal and vertical.  
\[\theta(2i,2j-1)=\theta(2i-1,2j)=\left\{\begin{array}{ll}0^{\circ}&\text{if }F_{0}(i,j)>F_{90}(i,j)\\ 90^{\circ}&\text{if }F_{0}(i,j)<F_{90}(i,j)\end{array}\right. \tag{14}\]  
In Equation (14), if \(F_{90}(i,j)\) and \(F_{0}(i,j)\), which are the SNN outputs of the gray-level transform of the \(I_{L}\) image, are equal to each other, then, \(I_{H}(2i-1,\) 2\(j)\) and \(I_{H}(2i,\) 2\(j-1)\) are defined as non-edge pixels. If \(F_{90}(i,j)\) is greater than \(F_{0}(i,j)\), \(\theta(2i-1,\) 2\(j)\) and \(\theta(2i,\) 2\(j-1)\) are assigned \(90^{\circ}\), they are assigned \(0^{\circ}\) otherwise.  
After the edge directions are detected, firstly, the pixels at \(I_{L}(i,j)\) are transferred to \(I_{H}(2i-1,\) 2\(j-1)\) as shown in Figure 2b. Then, the same operations are applied to the pixels in Figure 2c,d, respectively. Thus, all the pixels marked as edges are interpolated. If the pixels \(I_{H}(2i,\) 2\(j)\), \(I_{H}(2i,\) 2\(j-1)\), and \(I_{H}(2i-1,\) 2\(j)\) are marked as edges, their values are calculated using Equations (15)-(19), which have also been used in different studies [12,14].  
\[I_{H}=w(I_{a}+I_{b})+(0.5-w)(I_{c}+I_{d}) \tag{15}\]  
where \(w\) is an interpolation coefficient, and its value is 0.575 [12,14]. Let us assume that the indices of the \(2M\times 2N\)-sized \(I_{H}\) image are \(p\) and \(q\). If \(\theta(p,q)\) has an angle of \(45^{\circ}\):  
\[I_{a} =I_{H}(p-1,q-1),\ I_{b}=I_{H}(p+1,q+1) \tag{16}\] \[I_{c} =I_{H}(p-3,q-3),\ I_{d}=I_{H}(p+3,q+3)\]  
If \(\theta(p,q)=135^{\circ}\):  
\[I_{a} =I_{H}(p+1,q-1),\ I_{b}=I_{H}(p-1,q+1) \tag{17}\] \[I_{c} =I_{H}(p+3,q-3),\ I_{d}=I_{H}(p-3,q+3)\]  
If \(\theta(p,q)=0^{\circ}\):  
\[I_{a} =I_{H}(p,q-1),\ I_{b}=I_{H}(p,q+1) \tag{18}\] \[I_{c} =I_{H}(p,q-3),\ I_{d}=I_{H}(p,q+3)\]  
If \(\theta(p,q)=90^{\circ}\):  
\[I_{a} =I_{H}(p-1,q),\ I_{b}=I_{H}(p+1,q) \tag{19}\] \[I_{c} =I_{H}(p-3,q),\ I_{d}=I_{H}(p+3,q)\]  
Finally, bicubic interpolation is applied for the \(I_{H}(2i,2j)\), \(I_{H}(2i,2j-1)\), and \(I_{H}(2i-1,2j)\) pixels, which are marked as non-edge, and an \(I_{H}\) image is obtained. In this study, the interpolation process refers to \(2\times 2\) upsampling.