From e8c490c3f3157dd962cb7ce4379a5c424c2f28d7 Mon Sep 17 00:00:00 2001 From: mmcwilliams Date: Tue, 21 Nov 2023 13:28:49 -0500 Subject: [PATCH] progress on updateing palete schema --- py/comparison_comparison.py | 2 +- py/pallete_schema.py | 16 +++++++++++++++- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/py/comparison_comparison.py b/py/comparison_comparison.py index f9faa49..1871d4b 100644 --- a/py/comparison_comparison.py +++ b/py/comparison_comparison.py @@ -59,7 +59,7 @@ class ComparisonComparison: else : closest, dist = closest_color_euclidean(colors, cccompare) - colors = remove_from_list(colors, c losest) + colors = remove_from_list(colors, closest) ccbgr = convert_color(cc, 'RGB', 'BGR') chosenbgr = convert_color(closest, space, 'BGR') diff --git a/py/pallete_schema.py b/py/pallete_schema.py index 3f4595e..850fbea 100644 --- a/py/pallete_schema.py +++ b/py/pallete_schema.py @@ -1,5 +1,6 @@ from jsonschema import validate from json import dumps, loads +from common import convert_color, closest_color, create_colored_image, remove_from_list, closest_color_euclidean, closest_color_weighted_euclidean, euclidean_distance, weighted_euclidean_distance class PalleteSchema : colors = None @@ -40,4 +41,17 @@ class PalleteSchema : validate( instance = obj, schema = self.schema) jsonstr = dumps(obj, indent = 4) with open(filepath, 'w') as outfile : - outfile.write(jsonstr) \ No newline at end of file + outfile.write(jsonstr) + + def closest (self, comparison, space = 'BGR', pallete = None) : + p = pallete if pallete is not None else self.pallete + colors = normalize_colors(space, ) + + def normalize_colors (self, space = 'BGR', pallete = None) : + colors = [] + for color in pallete : + colors.append(convert_color(color['color'], color['space'], space)) + return colors + + +