From 454efb96efa41b96dc161892d45aa7d7b2945a61 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 14 Feb 2025 19:23:51 +0200 Subject: [PATCH] LAB color space, blur --- color_transfer.py | 9 ++++++++- utils.py | 2 +- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/color_transfer.py b/color_transfer.py index 36859e5..7439d0f 100644 --- a/color_transfer.py +++ b/color_transfer.py @@ -84,14 +84,21 @@ class PaletteTransferNode: target_colors = np.array(target_colors, dtype=np.uint8).reshape(-1, 1, 3) target_colors = cv2.cvtColor(target_colors, cv2.COLOR_RGB2HSV) target_colors = [tuple(hsv[0]) for hsv in target_colors] + if color_space == "LAB": + img = cv2.cvtColor(img, cv2.COLOR_RGB2LAB) + target_colors = np.array(target_colors, dtype=np.uint8).reshape(-1, 1, 3) + target_colors = cv2.cvtColor(target_colors, cv2.COLOR_RGB2LAB) + target_colors = [tuple(lab[0]) for lab in target_colors] clustered_img, detected_colors, clustering_model = ColorClustering(img, len(target_colors), cluster_method) processed = SwitchColors(clustered_img, detected_colors, target_colors, clustering_model, distance_method) if color_space == "HSV": processed = cv2.cvtColor(processed, cv2.COLOR_HSV2RGB) - + if color_space == "LAB": + processed = cv2.cvtColor(processed, cv2.COLOR_LAB2RGB) + if gaussian_blur: processed = Blur(processed, gaussian_blur) diff --git a/utils.py b/utils.py index 2346523..4ec4763 100644 --- a/utils.py +++ b/utils.py @@ -42,7 +42,7 @@ def HSV_Color_Similarity(detected_color, target_colors): similarities = dot_products / (v1_norm * v2_norms) return -similarities - + def Blur(image, kernel_size): return cv2.medianBlur(image.astype(np.uint8), kernel_size) \ No newline at end of file