## 4 Algorithms
### Leader Tape Detection  
Considering two spectrograms, \((P_{i},P_{j})\), this step aims at detecting the presence of a leader-tape inserted into one of the two tapes. This detector relies on the fact that, whether or not a leader is present, there is not a single affine transformation that maps the keypoints found on \(P_{i}\) onto those of \(P_{j}\). The reason is that keypoints lying in the portion of the spectrogram after a leader-tape insertion will carry an offset in their time coordinates with respect to those found on a spectrogram that does not contain such insertion. The algorithm proceeds as follows. 1. From two sets of keypoints \((\mathcal{K}_{i},\mathcal{K}_{j})\), find a subset of matched pairs by comparing the related descriptors. Given the matched pairs \(\big{(}(u_{k},\
u_{k}),(u_{k}^{\prime},\
u_{h}^{\prime})\big{)}\), estimate the optimum geometric transform mapping \(P_{i}\) onto \(P_{j}\) with the RANSAC algorithm [36]. If a leader-tape is present, the set of inlier points returned by the algorithm will converge to a subset of keypoints belonging to only one of the two portions of the spectrogram separated by the leader (Figure 3). 2. Define a function \(g_{i}(v)\) counting the number of keypoints detected in \(P_{i}(u,v)\) for each image column \(v\) (in order to avoid strong oscillations, \(g(v)\) is processed with a moving-average low-pass filter). Then, define \(g_{i}^{\prime}(v)\) as the number of inlier points left on \(P_{i}(u,v)\) after the RANSAC  
Figure 3: Spectrogram image \(P_{i}(u,v)\) of an audio track \(x_{i}(n)\), with green asterisks representing the detected SURF keypoints. Subfigures show the SURF keypoints (**a**) and inlier keypoints after RANSAC (**b**). Note that the remaining inlier points are located to the right of the leader-tape. algorithm. In the presence of a leader insertion, distance \(|g_{i}(v)-g^{\prime}_{i}(v)|\) shows an evident step that can be detected by looking for gradient peaks. 3. Let \(v_{l}\) be the coordinate associated with the detected step. Define the following sets: \[ \begin{split}\mathcal{K}_{i}^{(L)}&=\left\{(u_{k},v_ {k})\in\mathcal{K}_{i}|v_{k}<v_{l}\right\},\\ \mathcal{K}_{i}^{(R)}&=\left\{(u_{k},v_{k})\in \mathcal{K}_{i}|v_{k}>v_{l}\right\},\end{split} \] (2) i.e., the subsets of keypoints found on the left side (\(L\)) and on the right side (\(R\)) of the spectrogram with respect to the candidate leader location. Similarly, define \(\mathcal{K}_{j}^{(L)}\) and \(\mathcal{K}_{j}^{(R)}\). 4. Perform a new geometric transform estimation, on the left and right portion of the images separately, according to the subdivision defined in (2). The estimated models come in the form of \(3\times 3\) homography matrices, \(H^{(L)}\) and \(H^{(R)}\), from which it is possible to extract the translation components along the \(v\) direction, \(t^{(L)}\) and \(t^{(R)}\). The length of the candidate leader is then given by: \[w_{l}=|t^{(L)}-t^{(R)}|.\] (3) If \(w_{l}\
eq 0\), the algorithm concludes that a leader-tape is present within the current spectrogram pair. Finally, the algorithm tries to infer the correct phylogenetic relation that links \(P_{i}\) and \(P_{j}\), namely whether \(P_{j}\) was derived from \(P_{i}\) by inserting a leader-tape or vice versa. This can be achieved by measuring the average spectral energy around the detected location, knowing that leader insertions are characterized by a very low-energy region in the related spectrogram. If we find a significant difference between the average energies measured in the two images (with respect to a suitable tolerance threshold), it is possible to conclude that the phylogenetic ancestor is the the one related to the highest energy content. Specifically, the algorithm distinguishes the two following cases. If \(\sum_{u}P_{j}(u,v_{l})\gg\sum_{u}P_{i}(u,v_{l})\), then \(P_{j}\) is assumed to be the phylogenetic ancestor. The dissimilarity matrix is updated with \(d_{i,j}=+\infty\), indicating that a phylogenetic relation from \(i\) to \(j\) is not possible.