# Deep Visual Waterline Detection for Inland Marine Unmanned Surface Vehicles
## 3 Methodology
### Our Waterline Detection Algorithm Based on DeepWL  
As stated before, WLdetectNet performs as the mainstay of the paradigm DeepWL for our vision-based waterline detection, whereas its receptive field is constrained to the same region as WLpeephole whose size is fixed in practical applications. Thereby, our proposed paradigm DeepWL is more applicable for distinguishing segments relevant to a waterline, i.e., determining if there is a waterline segment in the detected image region.  
Given that the size of an image captured from USVs may be arbitrary, we present a waterline detection algorithm based on DeepWL, which pursues waterline image-map estimation from a single video stream captured on board. The algorithm is summarized in Algorithm 1, which results in a corresponding waterline estimation image-map (see Figure 1). In the algorithm, we formulate the task on waterline image-map estimation as a sequence of repetitive subtasks on distinguishing waterline segments in every handled video frame, wherein each subtask is conducted by taking advantage of DeepWL that implicitly consists of two stages: estimating a potential waterline segment via WLpeephole and marking the associated waterline segment via a specific strategy. Indeed, a waterline usually can be deemed as the combination of a spectrum of line segments.  
```
Single video stream \(X=\left\{x_{t}\right\}_{t=1:k}\), sampling rate \(f\), scale of WLpeephole \(r\), stride of WLpeephole moving in every image \(h\), WLdetectNet and its learned parameters \(C_{W}\) (according to Section 3.3).
``` A sequence of waterline estimation image-maps \(Y=\left\{y_{i}\right\}_{i=1:k/f}\). Procedure:
1: Sample \(X=\left\{x_{t}\right\}_{t=1:k}\) online according to sampling rate \(f\), which can eventually derive a corresponding sequence of images \(Z=\left\{z_{i}\right\}_{i=1:k/f}\).
2: Take the currently derived frame \(z_{i}\) by sampling as an image to be detected.
3: Initialize the placement of WLpeephole within \(z_{i}\) to be at the upper left corner of \(z_{i}\).
4: Fetch the image region (denoted as \(b\)) corresponding to WLpeephole as the current receptive field of WLdetectNet \(C_{W}\).
5: Apply WLdetectNet \(C_{W}\) to estimate if there is a waterline segment in \(b\) according to Section 3.1, i.e., derive the value of \(C_{W}(b)\).
6: If the label of \(C_{W}(b)\) corresponds to waterline, mark \(b\) according to a strategy: mark the central pixel of \(b\), else not.
7: Move WLpeephole (vertically or horizontally) to a new placement within \(z_{i}\), according to stride \(h\).
8: Iterate steps 4 to 7 until WLpeephole moving to the lower right corner of \(z_{i}\).
9: Connect all marked pixels within \(z_{i}\) as an estimated waterline, then output \(z_{i}\) to be the current waterline estimation image-map \(y_{i}\).
10: Iterate steps 2 to 9 until \(i=k/f\). ```  
**Algorithm 1**W**Waterline Detection Algorithm  
Thus, the performance of the algorithm depends to a large extent on the main network of our paradigm DeepWL, whose effectiveness and efficiency are put forward in this paper by the aforementioned two significant schemes relevant to WLdetectNet with the assistance of WLgenerateNet. Furthermore, in order to accelerate waterline image-map estimation from a single video stream, we do not resort to handling every frame of a single video stream in the algorithm. Meanwhile, in case of needing to present more fine-grained marking effect of a waterline in every estimation image-map, we can also opt a more considerate marking strategy to the algorithm. Notwithstanding in Algorithm 1 we employ a relatively simple marking strategy to rapidly approximate potential waterlines, it is actually enough for demands of some USVs.