commit LightLeak node

This commit is contained in:
chflame
2024-02-26 23:29:59 +08:00
parent 3aac72f95d
commit 7ccd6ec331
7 changed files with 130 additions and 15 deletions
+1 -2
View File
@@ -2,5 +2,4 @@ _test_*.*
__pycache__
.venv
.idea
*.pth
pickle
*.pth
+17 -5
View File
@@ -17,7 +17,7 @@ Nodes are divided into 5 groups according to their functions: LayerStyle, LayerC
## Update
**If the dependency package error after updating, please reinstall the relevant dependency packages. for details, please refer to [here](https://github.com/chflame163/ComfyUI_LayerStyle/issues/5).
* Commit [LightLeak](#LightLeak) node, this filter simulate the light leakage effect of the film.
* Commit [Film](#Film) node, this filter simulate the grain, dark edge, and blurred edge of the film, support input depth map to simulate defocus. it is reorganize and encapsulate of [digitaljohn/comfyui-propost](https://github.com/digitaljohn/comfyui-propost).
* Commit [ImageAutoCrop](#ImageAutoCrop) node, which is designed to generate image materials for training models.
* Commit [ImageScaleByAspectRatio](#ImageScaleByAspectRatio) node, it can be scaled image or mask according to frame ratio.
@@ -671,13 +671,13 @@ Output:
Improvements to [ComfyUI Segment Anything](https://github.com/storyicon/comfyui_segment_anything), combined with the Alpha Matte node of [ComfyUI-Image-Filters](https://github.com/spacepxl/ComfyUI-Image-Filters) in spacepxl, result in more detailed edges for masks.
*Please refer to the installation of ComfyUI Segment Anything to install the model. If ComfyUI Segment Anything has been correctly installed, you can skip this step.
* From [here](https://huggingface.co/bert-base-uncased/tree/main) download the config.json,model.safetensors,tokenizer_config.json,tokenizer.json 和 vocab.txt 5 files to ComfyUI/models/bert-base-uncased folder.
* From [here](https://huggingface.co/bert-base-uncased/tree/main) download the config.json,model.safetensors,tokenizer_config.json,tokenizer.json and vocab.txt 5 files to ```ComfyUI/models/bert-base-uncased``` folder.
* Download [GroundingDINO_SwinT_OGC config file](https://huggingface.co/ShilongLiu/GroundingDINO/resolve/main/GroundingDINO_SwinT_OGC.cfg.py), [GroundingDINO_SwinT_OGC model](https://huggingface.co/ShilongLiu/GroundingDINO/resolve/main/groundingdino_swint_ogc.pth),
[GroundingDINO_SwinB config file](https://huggingface.co/ShilongLiu/GroundingDINO/resolve/main/GroundingDINO_SwinB.cfg.py), [GroundingDINO_SwinB model](https://huggingface.co/ShilongLiu/GroundingDINO/resolve/main/groundingdino_swinb_cogcoor.pth) to ComfyUI/models/grounding-dino folder.
[GroundingDINO_SwinB config file](https://huggingface.co/ShilongLiu/GroundingDINO/resolve/main/GroundingDINO_SwinB.cfg.py), [GroundingDINO_SwinB model](https://huggingface.co/ShilongLiu/GroundingDINO/resolve/main/groundingdino_swinb_cogcoor.pth) to ```ComfyUI/models/grounding-dino``` folder.
* Download [sam_vit_h](https://dl.fbaipublicfiles.com/segment_anything/sam_vit_h_4b8939.pth),[sam_vit_l](https://dl.fbaipublicfiles.com/segment_anything/sam_vit_l_0b3195.pth),
[sam_vit_b](https://dl.fbaipublicfiles.com/segment_anything/sam_vit_b_01ec64.pth), [sam_hq_vit_h](https://huggingface.co/lkeab/hq-sam/resolve/main/sam_hq_vit_h.pth),
[sam_hq_vit_l](https://huggingface.co/lkeab/hq-sam/resolve/main/sam_hq_vit_l.pth), [sam_hq_vit_b](https://huggingface.co/lkeab/hq-sam/resolve/main/sam_hq_vit_b.pth),
[mobile_sam](https://github.com/ChaoningZhang/MobileSAM/blob/master/weights/mobile_sam.pt) to ComfyUI/models/sams folder.
[mobile_sam](https://github.com/ChaoningZhang/MobileSAM/blob/master/weights/mobile_sam.pt) to ```ComfyUI/models/sams``` folder.
![image](image/segment_anything_ultra_compare.png)
![image](image/segment_anything_ultra_example.png)
@@ -699,7 +699,7 @@ Remove background. compared to the similar background removal nodes, this node h
This node combines the Alpha Matte node of Spacepxl's [ComfyUI-Image-Filters](https://github.com/spacepxl/ComfyUI-Image-Filters) and the functionality of ZHO-ZHO-ZHO's [ComfyUI-BRIA_AI-RMBG](https://github.com/ZHO-ZHO-ZHO/ComfyUI-BRIA_AI-RMBG).
*Download the [BRIA Background Removal v1.4](https://huggingface.co/briaai/RMBG-1.4) model file (model. pth) to the /ComfyUI/models/rmbg/RMBG-1.4 folder. This model was developed by BRIA AI and can be used as an open-source model for non-commercial purposes.
*Download the [BRIA Background Removal v1.4](https://huggingface.co/briaai/RMBG-1.4) model file (```model.pth```) to the ```/ComfyUI/models/rmbg/RMBG-1.4``` folder. This model was developed by BRIA AI and can be used as an open-source model for non-commercial purposes.
**After downloading the model, recommended to add a line 'rmbg: models/rmbg/RMBG-1.4' in ComfyUI/extra_model_paths.yaml. (This step is not mandatory)
![image](image/rembg_ultra_example.png)
@@ -907,6 +907,18 @@ Node options:
* blur_focus_spread: Focus diffusion range. larger value means larger clear range.
* focal_depth: Simulate the focal distance of defucus. 0 indicates that focus is farthest, and 1 indicates that is closest. this setting only valid when input the depth_map.
### <a id="table1">LightLeak</a>
Simulate the light leakage effect of the film. please download the [light_leak.pkl(on Baidu Netdisk)](https://pan.baidu.com/s/1QY1ZyYm885krrqDB2t8lPg?pwd=yvs3), copy the file to ```ComfyUI/models/layerstyle``` folder.
![image](image/light_leak_example.png)
Node options:
![image](image/light_leak_node.png)
* light: 32 types of light spots are provided. random is a random selection.
* corner: There are four options for the corner where the light appears: top left, top right, bottom left, and bottom right.
* hue: The hue of the light.
* saturation: The color saturation of the light.
* opacity: The opacity of the light.
### <a id="table1">ColorMap</a>
Pseudo color heat map effect.
![image](image/colormap_result.png)
+20 -8
View File
@@ -13,10 +13,11 @@
## 更新说明
**如果本插件更新后出现依赖包错误,请重新安装相关依赖包。详情见[这里](https://github.com/chflame163/ComfyUI_LayerStyle/issues/5)。
* 添加 [Film](#Film) 节点, 这个滤镜模拟胶片的颗粒、暗边和边缘模糊,支持输入深度图模拟虚焦,是[digitaljohn/comfyui-propost](https://github.com/digitaljohn/comfyui-propost)的重新封装。
* 添加 [ImageAutoCrop](#ImageAutoCrop) 节点, 这个节点是为生成训练模型的图片素材而设计的。
* 添加 [ImageScaleByAspectRatio](#ImageScaleByAspectRatio) 节点, 可按画幅比例缩放图像。
* 改正 [LUT Apply](#LUT) 节点渲染出现色阶的bug, 并增加log色彩空间支持。*log色彩空间图片请加载专门的log lut。
* 添加[LightLeak](#LightLeak) 节点,这个滤镜模拟胶片漏光效果。
* 添加[Film](#Film) 节点, 这个滤镜模拟胶片的颗粒、暗边和边缘模糊,支持输入深度图模拟虚焦,是[digitaljohn/comfyui-propost](https://github.com/digitaljohn/comfyui-propost)的重新封装。
* 添加[ImageAutoCrop](#ImageAutoCrop) 节点, 这个节点是为生成训练模型的图片素材而设计的。
* 添加[ImageScaleByAspectRatio](#ImageScaleByAspectRatio) 节点, 可按画幅比例缩放图像。
* 改正[LUT Apply](#LUT) 节点渲染出现色阶的bug, 并增加log色彩空间支持。*log色彩空间图片请加载专门的log lut。
* 添加[CreateGradientMask](#CreateGradientMask) 节点。添加 [LayerImageTransform](#LayerImageTransform) 和 [LayerMaskTransform](#LayerMaskTransform) 节点。
* 添加[MaskEdgeUltraDetail](#MaskEdgeUltraDetail) 节点,给粗糙的遮罩进行处理获得超精细的边缘。添加 [Exposure](#Exposure) 节点,调整图像曝光。
* 添加[Sharp & Soft](#Sharp) 节点,可提升或抹平图像细节。新增[MaskByDifferent](#MaskByDifferent)节点,比较两张图片并输出Mask。新增[SegmentAnythingUltra](#SegmentAnythingUltra)节点,提升遮罩边缘质量。*如果没有安装SegmentAnything, 需要手动下载模型。
@@ -658,13 +659,13 @@ cropped_mask:
对[ComfyUI Segment Anything](https://github.com/storyicon/comfyui_segment_anything)的改进,结合了spacepxl的[ComfyUI-Image-Filters](https://github.com/spacepxl/ComfyUI-Image-Filters)的Alpha Matte节点,使遮罩有更具细节的边缘。
*请参照ComfyUI Segment Anything的安装方法安装模型。如果已经正确安装了ComfyUI Segment Anything,可跳过此步骤。
* 从 [这里](https://huggingface.co/bert-base-uncased/tree/main) 下载 config.json,model.safetensors,tokenizer_config.json,tokenizer.json 和 vocab.txt 5个文件到 ComfyUI/models/bert-base-uncased文件夹。
* 从 [这里](https://huggingface.co/bert-base-uncased/tree/main) 下载 config.json,model.safetensors,tokenizer_config.json,tokenizer.json 和 vocab.txt 5个文件到 ```ComfyUI/models/bert-base-uncased```文件夹。
* 下载 [GroundingDINO_SwinT_OGC config file](https://huggingface.co/ShilongLiu/GroundingDINO/resolve/main/GroundingDINO_SwinT_OGC.cfg.py), [GroundingDINO_SwinT_OGC model](https://huggingface.co/ShilongLiu/GroundingDINO/resolve/main/groundingdino_swint_ogc.pth),
[GroundingDINO_SwinB config file](https://huggingface.co/ShilongLiu/GroundingDINO/resolve/main/GroundingDINO_SwinB.cfg.py), [GroundingDINO_SwinB model](https://huggingface.co/ShilongLiu/GroundingDINO/resolve/main/groundingdino_swinb_cogcoor.pth) 到 ComfyUI/models/grounding-dino文件夹。
[GroundingDINO_SwinB config file](https://huggingface.co/ShilongLiu/GroundingDINO/resolve/main/GroundingDINO_SwinB.cfg.py), [GroundingDINO_SwinB model](https://huggingface.co/ShilongLiu/GroundingDINO/resolve/main/groundingdino_swinb_cogcoor.pth) 到 ```ComfyUI/models/grounding-dino```文件夹。
* 下载 [sam_vit_h](https://dl.fbaipublicfiles.com/segment_anything/sam_vit_h_4b8939.pth),[sam_vit_l](https://dl.fbaipublicfiles.com/segment_anything/sam_vit_l_0b3195.pth),
[sam_vit_b](https://dl.fbaipublicfiles.com/segment_anything/sam_vit_b_01ec64.pth), [sam_hq_vit_h](https://huggingface.co/lkeab/hq-sam/resolve/main/sam_hq_vit_h.pth),
[sam_hq_vit_l](https://huggingface.co/lkeab/hq-sam/resolve/main/sam_hq_vit_l.pth), [sam_hq_vit_b](https://huggingface.co/lkeab/hq-sam/resolve/main/sam_hq_vit_b.pth),
[mobile_sam](https://github.com/ChaoningZhang/MobileSAM/blob/master/weights/mobile_sam.pt) 这几个文件到ComfyUI/models/sams文件夹。
[mobile_sam](https://github.com/ChaoningZhang/MobileSAM/blob/master/weights/mobile_sam.pt) 这几个文件到```ComfyUI/models/sams```文件夹。
![image](image/segment_anything_ultra_compare.png)
![image](image/segment_anything_ultra_example.png)
@@ -685,7 +686,7 @@ cropped_mask:
去除背景。与类似的背景移除节点相比,这个节点具有超高的边缘细节。
本节点结合了spacepxl的[ComfyUI-Image-Filters](https://github.com/spacepxl/ComfyUI-Image-Filters)的Alpha Matte节点,以及ZHO-ZHO-ZHO的[ComfyUI-BRIA_AI-RMBG](https://github.com/ZHO-ZHO-ZHO/ComfyUI-BRIA_AI-RMBG)的功能。
*将[BRIA Background Removal v1.4](https://huggingface.co/briaai/RMBG-1.4)模型文件(model.pth)下载至/ComfyUI/models/rmbg/RMBG-1.4文件夹。该模型由 BRIA AI 开发,可作为非商业用途的开源模型。
*将[BRIA Background Removal v1.4](https://huggingface.co/briaai/RMBG-1.4)模型文件(model.pth)下载至```ComfyUI/models/rmbg/RMBG-1.4```文件夹。该模型由 BRIA AI 开发,可作为非商业用途的开源模型。
**下载模型后,建议在ComfyUI/extra_model_paths.yaml中添加一行'rmbg: models/rmbg/RMBG-1.4'。(此步骤非必须)
@@ -895,6 +896,17 @@ mask
* blur_focus_spread: 焦点扩散范围。数值越大,清晰的范围越大。
* focal_depth: 模拟虚焦的焦点距离。0表示焦点在最远,1表示焦点在最近。此项设置只在depth_map有输入时才生效。
### <a id="table1">LightLeak</a>
模拟胶片漏光效果。请下载[light_leak.pkl(百度网盘)](https://pan.baidu.com/s/1QY1ZyYm885krrqDB2t8lPg?pwd=yvs3)将文件复制到```ComfyUI/models/layerstyle``` 文件夹。
![image](image/light_leak_example.png)
节点选项说明:
![image](image/light_leak_node.png)
* light: 提供了32种光斑。random为随机选择。
* corner: 光斑出现的角落,有左上、右上、左下和右下4个选项。
* hue: 光斑的色相。
* saturation: 光斑的色彩饱和度。
* opacity: 光斑的不透明度。
### <a id="table1">ColorMap</a>
伪彩色热力图效果。
Binary file not shown.

After

Width:  |  Height:  |  Size: 2.3 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 111 KiB

+6
View File
@@ -55,6 +55,8 @@ except ImportError as e:
'''pickle'''
def read_image(filename:str) -> Image:
return Image.open(filename)
@@ -67,6 +69,10 @@ def load_pickle(file_name:str) -> object:
obj = pickle.load(f)
return obj
def load_light_leak_images() -> list:
file = os.path.join(COMFY_FOLDER_PATH.models_dir, "layerstyle", "light_leak.pkl")
return load_pickle(file)
'''Converter'''
def cv22ski(cv2_image:np.ndarray) -> np.array:
+86
View File
@@ -0,0 +1,86 @@
import os.path
import random
import time
from .imagefunc import *
NODE_NAME = 'LightLeak'
blend_mode = 'screen'
class LightLeak:
def __init__(self):
pass
@classmethod
def INPUT_TYPES(self):
light_list = ['random', '1', '2', '3', '4', '5', '6', '7', '8', '9', '10',
'11', '12', '13', '14', '15', '16', '17', '18', '19', '20',
'21', '22', '23', '24', '25', '26', '27', '28', '29', '30',
'31', '32']
corner_list = ['left_top', 'right_top', 'left_bottom', 'right_bottom']
return {
"required": {
"image": ("IMAGE", ),
"light": (light_list,),
"corner": (corner_list,),
"hue": ("INT", {"default": 0, "min": -255, "max": 255, "step": 1}),
"saturation": ("INT", {"default": 0, "min": -255, "max": 255, "step": 1}),
"opacity": ("INT", {"default": 100, "min": 0, "max": 100, "step": 1})
},
"optional": {
}
}
RETURN_TYPES = ("IMAGE",)
RETURN_NAMES = ("image",)
FUNCTION = 'light_leak'
CATEGORY = '😺dzNodes/LayerFilter'
OUTPUT_NODE = True
def light_leak(self, image, light, corner, hue, saturation, opacity):
ret_images = []
light_leak_images = load_light_leak_images()
if light == 'random':
random.seed(time.time())
light_index = random.randint(0,31)
else:
light_index = int(light) - 1
for i in image:
i = torch.unsqueeze(i, 0)
_canvas = tensor2pil(i).convert('RGB')
_light = light_leak_images[light_index]
if _canvas.width < _canvas.height:
_light = _light.transpose(Image.ROTATE_90).transpose(Image.FLIP_TOP_BOTTOM)
if corner == 'right_top':
_light = _light.transpose(Image.FLIP_LEFT_RIGHT)
elif corner == 'left_bottom':
_light = _light.transpose(Image.FLIP_TOP_BOTTOM)
elif corner == 'right_bottom':
_light = _light.transpose(Image.ROTATE_180)
if hue != 0 or saturation != 0:
_h, _s, _v = _light.convert('HSV').split()
if hue != 0:
_h = image_hue_offset(_h, hue)
if saturation != 0:
_s = image_gray_offset(_s, saturation)
_light = image_channel_merge((_h, _s, _v), 'HSV')
resize_sampler = Image.BILINEAR
_light = fit_resize_image(_light, _canvas.width, _canvas.height, fit='crop', resize_sampler=resize_sampler)
ret_image = chop_image(_canvas, _light, blend_mode=blend_mode, opacity = opacity)
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 = {
"LayerFilter: LightLeak": LightLeak
}
NODE_DISPLAY_NAME_MAPPINGS = {
"LayerFilter: LightLeak": "LayerFilter: LightLeak"
}