fix ImageRemoveAlpha node add optional mask input

This commit is contained in:
chflame
2024-06-13 10:58:57 +08:00
parent 277ed9805b
commit 32dee1e041
4 changed files with 21 additions and 9 deletions
+3 -1
View File
@@ -80,7 +80,7 @@ When this error has occurred, please check the network environment.
## Update
<font size="4">**If the dependency package error after updating, please reinstall the relevant dependency packages. </font><br />
* [ImageRemoveAlpha](#ImageRemoveAlpha) node add optional mask input.
* Commit [HLFrequencyDetailRestore](#HLFrequencyDetailRestore) node, Using low-frequency filtering and high-frequency preserving to restore image details, the fusion is better.
* Commit [AddGrain](#AddGrain) and [MaskGrain](#MaskGrain) nodes, Add noise to a picture or mask.
* Commit [FilmV2](#FilmV2) node, The fastgrain method is added on the basis of the previous one, and the noise generation speed is 10 times faster.
@@ -1002,6 +1002,8 @@ Remove the alpha channel from the image and convert it to RGB mode. you can choo
Node options:
![image](image/image_remove_alpha_node.jpg)
* RGBA_image: The input image supports RGBA or RGB modes.
* mask: Optional input mask. If there is an input mask, it will be used first, ignoring the alpha that comes with RGBA_image.
* fill_background: Whether to fill the background.
* background_color<sup>4</sup>: Color of background.
+3
View File
@@ -80,6 +80,7 @@ git clone https://github.com/chflame163/ComfyUI_LayerStyle.git
## 更新说明
<font size="4">**如果本插件更新后出现依赖包错误,请重新安装相关依赖包。
* [ImageRemoveAlpha](#ImageRemoveAlpha) 节点增加mask可选输入。
* 添加 [HLFrequencyDetailRestore](#HLFrequencyDetailRestore)节点, 使用低频滤波加保留高频来恢复图像细节,图像融合性更好。
* 添加 [AddGrain](#AddGrain) 和 [MaskGrain](#MaskGrain) 节点, 为图片或遮罩添加噪声。
* 添加 [FilmV2](#FilmV2) 节点, 在之前基础上增加了fastgrain方法,生成噪点速度加快了10倍。
@@ -990,6 +991,8 @@ GradientImage的V2升级版。
节点选项说明:
![image](image/image_remove_alpha_node.jpg)
* RGBA_image: 输入的图像,支持RGBA或RGB模式。
* mask:可选输入遮罩。如果有输入遮罩将优先使用, 忽略RGBA_image自带的alpha。
* fill_background: 是否填充背景。
* background_color<sup>4</sup>: 背景颜色。
Binary file not shown.

Before

Width:  |  Height:  |  Size: 59 KiB

After

Width:  |  Height:  |  Size: 38 KiB

+15 -8
View File
@@ -17,6 +17,7 @@ class ImageRemoveAlpha:
"background_color": ("STRING", {"default": "#000000"}),
},
"optional": {
"mask": ("MASK",), #
}
}
@@ -25,21 +26,27 @@ class ImageRemoveAlpha:
FUNCTION = 'image_remove_alpha'
CATEGORY = '😺dzNodes/LayerUtility'
def image_remove_alpha(self, RGBA_image, fill_background, background_color):
def image_remove_alpha(self, RGBA_image, fill_background, background_color, mask=None):
ret_images = []
for i in RGBA_image:
i = torch.unsqueeze(i, 0)
_image = tensor2pil(i)
if _image.mode != "RGBA":
log(f"Error: {NODE_NAME} skipped, because the input image is not RGBA.", message_type='error')
return (RGBA_image)
for index, img in enumerate(RGBA_image):
_image = tensor2pil(img)
if fill_background:
alpha = _image.split()[-1]
if mask is not None:
m = mask[index].unsqueeze(0) if index < len(mask) else mask[-1].unsqueeze(0)
alpha = tensor2pil(m).convert('L')
elif _image.mode == "RGBA":
alpha = _image.split()[-1]
else:
log(f"Error: {NODE_NAME} skipped, because the input image is not RGBA and mask is None.",
message_type='error')
return (RGBA_image,)
ret_image = Image.new('RGB', size=_image.size, color=background_color)
ret_image.paste(_image, mask=alpha)
ret_images.append(pil2tensor(ret_image))
else:
ret_images.append(pil2tensor(tensor2pil(i).convert('RGB')))