2023-10-23 14:32:35 +00:00
|
|
|
import cv2
|
|
|
|
import numpy as np
|
2023-10-24 02:46:18 +00:00
|
|
|
from pallete_schema import PalleteSchema
|
2023-10-24 20:45:22 +00:00
|
|
|
from common import convert_color, closest_color, create_colored_image
|
2023-10-23 14:32:35 +00:00
|
|
|
|
|
|
|
class ComparisonComparison:
|
2023-10-23 20:09:08 +00:00
|
|
|
def __init__ (self) :
|
2023-10-24 20:14:56 +00:00
|
|
|
red = [0, 10, 200]
|
|
|
|
green = [5, 250, 5]
|
|
|
|
blue = [240, 0, 20]
|
|
|
|
comp_colors = [red, green, blue]
|
2023-10-24 20:45:22 +00:00
|
|
|
pallete = PalleteSchema('./palletes/printed_pallete.json')
|
2023-10-24 21:09:09 +00:00
|
|
|
color_spaces = ['RGB', 'LAB', 'HSV']
|
|
|
|
for space in color_spaces :
|
|
|
|
print(f'Comparing in color space {space}')
|
|
|
|
colors = self.get_colors(pallete.colors, space)
|
|
|
|
show = []
|
|
|
|
for cc in comp_colors :
|
|
|
|
cccompare = convert_color(cc, 'RGB', space)
|
|
|
|
closest = closest_color(colors, cccompare)
|
|
|
|
|
|
|
|
ccbgr = convert_color(cc, 'RGB', 'BGR')
|
|
|
|
chosenbgr = convert_color(closest, space, 'BGR')
|
|
|
|
|
|
|
|
chosen = create_colored_image(100, 100, chosenbgr)
|
|
|
|
original = create_colored_image(100, 100, ccbgr)
|
|
|
|
|
|
|
|
combined = np.hstack([original, chosen])
|
|
|
|
show.append(combined)
|
|
|
|
show = np.vstack(show)
|
|
|
|
cv2.imshow("image", show)
|
2023-10-24 20:45:22 +00:00
|
|
|
cv2.waitKey(0)
|
2023-10-23 20:09:08 +00:00
|
|
|
|
2023-10-24 21:09:09 +00:00
|
|
|
def get_colors (self, pallete, space) :
|
2023-10-24 20:14:56 +00:00
|
|
|
colors = []
|
|
|
|
for color in pallete :
|
2023-10-24 21:09:09 +00:00
|
|
|
colors.append(convert_color(color['color'], color['space'], space))
|
2023-10-24 20:14:56 +00:00
|
|
|
return colors
|
2023-10-23 20:09:08 +00:00
|
|
|
|
2023-10-23 14:32:35 +00:00
|
|
|
if __name__ == "__main__":
|
|
|
|
ComparisonComparison()
|