Rename GetMaskSize to GetMaskSizeAndCount and add image equivalent

This commit is contained in:
Kijai 2024-05-03 13:50:47 +03:00
parent 811baef799
commit 4d25b205b5
4 changed files with 58 additions and 11 deletions

View File

@ -30,7 +30,7 @@ NODE_CONFIG = {
"CreateShapeMask": {"class": CreateShapeMask, "name": "Create Shape Mask"}, "CreateShapeMask": {"class": CreateShapeMask, "name": "Create Shape Mask"},
"CreateVoronoiMask": {"class": CreateVoronoiMask, "name": "Create Voronoi Mask"}, "CreateVoronoiMask": {"class": CreateVoronoiMask, "name": "Create Voronoi Mask"},
"CreateMagicMask": {"class": CreateMagicMask, "name": "Create Magic Mask"}, "CreateMagicMask": {"class": CreateMagicMask, "name": "Create Magic Mask"},
"GetMaskSize": {"class": GetMaskSize, "name": "Get Mask Size"}, "GetMaskSizeAndCount": {"class": GetMaskSizeAndCount, "name": "Get Mask Size & Count"},
"GrowMaskWithBlur": {"class": GrowMaskWithBlur, "name": "Grow Mask With Blur"}, "GrowMaskWithBlur": {"class": GrowMaskWithBlur, "name": "Grow Mask With Blur"},
"MaskBatchMulti": {"class": MaskBatchMulti, "name": "Mask Batch Multi"}, "MaskBatchMulti": {"class": MaskBatchMulti, "name": "Mask Batch Multi"},
"OffsetMask": {"class": OffsetMask, "name": "Offset Mask"}, "OffsetMask": {"class": OffsetMask, "name": "Offset Mask"},
@ -38,8 +38,9 @@ NODE_CONFIG = {
"ResizeMask": {"class": ResizeMask, "name": "Resize Mask"}, "ResizeMask": {"class": ResizeMask, "name": "Resize Mask"},
"RoundMask": {"class": RoundMask, "name": "Round Mask"}, "RoundMask": {"class": RoundMask, "name": "Round Mask"},
#images #images
"ColorMatch": {"class": ColorMatch, "name": "Color Match"},
"AddLabel": {"class": AddLabel, "name": "Add Label"}, "AddLabel": {"class": AddLabel, "name": "Add Label"},
"ColorMatch": {"class": ColorMatch, "name": "Color Match"},
"GetImageSizeAndCount": {"class": GetImageSizeAndCount, "name": "Get Image Size & Count"},
"ImageAndMaskPreview": {"class": ImageAndMaskPreview}, "ImageAndMaskPreview": {"class": ImageAndMaskPreview},
"ImageBatchMulti": {"class": ImageBatchMulti, "name": "Image Batch Multi"}, "ImageBatchMulti": {"class": ImageBatchMulti, "name": "Image Batch Multi"},
"ImageBatchTestPattern": {"class": ImageBatchTestPattern, "name": "Image Batch Test Pattern"}, "ImageBatchTestPattern": {"class": ImageBatchTestPattern, "name": "Image Batch Test Pattern"},

View File

@ -28,7 +28,7 @@ class ImagePass:
} }
RETURN_TYPES = ("IMAGE",) RETURN_TYPES = ("IMAGE",)
FUNCTION = "passthrough" FUNCTION = "passthrough"
CATEGORY = "KJNodes/misc" CATEGORY = "KJNodes/image"
DESCRIPTION = """ DESCRIPTION = """
Passes the image through without modifying it. Passes the image through without modifying it.
""" """
@ -455,7 +455,33 @@ ComfyUI/custom_nodes/ComfyUI-KJNodes/fonts
combined_images = processed_batch combined_images = processed_batch
return (combined_images,) return (combined_images,)
class GetImageSizeAndCount:
@classmethod
def INPUT_TYPES(s):
return {"required": {
"image": ("IMAGE",),
}}
RETURN_TYPES = ("IMAGE","INT", "INT", "INT",)
RETURN_NAMES = ("image", "width", "height", "count",)
FUNCTION = "getsize"
CATEGORY = "KJNodes/masking"
DESCRIPTION = """
Returns the width and height of the image,
and passes it through unchanged.
"""
def getsize(self, image):
width = image.shape[2]
height = image.shape[1]
count = image.shape[0]
return {"ui": {
"text": [f"{count}x{width}x{height}"]},
"result": (image, width, height, count)
}
class ImageBatchRepeatInterleaving: class ImageBatchRepeatInterleaving:
RETURN_TYPES = ("IMAGE",) RETURN_TYPES = ("IMAGE",)
@ -527,7 +553,7 @@ class ImageNormalize_Neg1_To_1:
}} }}
RETURN_TYPES = ("IMAGE",) RETURN_TYPES = ("IMAGE",)
FUNCTION = "normalize" FUNCTION = "normalize"
CATEGORY = "KJNodes/misc" CATEGORY = "KJNodes/image"
DESCRIPTION = """ DESCRIPTION = """
Normalize the images to be in the range [-1, 1] Normalize the images to be in the range [-1, 1]
""" """

