## 2 Detection Model
### Foreground Motion Blocks Extraction
#### 2.1.1 Sampling Areas Determination
When each cluster's size satisfies that \(|\tilde{\epsilon}_{j}|\geq N/(k+o)\) (\(o\) is an offset, empirically set as \(2\)) and \(J_{j}\) is constrained on a upper bound \(\epsilon|\tilde{\epsilon}_{j}|\), the algorithm stops and returns the optimal cluster labels. To specify the parameter influences on segmentation results, we set \(K_{max}=4\) and change \(\epsilon\) from \(0\) to \(1\). The clustering results are displayed in Figure 7, whereas three sequences are included for comparisons. We find that when \(\epsilon\geq 0.25\), the algorithm outputs two clusters; as \(\epsilon\) decreases, more clusters are generated with margin details. Next, we collect the margin points for each cluster. Let us assume that \(\mathfrak{M}_{i}=\{b_{t},b_{t},b_{r},b_{b}\}\), in which collection \(\mathfrak{M}_{i}\) contains the top, left, right and bottom block for cluster \(i\). Then, a rectangle area can be drawn based on these blocks. However, some \"noise\" blocks may reduce the precision of determining \(\mathfrak{M}_{i}\). For example, in Figure 8c, the rectangle area covers many blank areas that are useless. To solve this problem, we propose a motion area pruning algorithm, see Algorithm 4 for details. Please note that the algorithm first traverses each block cluster from its margin points in a depth-first way. The searching procedure terminates when it reaches the bounds or the visiting block is not ROI block (\(R^{n}\)). Then, the traversed data is collected into subset \(\mathcal{B}\). If the size of \(\mathcal{B}\) is small enough, the blocks in \(\mathcal{B}\) are ignored as \"noise\" ones. Finally, the algorithm returns the pruned block set \(\mathcal{B}_{1}\). Please note that the search range \(r\) and step \(s\) are set as five and two block-distance empirically, in which larger value of \(r\) would eliminate less \"noise\" blocks. Figure 8 shows the boundaries of motion areas before and after the pruning algorithm. We can observe that the proposed method reduces the \"noise\" blocks effectively and obtains the precise rectangle. Figure 7: The motion segmentation results for different values of \(\epsilon\) (\(K_{max}=4\)): (**a**) Raw sequences. (From top to bottom: _Suzie_, _Ice_, _Foreman_) (**b**) Foreground motion blocks. ```
1:\(\textit{Search}(b,\textit{Vis},\mathcal{B})\):
2:\(b\): The current processing block; Vis: Whether the block is visited; \(\mathcal{B}\): Temp block lists; Search range \(r\) and step \(s\). 3:If \(\textit{CheckBound}(b)==\textbf{false or }\textit{Vis}(b)\textbf{ or }\textit{Type}(b)==R^{n}\), return. 4:\(\textit{Vis}(b)\)=true, append \(b\) to \(B\). 5:for\(i=1\); \(i<r\); \(i+=s\)do
6:\(\textit{Search}(b(x\pm i,y\pm i),\textit{Vis},\mathcal{B})\). 7:endfor
8:\(\textit{Prune}(\mathfrak{M})\):
9: : Margin block set \(\mathfrak{M}\); Original block set \(\mathcal{B}^{i}_{0}\). Pruned block set \(\mathcal{B}^{i}_{1}=\emptyset\) (\(0<i\leq k\)). 10:for each \(\mathfrak{M}_{i}\) in \(\mathfrak{M}\)do
11:for each \(b_{j}\) in \(\mathfrak{M}_{i}\)do
12:\(\textit{Search}(b_{j},\textit{Vis},\mathcal{B}_{j})\). 13:\(\textit{If}|\mathcal{B}_{j}|>\frac{\mathcal{B}^{i}_{0}}{|\mathfrak{M}_{i}|+o}, \mathcal{B}^{i}_{1}\bigcup\mathcal{B}_{j}\). 14:endfor
15:endfor
16:return\(\bigcup\mathcal{B}^{i}_{1}\). ```

**Algorithm 4** Motion Area Pruning Algorithm

#### 2.1.6 Mask Drawing and ROI Extracting

After obtaining the boundaries of motion areas for each cluster, we consider drawing the margin masks for the motion areas. First of all, the \"edge\" blocks of each cluster are filtered by edge detection methods (i.e., Canny, Sobel). Let us assume that \(\mathcal{B}^{i}_{E}\) is the set of \"edge\" blocks of the \(i\)th cluster, the shape of mask is then generated by the Gift-Wrapping algorithm in [66], see Figure 9 for details. Figure 8: Visual effects before and after the pruning algorithm for motion areas: (**a**) Raw sequences. (From top to bottom: _Suzie_, _Ice_, _Foreman_) (**b**) Foreground motion blocks. (**c**) Before pruning. (**d**) After pruning.