# Segmentation of River Scenes Based on Water Surface Reflection Mechanism
## 2 Materials and Methods
### Improved Local Binary Pattern Feature  
The water part in an image tends to present simpler textures. Some studies utilize this characteristic to segment water bodies. The common texture features include gray-level co-occurrence matrix (GLCM) [25], Laws' Mask [26], Local Binary Pattern (LBP) [27] and so on. The study of the water surface reflection mechanism in the previous section shows that the appearance of the water region changes spatially. Consequently, the results of the textural descriptors calculated from the whole image, such as GLCM, for water region in an image would have a distinct numerical difference. LBP constructs a local feature descriptor that reflects the magnitude relationship between the center pixel and the neighborhood ones, which can effectively deal with the inhomogeneous appearance in an image, and establish a more reliable description for an image patch. Based on the water surface reflection mechanism discussed previously, an improved LBP feature is designed to describe the spatial characteristics of water appearance and then used to detect the water part of an image. To obtain the improved LBP feature, the image is firstly divided into several patches of a specified size, and then each patch is further divided into 9 blocks. The pixel value(or the average value) in each block is denoted as \(I_{k}\), \(k=1,2,3,...,9\) as shown in Figure 5.  
The traditional LBP feature compares the values of center block pixel \(I_{5}\) with the neighborhood ones and encodes them into a binary string. However, the comparison results are in different weights for different directions. Therefore, the proposed algorithm improves traditional LBP feature, as shown in Algorithm 1. It is designed based on the qualitative law that the pixel values decrease from far to near and the pixel values at the same distance to the camera are close. Figure 4: Pixel-wise intensity values and hue values in a column of river scene image. Figure 5: Illustration of generation of image patches. ```
0: gray-scale image patch in matrix form
0: 8-dimension feature
1: divide the image into 9 equal-size blocks with pixel value \(I_{k},k=1,2,3,...,9\)
2:if\(|I_{1}-I_{2}|<1\%*I_{1}\)and \(|I_{2}-I_{3}|<1\%*I_{2}\)then
3:\(f_{1}=1\)
4:else
5:\(f_{1}=0\)
6:if\(|I_{4}-I_{5}|<1\%*I_{4}\)and \(|I_{5}-I_{6}|<1\%*I_{5}\)then
7:\(f_{2}=1\)
8:else
9:\(f_{2}=0\)
10:if\(|I_{7}-I_{8}|<1\%*I_{7}\)and \(|I_{8}-I_{9}|<1\%*I_{8}\)then
11:\(f_{3}=1\)
12:else
13:\(f_{3}=0\)
14:if\(|I_{4}-I_{1}|\approx|I_{5}-I_{2}|\approx I_{6}-I_{3}\)then
15:\(f_{4}=1\)
16:else
17:\(f_{4}=0\)
18:if\(|I_{7}-I_{4}|\approx|I_{8}-I_{5}|\approx I_{9}-I_{6}\)then
19:\(f_{5}=1\)
20:else
21:\(f_{5}=0\)
22:if\(I_{1}>I_{4}>I_{7}\)then
23:\(f_{6}=1\)
24:else
25:\(f_{6}=0\)
26:if\(I_{2}>I_{5}>I_{8}\)then
27:\(f_{7}=1\)
28:else
29:\(f_{7}=0\)
30:if\(I_{3}>I_{6}>I_{9}\)then
31:\(f_{8}=1\)
32:else
33:\(f_{8}=0\)
34:return\(f=[f_{1},f_{2},f_{3},f_{4},f_{5},f_{6},f_{7},f_{8}]\)
```  
**Algorithm 1** Improved LBP feature  
In the improved LBP calculation, the features \(f_{1}\), \(f_{2}\), and \(f_{3}\) indicate that the \(I\) values of every row in the image patch are very close because the water pixels from a similar distance have almost the same reflected energy to the camera. While the pixel value differences in the vertical direction in the patch are numerically similar, as the meaning by \(f_{4}\) and \(f_{5}\), since the distance between adjacent pixels is small enough to neglect the gap. Moreover, the father pixel theoretically has a larger pixel value than that of a closer one, as the meaning of \(f_{6}\), \(f_{7}\), and \(f_{8}\). Finally, to overcome the drawback that the relationship of different directions in the traditional LBP has different weights, the improved LBP sums the obtained Boolean results \(f_{i},i=1,2,3,...,8\) as a score \(F\) :  
\[F=\sum_{i=1}^{8}f_{i}. \tag{13}\]After all, an appropriate threshold \(T_{1}\) is adopted to compare with the obtained score \(F\) to decide whether the patch is part of water or not, which can be formulated as follows:  
\[\left\{