diff --git a/README.md b/README.md index 2d8479c..282ff17 100644 --- a/README.md +++ b/README.md @@ -57,6 +57,7 @@ This custom node helps to conveniently enhance images through Detector, Detailer * DetailerDebug (SEGS) - Refines the image based on SEGS. Additionally, it provides the ability to monitor the cropped image and the refined image of the cropped image. * To prevent regeneration caused by the seed that does not change every time when using 'external_seed', please disable the 'seed random generate' option in the 'Detailer...' node. * MASK to SEGS - Generates SEGS based on the mask. + * MASK to SEGS For AnimateDiff - Generates SEGS based on the mask for AnimateDiff. * MediaPipe FaceMesh to SEGS - Separate each landmark from the mediapipe facemesh image to create labeled SEGS. * Usually, the size of images created through the MediaPipe facemesh preprocessor is downscaled. It resizes the MediaPipe facemesh image to the original size given as reference_image_opt for matching sizes during processing. * ToBinaryMask - Separates the mask generated with alpha values between 0 and 255 into 0 and 255. The non-zero parts are always set to 255. diff --git a/__init__.py b/__init__.py index 6d81e29..3c5f995 100644 --- a/__init__.py +++ b/__init__.py @@ -173,6 +173,7 @@ NODE_CLASS_MAPPINGS = { "MediaPipeFaceMeshToSEGS": MediaPipeFaceMeshToSEGS, "MaskToSEGS": MaskToSEGS, + "MaskToSEGS_for_AnimateDiff": MaskToSEGS_for_AnimateDiff, "ToBinaryMask": ToBinaryMask, "MasksToMaskList": MasksToMaskList, "MaskListToMaskBatch": MaskListToMaskBatch, @@ -295,6 +296,7 @@ NODE_DISPLAY_NAME_MAPPINGS = { "SegsToCombinedMask": "SEGS to MASK (combined)", "MediaPipeFaceMeshToSEGS": "MediaPipe FaceMesh to SEGS", "MaskToSEGS": "MASK to SEGS", + "MaskToSEGS_for_AnimateDiff": "MASK to SEGS for AnimateDiff", "BitwiseAndMaskForEach": "Bitwise(SEGS & SEGS)", "SubtractMaskForEach": "Bitwise(SEGS - SEGS)", "ImpactSegsAndMask": "Bitwise(SEGS & MASK)", diff --git a/modules/impact/config.py b/modules/impact/config.py index ff67c6b..cef0a79 100644 --- a/modules/impact/config.py +++ b/modules/impact/config.py @@ -2,7 +2,7 @@ import configparser import os -version = "V4.34.2" +version = "V4.35" dependency_version = 19 diff --git a/modules/impact/core.py b/modules/impact/core.py index ee8ea97..8e7a0b5 100644 --- a/modules/impact/core.py +++ b/modules/impact/core.py @@ -915,8 +915,6 @@ def mask_to_segs(mask, combined, crop_factor, bbox_fill, drop_size=1, label='A', if len(mask.shape) == 2: mask = np.expand_dims(mask, axis=0) - else: - mask = np.squeeze(mask, axis=1) for i in range(mask.shape[0]): mask_i = mask[i] diff --git a/modules/impact/segs_nodes.py b/modules/impact/segs_nodes.py index 90c39ad..cfae3f3 100644 --- a/modules/impact/segs_nodes.py +++ b/modules/impact/segs_nodes.py @@ -11,6 +11,7 @@ from nodes import MAX_RESOLUTION from impact.utils import * import impact.core as core from impact.core import SEG +import impact.utils as utils class SEGSDetailer: @classmethod @@ -926,6 +927,40 @@ class MaskToSEGS: return (result, ) +class MaskToSEGS_for_AnimateDiff: + @classmethod + def INPUT_TYPES(s): + return {"required": { + "mask": ("MASK",), + "combined": ("BOOLEAN", {"default": False, "label_on": "True", "label_off": "False"}), + "crop_factor": ("FLOAT", {"default": 3.0, "min": 1.0, "max": 100, "step": 0.1}), + "bbox_fill": ("BOOLEAN", {"default": False, "label_on": "enabled", "label_off": "disabled"}), + "drop_size": ("INT", {"min": 1, "max": MAX_RESOLUTION, "step": 1, "default": 10}), + } + } + + RETURN_TYPES = ("SEGS",) + FUNCTION = "doit" + + CATEGORY = "ImpactPack/Operation" + + def doit(self, mask, combined, crop_factor, bbox_fill, drop_size): + if len(mask.shape) == 3: + mask = mask.squeeze(0) + + segs = core.mask_to_segs(mask, combined, crop_factor, bbox_fill, drop_size) + + all_masks = SEGSToMaskList().doit(segs)[0] + + result_mask = all_masks[0] + for mask in all_masks[1:]: + result_mask += mask + + result_mask = utils.to_binary_mask(result_mask, 0.1) + + return MaskToSEGS().doit(result_mask, False, crop_factor, False, drop_size) + + class ControlNetApplySEGS: @classmethod def INPUT_TYPES(s):