The MaskMotionBlur node create motion blur on the mask. The SoftLight node create the bright highlights on the screen appear blurry.
54 lines
2.0 KiB
Python
54 lines
2.0 KiB
Python
from .imagefunc import *
|
|
|
|
class SoftLight:
|
|
|
|
def __init__(self):
|
|
pass
|
|
|
|
@classmethod
|
|
def INPUT_TYPES(self):
|
|
|
|
return {
|
|
"required": {
|
|
"image": ("IMAGE", ), #
|
|
|
|
"soft": ("FLOAT", {"default": 1, "min": 0.2, "max": 10, "step": 0.01}), # 模糊
|
|
"threshold": ("INT", {"default": -10, "min": -255, "max": 255, "step": 1}), # 高光阈值
|
|
"opacity": ("INT", {"default": 100, "min": 0, "max": 100, "step": 1}), # 透明度
|
|
},
|
|
"optional": {
|
|
}
|
|
}
|
|
|
|
RETURN_TYPES = ("IMAGE",)
|
|
RETURN_NAMES = ("image",)
|
|
FUNCTION = 'soft_light'
|
|
CATEGORY = '😺dzNodes/LayerFilter'
|
|
OUTPUT_NODE = True
|
|
|
|
def soft_light(self, image, soft, threshold, opacity,):
|
|
blend_mode = 'screen'
|
|
_canvas = tensor2pil(image).convert('RGB')
|
|
blur = int((_canvas.width + _canvas.height) / 200 * soft)
|
|
_otsumask = gray_threshold(_canvas, otsu=True)
|
|
_removebkgd = remove_background(_canvas, _otsumask, '#000000').convert('L')
|
|
auto_threshold = get_image_bright_average(_removebkgd)
|
|
light_mask = gray_threshold(_canvas, auto_threshold + threshold)
|
|
highlight_mask = gray_threshold(_canvas, auto_threshold + (255 - auto_threshold) // 2 + threshold // 2)
|
|
blurimage = gaussian_blur(_canvas, soft).convert('RGB')
|
|
light = chop_image(_canvas, blurimage, blend_mode=blend_mode, opacity=opacity)
|
|
highlight = chop_image(light, blurimage, blend_mode=blend_mode, opacity=opacity)
|
|
_canvas.paste(highlight, mask=gaussian_blur(light_mask, blur * 2).convert('L'))
|
|
_canvas.paste(highlight, mask=gaussian_blur(highlight_mask, blur).convert('L'))
|
|
ret_image = _canvas
|
|
log('SoftLight Processed.')
|
|
|
|
return (pil2tensor(ret_image),)
|
|
|
|
NODE_CLASS_MAPPINGS = {
|
|
"LayerFilter: SoftLight": SoftLight
|
|
}
|
|
|
|
NODE_DISPLAY_NAME_MAPPINGS = {
|
|
"LayerFilter: SoftLight": "LayerFilter: SoftLight"
|
|
} |