|
@@ -0,0 +1,37 @@
|
|
|
|
+import matplotlib.pyplot as plt
|
|
|
|
+from skimage.measure import label
|
|
|
|
+from collections import Counter
|
|
|
|
+import numpy as np
|
|
|
|
+
|
|
|
|
+img = plt.imread('figures_and_colors/balls_and_rects.png')
|
|
|
|
+
|
|
|
|
+def rect_or_circle(figure):
|
|
|
|
+ if np.all(figure == figure[0][0]):
|
|
|
|
+ return 'rect'
|
|
|
|
+ return 'circle'
|
|
|
|
+
|
|
|
|
+gray_img = img.mean(axis=2)
|
|
|
|
+binary_img = gray_img.copy()
|
|
|
|
+binary_img[binary_img > 0] = 1
|
|
|
|
+
|
|
|
|
+labels = label(binary_img)
|
|
|
|
+
|
|
|
|
+fig = plt.figure()
|
|
|
|
+ax = fig.add_subplot(projection='3d')
|
|
|
|
+ax.set_xlabel('Red')
|
|
|
|
+ax.set_xlabel('Green')
|
|
|
|
+ax.set_xlabel('Blue')
|
|
|
|
+
|
|
|
|
+counter = Counter()
|
|
|
|
+figuremap = {'xs':[], 'ys':[], 'zs':[], 'marker':[], 'color':[]}
|
|
|
|
+for lbl in np.unique(labels)[1:]:
|
|
|
|
+ x, y = np.where(labels==lbl)
|
|
|
|
+ figure = img[x.min():x.max(), y.min():y.max(), :]
|
|
|
|
+ counter[rect_or_circle(figure)] += 1
|
|
|
|
+ marker = 's' if rect_or_circle(figure) == 'rect' else 'o'
|
|
|
|
+ color = figure[int(x.mean())-x.min()][int(y.mean())-y.min()]
|
|
|
|
+ ax.scatter(color[0], color[1], color[2], marker=marker, color=color)
|
|
|
|
+
|
|
|
|
+# ax.scatter(**figuremap)
|
|
|
|
+plt.show()
|
|
|
|
+print(counter)
|