From 007e7076c7404c86180ff3aa6ea3fe15024a87c3 Mon Sep 17 00:00:00 2001 From: chqn Date: Wed, 3 Jan 2024 13:12:48 -0600 Subject: Refactored function signatures and added some TODOs --- src/color_engine.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src/color_engine.py') diff --git a/src/color_engine.py b/src/color_engine.py index f86b2e7..6d5c90a 100644 --- a/src/color_engine.py +++ b/src/color_engine.py @@ -14,11 +14,13 @@ def grabColors(img_path: str, num_colors: int) -> list(): # scale image down by factor of 10 to decrease computation time dim = (int(len(img[0])/10), int(len(img)/10)) img = cv.resize(img, dim, interpolation= cv.INTER_AREA) + # TODO: implement KMeans clustering from scratch to + # improve program modularity clt = KMeans(n_clusters=num_colors, n_init='auto') clt.fit(img.reshape(-1, 3)) return clt.cluster_centers_ -def rgbToHex(input_values: list): +def rgbToHex(input_values: list) -> list: """ Takes in a list of RBG color values and returns a list of those same colors as hex values """ @@ -30,11 +32,11 @@ def rgbToHex(input_values: list): hex_list.append('#{:02x}{:02x}{:02x}'.format(red, green, blue)) return hex_list -def hexToRGB(hex_value: str): +def hexToRGB(hex_value: str) -> tuple: hex_value = hex_value.lstrip('#') return tuple(int(hex_value[i:i+2], 16) for i in (0, 2, 4)) -def compColors(color_list: list): +def compColors(color_list: list) -> list: """ given a list of colors, generate complimentary colors to contrast the prominent colors. return a list of these colors. @@ -43,7 +45,7 @@ def compColors(color_list: list): for color in color_list: curr_hex = color[1:] # slice off the # from the hex code rgb = (curr_hex[0:2], curr_hex[2:4], curr_hex[4:6]) - comp = ['%02X' % (255 - int(a, 16)) for a in rgb] + comp = ['%02X' % (255 - int(a, 16)) for a in rgb] # magic :D compliments.append('#' + ''.join(comp)) return compliments -- cgit v1.2.3