Applying the generated labels we get following results.
Normalization process of YOLO annotations
Example Conversion
To convert non-normalized bounding box coordinates (xmax, ymax, xmin, ymin) to YOLO format (xcenter, ycenter, width, height):
# Assuming row contains your bounding box coordinates
row = {'xmax': 400, 'xmin': 200, 'ymax': 300, 'ymin': 100}
class_id = 0 # Example class id (replace with actual class id)
# Image dimensions
WIDTH = 640 # annotated image width
HEIGHT = 640 # annotated image height
# Calculate width and height of the bounding box
width = row['xmax'] - row['xmin']
height = row['ymax'] - row['ymin']
# Calculate the center of the bounding box
x_center = row['xmin'] + (width / 2)
y_center = row['ymin'] + (height / 2)
# Normalize the coordinates
normalized_x_center = x_center / WIDTH
normalized_y_center = y_center / HEIGHT
normalized_width = width / WIDTH
normalized_height = height / HEIGHT
# Create the annotation string in YOLO format
content = f"{class_id} {normalized_x_center} {normalized_y_center} {normalized_width} {normalized_height}"
print(content)
The above conversion will give us YOLO format string.
0 0.46875 0.3125 0.3125 0.3125
is also supported by A.Lab. Below is an example of annotated ripe and unripe tomatoes. In this example, 0 represents ripe tomatoes and 1 represents unripe ones.