-
Notifications
You must be signed in to change notification settings - Fork 2
/
make_radial_plot.py
83 lines (67 loc) · 2.75 KB
/
make_radial_plot.py
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
import os
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.patches import Circle
from collections import defaultdict
import matplotlib.colors as colors
import cv2
import random
def scatter_plot(dir_paths, num_files=500, alpha=0.6):
fig, ax = plt.subplots()
# Dictionary mapping index -> label
labels = {i: f"s{i+1}" for i, _ in enumerate(dir_paths)}
colors = ['r', 'g', 'b', 'c', 'm', 'y', 'k']
markers = ['o', 's', 'D', 'v', '^', 'p', 'h']
for i, (dir_path, label) in enumerate(zip(dir_paths, labels.values()), start=1):
files = os.listdir(dir_path)[:num_files]
hues = []
saturations = []
for file in files:
img = cv2.imread(os.path.join(dir_path, file))
img = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
hue = img[:, :, 0].mean()
saturation = img[:, :, 1].mean()
hues.append(hue)
saturations.append(saturation)
color = colors[i - 1]
marker = markers[(i - 1) % len(markers)]
# ax.scatter(hues, saturations, c=color, marker=marker, alpha=alpha, label=f"{label}")
ax.scatter(hues, saturations, c=color, alpha=alpha, label=f"{label}", s=12)
ax.set_ylabel('Saturation')
ax.set_xlabel('Hue')
ax.legend()
plt.savefig("hue_vs_saturdation.pdf", format='pdf', dpi=600)
plt.show()
# Replace these with the actual directory paths.
dir1 = ""
dir2 = "/"
dir3= "/nfstud/"
dir4= "/nfs/s/n/"
dir5= "/nfs/studches/"
dir6 = "/nfs/stus/"
listofdirs = [dir1, dir2, dir3, dir4, dir5, dir6]
# scatter_plot(listofdirs)
def random_grid_plot(dir_paths, num_images=3, row_cols=(6, 3)):
fig, axes = plt.subplots(6, 3)
fig.suptitle("Random Images HSV Values")
for i, (dir_path, ax_group) in enumerate(zip(dir_paths, axes.flat)):
files = sorted(os.listdir(dir_path))
selected_indices = random.sample(range(len(files)), min(num_images, len(files)))
hues = []
saturations = []
for idx in selected_indices:
img = cv2.imread(os.path.join(dir_path, files[idx]))
img = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
hue = img[:, :, 0].mean()
saturation = img[:, :, 1].mean()
hues.append(hue)
saturations.append(saturation)
for j, (hue_, sat_) in enumerate(zip(hues, saturations)):
# ax = ax_group[j // row_cols[1]]
ax.imshow(img, aspect="auto")
ax.tick_params(left=False, bottom=False)
ax.set_title(f"Hue:{int(hue_)}, Saturation:{int(sat_)}")
ax.axis("off")
plt.savefig("palletete.pdf", format='pdf', dpi=600)
plt.show()
random_grid_plot(listofdirs)