## 3 Materials and Methods
### BeePIV
#### 3.3.5 Difference Maxima Erosion
In our example, the largest pixel value \(143\) at position \((1,3)\) is is eroded, because it is within the distance threshold from \((1,1)\), which is considered first. A more computationally involved approach to guarantee the preservation of relative local maxima is to sort the values in \(S_{b_{t,\Delta}}\) in descending order and continue to erode the positions within \(d^{\prime}\) pixels of the position of each sorted maxima until there is nothing else to erode. In practice, we found that this method does not contribute to the accuracy of the algorithm due to the proximity of local maxima to each other. To put it differently, it is the positions of the local maxima that matter, not their actual pixel values in smoothed difference frames in that the motion points generated by the multiple body parts of a flying bee have a strong tendency to cluster in close proximity. The video erosion operator \(E_{d^{\prime}}^{*}(V)\) applies the erosion operator \(E_{d^{\prime}}\) to every frame in a sequence of binary difference frames \(S_{b_{t,\Delta}}^{V}\) and returns a sequence of corresponding eroded frames \(R_{b_{t,\Delta}}^{V}\), as defined in Equation (22), where \(Z=(S_{b_{t,\Delta}}^{V},\ldots,S_{b_{t+\Delta}}^{V})\) is a sequence of difference frames. \[E_{dV}^{*}(Z)=E_{dV}^{*}\Big{(}S_{b_{L,\Delta}}^{V},\dots,S_{b_{l+k,\Delta}}^{V} \Big{)}=\Big{(}R_{b_{L,\Delta}}^{V},\dots,R_{b_{l+k,\Delta}}^{V}\Big{)} \tag{22}\]  
The positions of 1's in each \(R_{b_{L,\Delta}}\) are treated as centers of small circles whose radius is \(1/\beta\) of the width of \(R_{b_{L,\Delta}}\), where \(\beta=50\) in our current implementation. The \(\beta\) parameter, in effect, controls the size of the motion points for PIV. After the black circles are drawn on a white background the frame \(R_{b_{L,\Delta}}\) becomes the frame \(W_{l}\). We refer to \(W_{l}\) frames as motion frames and define the drawing operator \(J_{\beta}\) in Equation (23), where \(W_{l}\) is obtained by drawing at each position with 1 in \(R_{b_{L,\Delta}}\) a black circle with a radius of \(1/\beta\) of the width of \(R_{b_{L,\Delta}}\). \[J_{\beta}(R_{b_{L,\Delta}})=W_{l} \tag{23}\]  
Figure 11 shows twelve motion frames obtained from the twelve frames in Figure 2. Figure 12 shows the detected motion points in each motion frame \(W_{l}\) plotted on the corresponding original frame \(F_{l}\) from which \(W_{l}\) was obtained. The motion frames \(W_{l}\) record bee motions reduced to single points and constitute the input to the PIV algorithm described in the next section. The video drawing operator \(J_{\beta}^{*}(V)\) applies the drawing operator \(J_{\beta}\) to every frame in a sequence of eroded frames \(R_{b_{L,\Delta}}\) and returns a sequence of the corresponding white background frames with black circles \(W_{l}\), as defined in Equation (24), where \(Z=(R_{b_{L,\Delta}},\dots,R_{b_{l+k,\Delta}})\) is a sequence of eroded frames. The sequence of motion frames is given to the PIV algorithm described in the next section. \[J_{\beta}^{*}(Z)=\Big{(}I_{\beta}\Big{(}R_{b_{L,\Delta}}\Big{)},\dots,I_{\beta }\Big{(}R_{b_{l+k,\Delta}}\Big{)}\Big{)}=\Big{(}W_{l},\dots,W_{l+k}\Big{)} \tag{24}\]  
Figure 11: Motion frames \(W_{1}\) to \(W_{12}\) obtained from original frames \(F_{1}\) to \(F_{12}\) in Figure 2.