Last active
June 9, 2020 02:36
-
-
Save cinjon/904b53e0e17ec3916dae572e832d6576 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
H = 10 | |
kmeans = make_clusters(eigenvectors, num_clusters) | |
W = 18 | |
T = 128 | |
CD = 8 | |
CR = int(T // CD) | |
colors = [] | |
labels = kmeans.labels_ | |
for i in range(kmeans.cluster_centers_.shape[0]): | |
hexcolor = '%06X' % randint(0, 0xFFFFFF) | |
colors.append(np.array([int(hexcolor[i:i+2], 16) for i in (0, 2, 4)])) | |
img = np.zeros((H*CD, W*CR, 3)) | |
for counter_down in range(CD): | |
for counter_right in range(CR): | |
for x in range(H): | |
for y in range(W): | |
xpos = counter_down*H + x | |
ypos = counter_right*W + y | |
v1 = CR*W*H*counter_down + W*H*counter_right + x*W + y | |
img[xpos, ypos] = colors[labels[v1]] | |
print(img.max(), img.min(), img.shape, img.dtype) | |
image = Image.fromarray(img.astype(np.uint8)) | |
path = '/content/tmp-%dcluster.png' % len(colors) | |
image.save(path) | |
display.display(display.Image(path, height=600, width=600)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment