Last active
December 24, 2018 22:10
-
-
Save pravj/5537fe59a13f6bacbe3855eced767ed9 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
# Reference: https://code.likeagirl.io/finding-dominant-colour-on-an-image-b4e075f98097 | |
from sklearn.cluster import KMeans | |
# word block colors (color palette) | |
block_colors = [] | |
# change dimension to (width x height, color-channels) | |
screen = screen.reshape((screen.shape[0] * screen.shape[1], 3)) | |
# Collect 8 major colors in the image using KMeans clustering | |
# It will include some background colors also having majority share | |
color_cluster = KMeans(n_clusters=8) | |
color_cluster.fit(screen) | |
# histogram representing area proportion for each color | |
# refers to other function, https://github.com/pravj/semantris-solver | |
hist = find_histogram(color_cluster) | |
# filter out persistent/background colors from game background | |
for i, rgb in enumerate(color_cluster.cluster_centers_): | |
if not is_blocks_background_color(*rgb, hist[i]): | |
block_colors.append(rgb) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment