diff --git a/README.MD b/README.MD
index 8be1897..94b6428 100644
--- a/README.MD
+++ b/README.MD
@@ -70,6 +70,7 @@ When this error has occurred, please check the network environment.
## Update
**If the dependency package error after updating, please reinstall the relevant dependency packages.
+* Commit [ColorTemperature](#ColorTemperature) and [ColorBalance](#ColorBalance) nodes, used to adjust the color temperature and color balance of the picture.
* Add new types of [Blend Mode V2](#BlendModeV2) between images. now supports up to 30 blend modes. The new blend mode is available for all V2 versions that support mixed mode nodes, including ImageBlend V2, ImageBlendAdvance V2, DropShadow V2, InnerShadow V2, OuterGlow V2, InnerGlow V2, Stroke V2, ColorOverlay V2, GradientOverlay V2.
Part of the code for BlendMode V2 is from [Virtuoso Nodes for ComfyUI](https://github.com/chrisfreilich/virtuoso-nodes). Thanks to the original authors.
* Commit [YoloV8Detect](#YoloV8Detect) node.
@@ -361,6 +362,26 @@ Node options:
Node option:
* exposure: Exposure value. Higher values indicate brighter image.
+
+### ColorTemperature
+
+Change the color temperature of the image.
+
+Node Options:
+
+* temperature: Color temperature value. Range between-100 and 100. The higher the value, the higher the color temperature (bluer); The lower the color temperature, the lower the color temperature (yellowish).
+
+### ColorBalance
+
+Change the color balance of an image.
+
+Node Options:
+
+* cyan_red: Cyan-Red balance. negative values are leaning cyan, positive values are leaning red.
+* magenta_green: Megenta-Green balance. negative values are leaning megenta, positive values are leaning green.
+* yellow_blue: Yellow-Blue balance. negative values are leaning yellow, positive values are leaning blue.
+
+
### Gamma
Change the gamma value of the image.
diff --git a/README_CN.MD b/README_CN.MD
index 5a1638f..c262f97 100644
--- a/README_CN.MD
+++ b/README_CN.MD
@@ -70,6 +70,8 @@ git clone https://github.com/chflame163/ComfyUI_LayerStyle.git
## 更新说明
**如果本插件更新后出现依赖包错误,请重新安装相关依赖包。
+
+* 添加 [ColorTemperature](#ColorTemperature) 和 [ColorBalance](#ColorBalance) 节点,用于调整图片色温和色彩平衡。
* 更新 [混合模式](#混合模式)到V2版本,现在支持多达30种混合模式。新增的混合模式适用于所有支持混合模式节点的V2版本,包括ImageBlend V2, ImageBlendAdvance V2, DropShadow V2, InnerShadow V2, OuterGlow V2, InnerGlow V2, Stroke V2, ColorOverlay V2, GradientOverlay V2。
混合模式V2的部分代码来自[Virtuoso Nodes for ComfyUI](https://github.com/chrisfreilich/virtuoso-nodes)的```Blend Modes```节点。感谢原作者。
* 添加 [YoloV8Detect](#YoloV8Detect) 节点。
@@ -356,6 +358,25 @@ git clone https://github.com/chflame163/ComfyUI_LayerStyle.git
* highlight_level_offset: 亮部取值的偏移量,更小的数值使更多靠近阴暗的区域纳入亮部。
* highlight_range: 亮部的过渡范围。
+### ColorTemperature
+
+改变图像的色温。
+
+节点选项说明:
+
+* temperature: 色温值。范围在-100到100之间。值越高,色温越高(偏蓝);越低,色温越低(偏黄)。
+
+### ColorBalance
+
+改变图像的色彩平衡。
+
+节点选项说明:
+
+* cyan_red: 青-红平衡。负值为偏青,正值为偏红。
+* magenta_green: 品-绿平衡。负值为偏品,正值为偏绿。
+* yellow_blue: 黄-蓝平衡。负值为偏黄,正值为偏蓝。
+
+
### Gamma
改变图像的Gamma值。
@@ -372,6 +393,7 @@ git clone https://github.com/chflame163/ComfyUI_LayerStyle.git
* contrast: 图像的对比度。
* saturation: 图像的色彩饱和度。
+
### RGB
对图像的RGB各通道进行调整。
diff --git a/image/color_balance_example.png b/image/color_balance_example.png
new file mode 100644
index 0000000..33a63c5
Binary files /dev/null and b/image/color_balance_example.png differ
diff --git a/image/color_balance_node.png b/image/color_balance_node.png
new file mode 100644
index 0000000..f1e5bd4
Binary files /dev/null and b/image/color_balance_node.png differ
diff --git a/image/color_temperature_example.png b/image/color_temperature_example.png
new file mode 100644
index 0000000..9447311
Binary files /dev/null and b/image/color_temperature_example.png differ
diff --git a/image/color_temperature_node.png b/image/color_temperature_node.png
new file mode 100644
index 0000000..90c20a8
Binary files /dev/null and b/image/color_temperature_node.png differ
diff --git a/py/color_correct_color_balance.py b/py/color_correct_color_balance.py
new file mode 100644
index 0000000..b76a99d
--- /dev/null
+++ b/py/color_correct_color_balance.py
@@ -0,0 +1,74 @@
+from .imagefunc import *
+
+
+NODE_NAME = 'ColorBalance'
+
+class ColorBalance:
+
+ def __init__(self):
+ pass
+
+ @classmethod
+ def INPUT_TYPES(self):
+
+ return {
+ "required": {
+ "image": ("IMAGE", ), #
+ "cyan_red": ("FLOAT", {"default": 0, "min": -1.0, "max": 1.0, "step": 0.001}),
+ "magenta_green": ("FLOAT", {"default": 0, "min": -1.0, "max": 1.0, "step": 0.001}),
+ "yellow_blue": ("FLOAT", {"default": 0, "min": -1.0, "max": 1.0, "step": 0.001})
+ },
+ "optional": {
+ }
+ }
+
+ RETURN_TYPES = ("IMAGE",)
+ RETURN_NAMES = ("image",)
+ FUNCTION = 'color_balance'
+ CATEGORY = '😺dzNodes/LayerColor'
+
+ def color_balance(self, image, cyan_red, magenta_green, yellow_blue):
+
+ l_images = []
+ l_masks = []
+ ret_images = []
+
+ for l in image:
+ l_images.append(torch.unsqueeze(l, 0))
+ m = tensor2pil(l)
+ if m.mode == 'RGBA':
+ l_masks.append(m.split()[-1])
+ else:
+ l_masks.append(Image.new('L', m.size, 'white'))
+
+
+ for i in range(len(l_images)):
+ _image = l_images[i]
+ _mask = l_masks[i]
+ orig_image = tensor2pil(_image)
+
+ ret_image = color_balance(orig_image,
+ [cyan_red, magenta_green, yellow_blue],
+ [cyan_red, magenta_green, yellow_blue],
+ [cyan_red, magenta_green, yellow_blue],
+ shadow_center=0.15,
+ midtone_center=0.5,
+ midtone_max=1,
+ preserve_luminosity=True)
+
+ if orig_image.mode == 'RGBA':
+ ret_image = RGB2RGBA(ret_image, orig_image.split()[-1])
+
+ ret_images.append(pil2tensor(ret_image))
+
+ log(f"{NODE_NAME} Processed {len(ret_images)} image(s).", message_type='finish')
+ return (torch.cat(ret_images, dim=0),)
+
+
+NODE_CLASS_MAPPINGS = {
+ "LayerColor: ColorBalance": ColorBalance
+}
+
+NODE_DISPLAY_NAME_MAPPINGS = {
+ "LayerColor: ColorBalance": "LayerColor: ColorBalance"
+}
\ No newline at end of file
diff --git a/py/color_correct_color_temperature.py b/py/color_correct_color_temperature.py
new file mode 100644
index 0000000..680e09a
--- /dev/null
+++ b/py/color_correct_color_temperature.py
@@ -0,0 +1,57 @@
+# Adapt from https://github.com/EllangoK/ComfyUI-post-processing-nodes/blob/master/post_processing/color_correct.py
+
+from .imagefunc import *
+
+NODE_NAME = 'ColorTemperature'
+
+class ColorTemperature:
+ @classmethod
+ def INPUT_TYPES(s):
+ return {
+ "required": {
+ "image": ("IMAGE",),
+ "temperature": ("FLOAT", {"default": 0, "min": -100, "max": 100, "step": 1},),
+ },
+ }
+
+ RETURN_TYPES = ("IMAGE",)
+ RETURN_NAMES = ("image",)
+ FUNCTION = "color_temperature"
+ CATEGORY = '😺dzNodes/LayerColor'
+
+ def color_temperature(self, image, temperature,
+ ):
+
+ batch_size, height, width, _ = image.shape
+ result = torch.zeros_like(image)
+
+ temperature /= -100
+
+ for b in range(batch_size):
+ tensor_image = image[b].numpy()
+ modified_image = Image.fromarray((tensor_image * 255).astype(np.uint8))
+ modified_image = np.array(modified_image).astype(np.float32)
+
+ if temperature > 0:
+ modified_image[:, :, 0] *= 1 + temperature
+ modified_image[:, :, 1] *= 1 + temperature * 0.4
+ elif temperature < 0:
+ modified_image[:, :, 0] *= 1 + temperature * 0.2
+ modified_image[:, :, 2] *= 1 - temperature
+
+ modified_image = np.clip(modified_image, 0, 255)
+ modified_image = modified_image.astype(np.uint8)
+ modified_image = modified_image / 255
+ modified_image = torch.from_numpy(modified_image).unsqueeze(0)
+ result[b] = modified_image
+
+ log(f"{NODE_NAME} Processed {len(result)} image(s).", message_type='finish')
+ return (result,)
+
+NODE_CLASS_MAPPINGS = {
+ "LayerColor: ColorTemperature": ColorTemperature
+}
+
+NODE_DISPLAY_NAME_MAPPINGS = {
+ "LayerColor: ColorTemperature": "LayerColor: ColorTemperature"
+}
\ No newline at end of file