Skip to content

Masks Combine Regions

Documentation

  • Class name: Masks Combine Regions
  • Category: WAS Suite/Image/Masking
  • Output node: False

The node is designed to merge or combine multiple mask regions into a single cohesive mask. This process is essential for applications requiring unified mask representations from segmented or individually processed mask regions.

Input types

Required

  • mask_a
    • The 'mask_a' parameter represents one of the individual mask regions to be combined. It is a crucial part of the input set for generating a unified mask.
    • Comfy dtype: MASK
    • Python dtype: torch.Tensor
  • mask_b
    • The 'mask_b' parameter is another individual mask region that contributes to the creation of a unified mask. It is essential for the combination process.
    • Comfy dtype: MASK
    • Python dtype: torch.Tensor

Optional

  • mask_c
    • The 'mask_c' parameter is an optional mask region that can be included in the combination process to contribute to the unified mask.
    • Comfy dtype: MASK
    • Python dtype: torch.Tensor
  • mask_d
    • The 'mask_d' parameter is an optional mask region that can be included in the combination process to contribute to the unified mask.
    • Comfy dtype: MASK
    • Python dtype: torch.Tensor
  • mask_e
    • The 'mask_e' parameter is an optional mask region that can be included in the combination process to contribute to the unified mask.
    • Comfy dtype: MASK
    • Python dtype: torch.Tensor
  • mask_f
    • The 'mask_f' parameter is an optional mask region that can be included in the combination process to contribute to the unified mask.
    • Comfy dtype: MASK
    • Python dtype: torch.Tensor

Output types

  • mask
    • Comfy dtype: MASK
    • The 'mask' output represents the unified mask generated by combining the input mask regions. It is significant for downstream tasks that require a single, comprehensive mask representation.
    • Python dtype: torch.Tensor

Usage tips

  • Infra type: GPU
  • Common nodes: unknown

Source code

class WAS_Mask_Combine:

    def __init__(self):
        self.WT = WAS_Tools_Class()

    @classmethod
    def INPUT_TYPES(cls):
        return {
                    "required": {
                        "mask_a": ("MASK",),
                        "mask_b": ("MASK",),
                    },
                    "optional": {
                        "mask_c": ("MASK",),
                        "mask_d": ("MASK",),
                        "mask_e": ("MASK",),
                        "mask_f": ("MASK",),
                    }
                }

    CATEGORY = "WAS Suite/Image/Masking"

    RETURN_TYPES = ("MASK",)

    FUNCTION = "combine_masks"

    def combine_masks(self, mask_a, mask_b, mask_c=None, mask_d=None, mask_e=None, mask_f=None):
        masks = [mask_a, mask_b]
        if mask_c:
            masks.append(mask_c)
        if mask_d:
            masks.append(mask_d)
        if mask_e:
            masks.append(mask_e)
        if mask_f:
            masks.append(mask_f)
        combined_mask = torch.sum(torch.stack(masks, dim=0), dim=0)
        combined_mask = torch.clamp(combined_mask, 0, 1)  # Ensure values are between 0 and 1
        return (combined_mask, )