rename extand*.py to extend*.py

This commit is contained in:
chflame163
2024-09-04 22:22:58 +08:00
parent ac07d6032a
commit 62b0394685
4 changed files with 93 additions and 91 deletions
+2 -1
View File
@@ -103,6 +103,7 @@ When this error has occurred, please check the network environment.
## Update
<font size="4">**If the dependency package error after updating, please double clicking ```repair_dependency.bat``` (for Official ComfyUI Protable) or ```repair_dependency_aki.bat``` (for ComfyUI-aki-v1.x) in the plugin folder to reinstall the dependency packages. </font><br />
* [ExtendCanvasV2](#ExtendCanvasV2) node support negative value input, it means image will be cropped.
* The default title color of nodes is changed to blue-green, and nodes in LayerStyle, LayerColor, LayerMask, LayerUtility, and LayerFilter are distinguished by different colors.
* The Object Detector nodes added sort bbox option, which allows sorting from left to right, top to bottom, and large to small, making object selection more intuitive and convenient. The nodes released yesterday has been abandoned, please manually replace it with the new version node (sorry).
* Commit [SAM2Ultra](#SAM2Ultra), [SAM2VideoUltra](#SAM2VideoUltra), [ObjectDetectorFL2](#ObjectDetectorFL2), [ObjectDetectorYOLOWorld](#ObjectDetectorYOLOWorld), [ObjectDetectorYOLO8](#ObjectDetectorYOLO8), [ObjectDetectorMask](#ObjectDetectorMask) and [BBoxJoin](#BBoxJoin) nodes.
@@ -939,7 +940,7 @@ Node options:
### <a id="table1">ExtendCanvasV2</a>
V2 upgrade to ExtendCanvas.
Based on ExtendCanvas, color is modified to be a string type, and it supports external ```ColorPicker``` input.
Based on ExtendCanvas, color is modified to be a string type, and it supports external ```ColorPicker``` input, Support negative value input, it means image will be cropped.
![image](image/extend_canvas_v2_node.jpg)
### XY to <a id="table1">Percent</a>
+3 -2
View File
@@ -105,6 +105,7 @@ git clone https://github.com/chflame163/ComfyUI_LayerStyle.git
## 更新说明
<font size="4">**如果本插件更新后出现依赖包错误,请双击运行插件目录下的```install_requirements.bat```(官方便携包),或 ```install_requirements_aki.bat```(秋叶整合包) 重新安装依赖包。
* [ExtendCanvasV2](#ExtendCanvasV2) 节点支持负值输入,负值将被裁剪。
* 节点默认标题颜色改为蓝绿色,LayerStyle, LayerColor, LayerMask, LayerUtility 和 LayerFilter 的节点分别用不同的颜色区分。
* 合并 [heshengtao](https://github.com/heshengtao) 提交的PR, 添加[TextImageV2](#TextImageV2)节点,修改图片文字节点的缩放,字体间隔跟随缩放,坐标不再以文字左上角,而是整行文字的中心点。感谢作者的贡献。
* ObjectDectector节点组增加sort bbox功能, 可按从左到右、从上到下、从大到小排序,选择物体更直观方便。昨天发布的节点已放弃,请手动更换为新版节点(对不起)。
@@ -924,12 +925,12 @@ GetColorTone的V2升级版。可以指定获取主体或背景的主色或平均
* bottom: 底部扩展值。
* left: 左侧扩展值。
* right: 右侧扩展值。
* color; 画布颜色
* color: 画布颜色
### <a id="table1">ExtendCanvasV2</a>
ExtendCanvas的V2升级版。
在ExtendCanvas基础上修改了color为字符串类型,支持外接```ColorPicker```输入。
在ExtendCanvas基础上修改了color为字符串类型,支持外接```ColorPicker```输入。支持负值输入,负值将被裁剪。
![image](image/extend_canvas_v2_node.jpg)
+88 -88
View File
@@ -1,89 +1,89 @@
from .imagefunc import *
NODE_NAME = 'ExtendCanvas'
class ExtendCanvas:
def __init__(self):
pass
@classmethod
def INPUT_TYPES(self):
return {
"required": {
"image": ("IMAGE", ),
"invert_mask": ("BOOLEAN", {"default": True}), # 反转mask
"top": ("INT", {"default": 0, "min": 0, "max": 99999, "step": 1}),
"bottom": ("INT", {"default": 0, "min": 0, "max": 99999, "step": 1}),
"left": ("INT", {"default": 0, "min": 0, "max": 99999, "step": 1}),
"right": ("INT", {"default": 0, "min": 0, "max": 99999, "step": 1}),
"color": ("COLOR", {"default": "#000000"},),
},
"optional": {
"mask": ("MASK",), #
}
}
RETURN_TYPES = ("IMAGE", "MASK",)
RETURN_NAMES = ("image", "mask")
FUNCTION = 'extend_canvas'
CATEGORY = '😺dzNodes/LayerUtility'
def extend_canvas(self, image, invert_mask,
top, bottom, left, right, color,
mask=None,
):
l_images = []
l_masks = []
ret_images = []
ret_masks = []
for l in image:
l_images.append(torch.unsqueeze(l, 0))
m = tensor2pil(l)
if m.mode == 'RGBA':
l_masks.append(m.split()[-1])
if mask is not None:
if mask.dim() == 2:
mask = torch.unsqueeze(mask, 0)
l_masks = []
for m in mask:
if invert_mask:
m = 1 - m
l_masks.append(tensor2pil(torch.unsqueeze(m, 0)).convert('L'))
else:
if len(l_masks) == 0:
l_masks.append(Image.new('L', size=tensor2pil(l_images[0]).size, color='white'))
max_batch = max(len(l_images), len(l_masks))
for i in range(max_batch):
_image = l_images[i] if i < len(l_images) else l_images[-1]
_image = tensor2pil(_image).convert('RGB')
_mask = l_masks[i] if i < len(l_masks) else l_masks[-1]
width = _image.width + left + right
height = _image.height + top + bottom
_canvas = Image.new('RGB', (width, height), color)
_mask_canvas = Image.new('L', (width, height), "black")
_canvas.paste(_image, box=(left,top))
_mask_canvas.paste(_mask.convert('L'), box=(left, top))
ret_images.append(pil2tensor(_canvas))
ret_masks.append(image2mask(_mask_canvas))
log(f"{NODE_NAME} Processed {len(ret_images)} image(s).", message_type='finish')
return (torch.cat(ret_images, dim=0), torch.cat(ret_masks, dim=0),)
NODE_CLASS_MAPPINGS = {
"LayerUtility: ExtendCanvas": ExtendCanvas
}
NODE_DISPLAY_NAME_MAPPINGS = {
"LayerUtility: ExtendCanvas": "LayerUtility: ExtendCanvas"
from .imagefunc import *
NODE_NAME = 'ExtendCanvas'
class ExtendCanvas:
def __init__(self):
pass
@classmethod
def INPUT_TYPES(self):
return {
"required": {
"image": ("IMAGE", ),
"invert_mask": ("BOOLEAN", {"default": True}), # 反转mask
"top": ("INT", {"default": 0, "min": 0, "max": 99999, "step": 1}),
"bottom": ("INT", {"default": 0, "min": 0, "max": 99999, "step": 1}),
"left": ("INT", {"default": 0, "min": 0, "max": 99999, "step": 1}),
"right": ("INT", {"default": 0, "min": 0, "max": 99999, "step": 1}),
"color": ("COLOR", {"default": "#000000"},),
},
"optional": {
"mask": ("MASK",), #
}
}
RETURN_TYPES = ("IMAGE", "MASK",)
RETURN_NAMES = ("image", "mask")
FUNCTION = 'extend_canvas'
CATEGORY = '😺dzNodes/LayerUtility'
def extend_canvas(self, image, invert_mask,
top, bottom, left, right, color,
mask=None,
):
l_images = []
l_masks = []
ret_images = []
ret_masks = []
for l in image:
l_images.append(torch.unsqueeze(l, 0))
m = tensor2pil(l)
if m.mode == 'RGBA':
l_masks.append(m.split()[-1])
if mask is not None:
if mask.dim() == 2:
mask = torch.unsqueeze(mask, 0)
l_masks = []
for m in mask:
if invert_mask:
m = 1 - m
l_masks.append(tensor2pil(torch.unsqueeze(m, 0)).convert('L'))
else:
if len(l_masks) == 0:
l_masks.append(Image.new('L', size=tensor2pil(l_images[0]).size, color='white'))
max_batch = max(len(l_images), len(l_masks))
for i in range(max_batch):
_image = l_images[i] if i < len(l_images) else l_images[-1]
_image = tensor2pil(_image).convert('RGB')
_mask = l_masks[i] if i < len(l_masks) else l_masks[-1]
width = _image.width + left + right
height = _image.height + top + bottom
_canvas = Image.new('RGB', (width, height), color)
_mask_canvas = Image.new('L', (width, height), "black")
_canvas.paste(_image, box=(left,top))
_mask_canvas.paste(_mask.convert('L'), box=(left, top))
ret_images.append(pil2tensor(_canvas))
ret_masks.append(image2mask(_mask_canvas))
log(f"{NODE_NAME} Processed {len(ret_images)} image(s).", message_type='finish')
return (torch.cat(ret_images, dim=0), torch.cat(ret_masks, dim=0),)
NODE_CLASS_MAPPINGS = {
"LayerUtility: ExtendCanvas": ExtendCanvas
}
NODE_DISPLAY_NAME_MAPPINGS = {
"LayerUtility: ExtendCanvas": "LayerUtility: ExtendCanvas"
}