FilterZeroMasksAndCorrespondingImages
This node takes a list of masks (MASK) as a required input and can optionally receive a list of images (IMAGE).
Filter Zero Masks And Corresponding Images
The FilterZeroMasksAndCorrespondingImages node receives a list of masks (MASK) as a required input and can optionally receive a list of images (IMAGE).
The FilterZeroMasksAndCorrespondingImages node is a tool for data cleaning and filtering. Its core function is to automatically identify and separate masks that are empty (contain no content), while simultaneously processing associated image data if provided. This node allows users to efficiently organize data within their workflow by removing invalid mask entries.
Node Functionality
This node receives a list of masks (MASK) as a required input and can optionally receive a list of images (IMAGE). Its internal mechanism involves iterating through all input masks and determining if a mask is empty by calculating the number of non-zero pixels. If an image list is provided, the node ensures its length matches the mask list. Then, based on the filtering results of the masks, it performs synchronized grouping of the images.
Node Parameter Description - FilterZeroMasksAndCorrespondingImages
Inputs
| Parameter Name | Data Type | Required | Default Value | Range/Options | Description |
|---|---|---|---|---|---|
masks | MASK | Yes | - | - | masks (Input Parameter): The input list of masks to be filtered. The node will check each mask for the presence of non-zero pixels. |
original_images | IMAGE | No | - | - | original_images (Input Parameter): An optional input list of images. Its count must exactly match the number of masks in the masks parameter. |
Outputs
| Parameter Name | Data Type | Description |
|---|---|---|
| non_zero_masks_out | MASK | non_zero_masks_out (Output Parameter): Outputs all valid, non-empty masks. |
| non_zero_mask_images_out | IMAGE | non_zero_mask_images_out (Output Parameter): Outputs the original images corresponding to the non-empty masks. |
| zero_mask_images_out | IMAGE | zero_mask_images_out (Output Parameter): Outputs the original images corresponding to the empty masks. |
| zero_mask_images_out_indexes | INDEXES | zero_mask_images_out_indexes (Output Parameter): Outputs the index positions of the empty masks within the original input list. |
Usage Scenarios
This node is very useful in workflows involving batch image generation with subsequent processing. For example, a user could first generate a batch of images and corresponding masks using multiple prompts, then connect the results to this node. The node will automatically filter out masks that did not generate valid content, outputting the masks with content and their corresponding images for the next refinement step, while separately outputting the images corresponding to empty masks for inspection.
Notes
If image input is provided, its count must strictly equal the number of masks; otherwise, the node will ignore the image input and issue a warning. This node does not modify the content of the masks or images themselves; it only regroups and indexes them based on whether the masks are entirely zero.
FilterZeroMasksAndCorrespondingImages Node Source Code Link
The FilterZeroMasksAndCorrespondingImages node is from the ComfyUI-KJNodes node package.
Comments
Sign in with GitHub to join the discussion.