# Automatic Classification of Morphologically Similar Fish Species Using Their Head Contours
## 2 Materials and Methods
### Open Contour Normalization  
Before the development of the features can be addressed, the open contours must first be normalized. The normalization should be able to compare segments that are represented by a different number of points while also neutralising variations with respect to rotation and scale. Furthermore, care will be taken to ensure that the normalization respects the aspect ratio of the segments. In the case of open contours, the reader can see that the first, \(\left(h_{0},v_{0}\right)=\left(0,0\right)\), and the last point, \(\left(h_{N_{i}-1},v_{N_{i}-1}\right)\), of the open contour must necessarily differ and, therefore, the reconstruction done with few DFT coefficients could present strong distortions due to the Gibbs phenomenon. However, although the  
Figure 6: Steps for the contour segment extraction. In (**a**), binarization; in (**b**–**e**), the steps to fill the gaps in the background and in the fish regions; in (**f**), the boundary detection of the white region; and in (**g**), the contour of interest found after removing the image borders.  
Figure 7: Fragment of interest of the fish delimited by landmarks \(L_{1}\) and \(L_{2}\).  
elements \(x_{0}\) and \(x_{N_{i}-1}\) of the sequence differ significantly, the DCT can efficiently approximate the sequence \(x_{n}\) with \(\hat{x}_{n}\) using few coefficients (\(L\)).  
As previously demonstrated, the DFT works very well for closed contours because the natural shapes tend to have a smooth variation and, if sampled correctly, the point \((h_{0},v_{0})\) is very similar to \((h_{N_{i}-1},v_{N_{i}-1})\), with \(h_{0}\) and \(v_{0}\) being close to \(h_{N_{i}-1}\) and \(v_{N_{i}-1}\), respectively. The normalization put forward is simple and takes these issues into account. It can be performed following these next two steps:  
* First, for each open contour, we compute the Euclidean distance \(\alpha\) between \((h_{0},v_{0})\) and \((h_{N_{i}-1},v_{N_{i}-1})\), and the angle \(\theta\) that the segment defined by these two points forms with the horizontal. Seen graphically in Figure 7, the points \((h_{0},v_{0})\) and \((h_{N_{i}-1},v_{N_{i}-1})\) correspond to the landmarks \(L_{1}\) and \(L_{2}\), respectively. As all the segments begin at \((h_{0},v_{0})=(0,0)\), we have: \[\alpha=\sqrt{h_{N_{i}-1}^{2}+v_{N_{i}-1}^{2}}\quad\text{and}\quad\theta=\tan^{ -1}\left(v_{N_{i}-1}/h_{N_{i}-1}\right).\] (8) Then, \(\alpha\) and \(\theta\) are used to rotate and re-scale all the contours points according to: \[\begin{bmatrix}p_{k}\\ q_{k}\end{bmatrix}=\frac{1}{\alpha}\begin{bmatrix}cos(\theta)&-sin(\theta)\\ sin(\theta)&cos(\theta)\end{bmatrix}\begin{bmatrix}v_{k}\\ h_{k}\end{bmatrix}.\] (9) After this operation, without changing the aspect ratio, all profiles have been re-scaled and rotated so that they start at point (0,0) and end at point (1,0). Figure 8 separately shows both the scale and scale-and-rotation effects on the original Red Mullet contours. Note in Figure 8 that the relevant information to discriminate the contours is concentrated in \(q_{k}\) (the vertical axis after the rotation) while \(q_{k}\) (the horizontal axis after the rotation) will be very close for all contours and will always go from 0 to 1 in approximately constant increments.
* Second, in order to balance the number of points, the sequence of points \(q_{k}\) is re-sampled so that they all have 256 values. The re-sampling is performed by cubic splines in order to have values at equispaced intervals in the range going from 0 to 1. We call the re-sampled sequence \(x_{k}\). Finally the contours are represented with a single sequence. In addition, the points \(x_{0}\) and \(x_{255}\) practically take the same value (0), which allows the DFT to be used as well.