Open vitacon opened 10 months ago
I took me a while to notice it is already solved by a custom node. https://github.com/Stability-AI/stability-ComfyUI-nodes
And it is handled using cv2.
def color_blend(bw_layer,color_layer):
# Convert the color layer to LAB color space
color_lab = cv2.cvtColor(color_layer, cv2.COLOR_BGR2Lab)
# Convert the black and white layer to grayscale
bw_layer_gray = cv2.cvtColor(bw_layer, cv2.COLOR_BGR2GRAY)
# Replace the luminosity (L) channel in the color image with the black and white luminosity
_, color_a, color_b = cv2.split(color_lab)
blended_lab = cv2.merge((bw_layer_gray, color_a, color_b))
# Convert the blended LAB image back to BGR color space
blended_result = cv2.cvtColor(blended_lab, cv2.COLOR_Lab2BGR)
return blended_result
kornia now is installed by default https://github.com/comfyanonymous/ComfyUI/blob/master/requirements.txt#L13 so the original code snippet should work now
I use ComfyUI to colorize photos and to get a better result I need to combine Hue and Saturation of the output with the Luminance of the input image. So far I do it with an .exe made in .NET but it would be much nicer to handle it in ComfyUI.
It should be rather easy but I don't know Python libraries. I was pointed to kornia (K.color.rgb_to_hls) but it seems it's not included within Comfy because the code below does not work.
nodes_post_processing.py
What is the easiest way to do it?