Created
August 15, 2017 09:39
-
-
Save yazdipour/481d3273d3e2e85c00d492ac8f057728 to your computer and use it in GitHub Desktop.
This file contains 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
# import Image | |
# f = raw_input('Image:\n') | |
# im = Image.open(f) | |
# rgb_im = im.convert('RGB') | |
# r, g, b = rgb_im.getpixel((x, y)) | |
# def distance(c1, c2): | |
# (r1,g1,b1) = c1 | |
# (r2,g2,b2) = c2 | |
# return math.sqrt((r1 - r2)**2 + (g1 - g2) ** 2 + (b1 - b2) **2) | |
# colors = list(rgb_code_dictionary.keys()) | |
# closest_colors = sorted(colors, key=lambda color: distance(color, point)) | |
# closest_color = closest_colors[0] | |
# code = rgb_code_dictionary[closest_color] | |
import scipy.spatial as sp | |
input_color = (100, 50, 25) | |
websafe_colors = [(200, 100, 50),(100, 50, 22)]# list of web-save colors | |
tree = sp.KDTree(websafe_colors) # creating k-d tree from web-save colors | |
ditsance, result = tree.query(input_color) # get Euclidean distance and index of web-save color in tree/list | |
nearest_color = websafe_colors[result] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment