if show_all:
import matplotlib.pyplot as pyplot
+ import Image
+ fig = pyplot.figure(figsize=(8, 6))
pyplot.scatter(luma, saturation,
color=[(s[2][0]/255.,
s[2][1]/255.,
for s in board_raw])
pyplot.xlim(0,1)
pyplot.ylim(0,1)
- pyplot.show()
+ fig.canvas.draw()
+ size = fig.canvas.get_width_height()
+ buff = fig.canvas.tostring_rgb()
+ image_p = Image.fromstring('RGB', size, buff, 'raw')
+ do_something(image_p, "color distribution")
clusters = k_means.cluster(3, 2,zip(zip(luma, saturation), range(len(luma))),
[[0., 0.5], [0.5, 0.5], [1., 0.5]])
#clusters.sort(key=mean_luma)
if show_all:
+ fig = pyplot.figure(figsize=(8, 6))
pyplot.scatter([d[0][0] for d in clusters[0]], [d[0][1] for d in clusters[0]],
color=(1,0,0,1))
pyplot.scatter([d[0][0] for d in clusters[1]], [d[0][1] for d in clusters[1]],
color=(0,0,1,1))
pyplot.xlim(0,1)
pyplot.ylim(0,1)
- pyplot.show()
+ fig.canvas.draw()
+ size = fig.canvas.get_width_height()
+ buff = fig.canvas.tostring_rgb()
+ image_p = Image.fromstring('RGB', size, buff, 'raw')
+ do_something(image_p, "color clustering")
clusters[0] = [(p[1], 'B') for p in clusters[0]]
clusters[1] = [(p[1], '.') for p in clusters[1]]