View File

@ -823,7 +823,7 @@ class CreateVoronoiMask:
return (torch.stack(out, dim=0), 1.0 - torch.stack(out, dim=0),) return (torch.stack(out, dim=0), 1.0 - torch.stack(out, dim=0),)
class GetMaskSize: class GetMaskSizeAndCount:
@classmethod @classmethod
def INPUT_TYPES(s): def INPUT_TYPES(s):
return {"required": { return {"required": {
@ -836,7 +836,7 @@ class GetMaskSize:
CATEGORY = "KJNodes/masking" CATEGORY = "KJNodes/masking"
DESCRIPTION = """ DESCRIPTION = """
Returns the width and height of the mask, Returns the width and height of the mask,
and passes through the mask unchanged. and passes it through unchanged.
""" """

View File

@ -74,18 +74,38 @@ app.registerExtension({
} }
break; break;
case "GetMaskSize": case "GetMaskSizeAndCount":
const onConnectInput = nodeType.prototype.onConnectInput; const onGetMaskSizeConnectInput = nodeType.prototype.onConnectInput;
nodeType.prototype.onConnectInput = function (targetSlot, type, output, originNode, originSlot) { nodeType.prototype.onConnectInput = function (targetSlot, type, output, originNode, originSlot) {
const v = onConnectInput?.(this, arguments); const v = onGetMaskSizeConnectInput?.(this, arguments);
targetSlot.outputs[1]["name"] = "width" targetSlot.outputs[1]["name"] = "width"
targetSlot.outputs[2]["name"] = "height" targetSlot.outputs[2]["name"] = "height"
targetSlot.outputs[3]["name"] = "count" targetSlot.outputs[3]["name"] = "count"
return v; return v;
} }
const onExecuted = nodeType.prototype.onExecuted; const onGetMaskSizeExecuted = nodeType.prototype.onExecuted;
nodeType.prototype.onExecuted = function(message) { nodeType.prototype.onExecuted = function(message) {
const r = onExecuted? onExecuted.apply(this,arguments): undefined const r = onGetMaskSizeExecuted? onGetMaskSizeExecuted.apply(this,arguments): undefined
let values = message["text"].toString().split('x').map(Number);
this.outputs[1]["name"] = values[1] + " width"
this.outputs[2]["name"] = values[2] + " height"
this.outputs[3]["name"] = values[0] + " count"
return r
}
break;
case "GetImageSizeAndCount":
const onGetImageSizeConnectInput = nodeType.prototype.onConnectInput;
nodeType.prototype.onConnectInput = function (targetSlot, type, output, originNode, originSlot) {
const v = onGetImageSizeConnectInput?.(this, arguments);
targetSlot.outputs[1]["name"] = "width"
targetSlot.outputs[2]["name"] = "height"
targetSlot.outputs[3]["name"] = "count"
return v;
}
const onGetImageSizeExecuted = nodeType.prototype.onExecuted;
nodeType.prototype.onExecuted = function(message) {
const r = onGetImageSizeExecuted? onGetImageSizeExecuted.apply(this,arguments): undefined
let values = message["text"].toString().split('x').map(Number); let values = message["text"].toString().split('x').map(Number);
this.outputs[1]["name"] = values[1] + " width" this.outputs[1]["name"] = values[1] + " width"
this.outputs[2]["name"] = values[2] + " height" this.outputs[2]["name"] = values[2] + " height"