-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplot_annotated.py
More file actions
36 lines (30 loc) · 1.09 KB
/
Copy pathplot_annotated.py
File metadata and controls
36 lines (30 loc) · 1.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import matplotlib.pyplot as plt
from PIL import Image
if __name__ == "__main__":
image_path = "data/annotated/0164_swirl.jpg"
label_path = "data/annotated/0164_swirl.txt"
image = Image.open(image_path)
width, height = image.size
plt.imshow(image)
plt.axis(False)
with open(label_path, "r") as file:
lines = [line.strip() for line in file if line.strip()]
# each line is one annotated object: "<class_id> x1 y1 x2 y2 ... xn yn" with x/y normalized to [0, 1]
for line in lines:
values = line.split()
coordinates = [float(v) for v in values[1:]]
xs = [coordinates[i] * width for i in range(0, len(coordinates), 2)]
ys = [coordinates[i] * height for i in range(1, len(coordinates), 2)]
# give every vertex its own color via the colormap so the dots are visibly different
colors = list(range(len(xs)))
plt.scatter(
xs,
ys,
c=colors,
cmap="hsv",
s=40,
edgecolors="black",
linewidths=0.5,
zorder=2,
)
plt.show()