Add files via upload

This commit is contained in:
Fictiverse
2023-10-29 22:28:56 +01:00
committed by GitHub
parent 7554fb0460
commit 564965104b
+42 -14
View File
@@ -1,21 +1,37 @@
import cv2
import numpy as np
from skimage.exposure import match_histograms
from PIL import Image
from skimage import exposure
from enum import Enum
import torch
# Tensor to PIL
def tensor2pil(image):
return Image.fromarray(np.clip(255. * image.cpu().numpy().squeeze(), 0, 255).astype(np.uint8))
# Define 'BlendType' and 'blendLayers' as needed
def blendLayers(image1, image2):
# Extract the luminance channel from both images
image1_luminance = image1.convert("L")
image2_luminance = image2.convert("L")
# Combine the luminance channel from image1 with the color channels of image2
r, g, b = image2.split()
blended_image = Image.merge("RGB", [image1_luminance, g, b])
return blended_image
class ColorCorrection:
"""
This node provides a simple interface to apply PixelSort blur to the output image.
"""
def __init__(self):
pass
@classmethod
def INPUT_TYPES(cls): # Use cls instead of s
def INPUT_TYPES(cls):
return {
"required": {
"image": ("IMAGE",),
"original_image": ("IMAGE",),
"correction": ("IMAGE",), # Add this line
},
}
@@ -23,14 +39,26 @@ class ColorCorrection:
FUNCTION = "color_correction"
CATEGORY = "Fictiverse"
def color_correction(self, image, original_image):
correction_target = cv2.cvtColor(np.asarray(image), cv2.COLOR_RGB2LAB)
corrected_image = cv2.cvtColor(exposure.match_histograms(
cv2.cvtColor(np.asarray(original_image), cv2.COLOR_RGB2LAB),
correction_target,
channel_axis=2
), cv2.COLOR_LAB2RGB).astype("uint8")
return (corrected_image,)
def color_correction(self, original_image, correction):
pil_original_image = np.array(tensor2pil(original_image))
pil_correction = np.array(tensor2pil(correction))
# Perform color correction
original_lab = cv2.cvtColor(pil_original_image, cv2.COLOR_RGB2LAB)
corrected_lab = cv2.cvtColor(pil_correction, cv2.COLOR_RGB2LAB)
corrected_image = cv2.cvtColor(match_histograms(original_lab, corrected_lab, channel_axis=2), cv2.COLOR_LAB2RGB).astype("uint8")
# You need to implement the blendLayers function and BlendType.LUMINOSITY.
# The following line assumes that it exists in your code:
image = blendLayers(Image.fromarray(corrected_image), Image.fromarray(pil_original_image))
#Return image is in wrong type ?
return (image,)
NODE_CLASS_MAPPINGS = {
"Color correction": ColorCorrection