|
@@ -0,0 +1,30 @@
|
|
|
+import numpy as np
|
|
|
+import matplotlib.pyplot as plt
|
|
|
+from skimage.color import rgb2hsv
|
|
|
+from sklearn.cluster import KMeans
|
|
|
+
|
|
|
+image = plt.imread('./figures_and_colors/balls_and_rects.png')
|
|
|
+
|
|
|
+hsv_image = rgb2hsv(image)
|
|
|
+
|
|
|
+unique_colors = np.unique(hsv_image[:, :, 0])
|
|
|
+
|
|
|
+plt.subplot(1,2,1)
|
|
|
+plt.ylim(0, 1)
|
|
|
+plt.plot(unique_colors, 'o')
|
|
|
+
|
|
|
+colormap = ['r', 'g', 'b', 'y', 'c', 'm']
|
|
|
+curr_color = 0
|
|
|
+
|
|
|
+figuremap = {'index':[1],'values':[unique_colors[1]], 'colors':[colormap[curr_color]]}
|
|
|
+for i,color in enumerate(unique_colors[2:-1]):
|
|
|
+ if abs(color - figuremap['values'][-1]) > 0.05:
|
|
|
+ curr_color += 1
|
|
|
+ figuremap['index'].append(i)
|
|
|
+ figuremap['values'].append(color)
|
|
|
+ figuremap['colors'].append(colormap[curr_color])
|
|
|
+
|
|
|
+plt.subplot(1,2,2)
|
|
|
+plt.ylim(0, 1)
|
|
|
+plt.scatter(x=figuremap['index'], y=figuremap['values'], marker='o', color=figuremap['colors'])
|
|
|
+plt.show()
|