jezv 11 月之前
父節點
當前提交
9eef3e2d4f
共有 2 個文件被更改,包括 37 次插入0 次删除
  1. 二進制
      figures_and_colors/balls_and_rects.png
  2. 37 0
      figures_and_colors/main.py

二進制
figures_and_colors/balls_and_rects.png


+ 37 - 0
figures_and_colors/main.py

@@ -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)