## 2 Method
### Image Data Augmentation and Automatic Annotation Tool: Zhizeng Huigai  
When constructing large-scale datasets, the limited quantity of original image data often necessitates the use of data augmentation techniques to expand the number of dataset images and balance different data categories. This approach improves the model's robustness and generalization capabilities. Typically, data augmentation can increase the data volume severalfold, by tens or even hundreds of times, for instance, through image rotations at various angles. However, although these techniques resolve the issue of insufficient sample size, they significantly intensify the workload associated with data annotation, which becomes a major bottleneck.  
To address this challenge, this section introduces a tool designed to simultaneously produce data augmentation and corresponding data annotation results, thereby overcoming current limitations in automation and low annotation efficiency. This tool is primarily intended for datasets using rectangular bounding box annotations and outputs image labels in YOLO format.  
The basic principle of the automatic annotation algorithm is as follows:  
\begin{table}
\begin{tabular}{l l} \hline \hline
**Classification Serial Number** & **Classification Label** \\ \hline
0 & Foam Pollution \\ \hline
1 & River Color—Red \\ \hline
2 & Garbage Pollution \\ \hline
3 & Oil Film Pollution \\ \hline \hline \end{tabular}
\end{table}
Table 4: Final classification sequence after reordering and additions (Step 5).  
\begin{table}
\begin{tabular}{l l} \hline \hline
**Classification Serial Number** & **Classification Label** \\ \hline
0 & Foam Pollution \\ \hline
1 & Garbage Pollution \\ \hline
2 & River Color—Red \\ \hline
3 & Oil Film Pollution \\ \hline \hline \end{tabular}
\end{table}
Table 3: Classification sequence after deleting one category (Step 1).  
For each original image, which corresponds to one or more bounding boxes, when the image is rotated, the associated annotation boxes rotate by the same angle.
2. The rotation angle of each image is recorded, and the algorithm automatically adjusts the positions and rotation angles of the corresponding annotation boxes to match the image's rotation.
3. For a rotated image, every coordinate point of its bounding box is multiplied by the rotation matrix, ensuring the bounding box rotates around the image's rotation center by the same angle. This guarantees that the annotation boxes remain accurately aligned with the rotated image.  
In a two-dimensional plane, the rotation matrix for a point (x, y) rotated by an angle \(\theta\) around the origin to obtain the coordinates (x\({}^{\prime}\), y\({}^{\prime}\)) can be calculated using the following rotation matrix. The rotation matrix R is  
\[\text{R}=\begin{bmatrix}\cos\theta&-\text{sin}\theta\\ \sin\theta&\cos\theta\end{bmatrix}\]  
Then, the coordinates (x\({}^{\prime}\), y\({}^{\prime}\)) of the point (x, y) after rotation can be obtained through the following matrix multiplication:  
\[\begin{bmatrix}x^{\prime}\\ y^{\prime}\end{bmatrix}=\begin{bmatrix}\cos\theta&-\text{sin}\theta\\ \sin\theta&\cos\theta\end{bmatrix}\begin{bmatrix}x\\ y\end{bmatrix}\]  
That is, x\({}^{\prime}\) = xcos\(\theta\) - ysin\(\theta\), y\({}^{\prime}\) = xsin\(\theta\) + ycos\(\theta\). For example, when rotating the point (1,0) counterclockwise by 90\({}^{\circ}\) around the origin, at this time, \(\theta\) = 90\({}^{\circ}\), cos\(\theta\) = 0, sin\(\theta\) = 1. According to the above formula, we can calculate x\({}^{\prime}\) = 0, y\({}^{\prime}\) = 1, and the coordinates of the rotated point are (0,1).  
This method enables accurate automatic annotation of augmented images. Furthermore, for each image in the augmented dataset, the tool generates file names by appending the rotation angle to the original image name and outputs label files whose names correspond to the augmented images. Each label file contains the results of the automatic annotation algorithm, ensuring a precise and efficient annotation process for the augmented dataset.