ComfyUI > Nodes > ComfyUI-YCNodes > Mask Top-N Filter

ComfyUI Node: Mask Top-N Filter

Class Name

MaskTopNFilter

Category
YCNode/Mask
Author
yichengup (Account age: 473days)
Extension
ComfyUI-YCNodes
Latest Updated
2025-06-03
Github Stars
0.02K

How to Install ComfyUI-YCNodes

Install this extension via the ComfyUI Manager by searching for ComfyUI-YCNodes
  • 1. Click the Manager button in the main menu
  • 2. Select Custom Nodes Manager button
  • 3. Enter ComfyUI-YCNodes in the search bar
After installation, click the Restart button to restart ComfyUI. Then, manually refresh your browser to clear the cache and access the updated list of nodes.

Visit ComfyUI Online for ready-to-use ComfyUI environment

  • Free trial available
  • 16GB VRAM to 80GB VRAM GPU machines
  • 400+ preloaded models/nodes
  • Freedom to upload custom models/nodes
  • 200+ ready-to-run workflows
  • 100% private workspace with up to 200GB storage
  • Dedicated Support

Run ComfyUI Online

Mask Top-N Filter Description

Refines mask images by isolating top N largest connected components for focused output.

Mask Top-N Filter:

The MaskTopNFilter node is designed to refine and enhance mask images by isolating the most significant regions within the mask. Its primary function is to filter out less prominent areas, retaining only the top N largest connected components based on their size. This is particularly useful in scenarios where you want to focus on the most substantial features of a mask, such as in image segmentation tasks where only the most relevant parts of an image need to be highlighted or processed further. By converting the mask into a binary image and analyzing connected components, the node effectively reduces noise and irrelevant details, providing a cleaner and more focused mask output. This capability is essential for AI artists who need to streamline their workflow by concentrating on the most critical parts of an image, ensuring that subsequent processing steps are more efficient and effective.

Mask Top-N Filter Input Parameters:

mask

The mask parameter is the input mask image that you want to process. It is expected to be in a format that the node can interpret, typically a tensor representing the mask. This parameter is crucial as it serves as the base from which the node will identify and filter the top N regions. The mask should ideally highlight the areas of interest that you want to refine or focus on.

keep_top_n

The keep_top_n parameter determines the number of largest connected components to retain in the output mask. It is an integer value with a default of 2, a minimum of 1, and a maximum of 10. This parameter directly impacts the node's execution by specifying how many of the most significant regions should be preserved, allowing you to control the level of detail and focus in the resulting mask. Adjusting this value can help you tailor the output to your specific needs, whether you want to highlight only the most prominent features or include more details.

Mask Top-N Filter Output Parameters:

filtered_mask

The filtered_mask is the output of the node, representing the processed mask with only the top N largest connected components retained. This output is crucial as it provides a refined version of the input mask, focusing on the most significant areas and removing less relevant details. The filtered mask is typically used in further image processing tasks where a cleaner and more focused mask is beneficial.

Mask Top-N Filter Usage Tips:

  • To achieve the best results, ensure that the input mask is well-prepared and highlights the areas of interest clearly. This will help the node accurately identify and retain the most significant regions.
  • Experiment with the keep_top_n parameter to find the optimal number of regions to retain for your specific task. Start with the default value and adjust as needed to balance between detail and focus.

Mask Top-N Filter Common Errors and Solutions:

Error: "Input mask is not a valid tensor"

  • Explanation: This error occurs when the input mask is not in the expected tensor format, which the node requires for processing.
  • Solution: Ensure that the input mask is correctly formatted as a tensor. You may need to convert or preprocess your mask image to meet this requirement.

Error: "keep_top_n value is out of range"

  • Explanation: This error indicates that the keep_top_n parameter is set to a value outside the allowed range of 1 to 10.
  • Solution: Adjust the keep_top_n parameter to be within the valid range. Check the value you have set and ensure it is between 1 and 10.

Mask Top-N Filter Related Nodes

Go back to the extension to check out more related nodes.
ComfyUI-YCNodes
RunComfy
Copyright 2025 RunComfy. All Rights Reserved.

RunComfy is the premier ComfyUI platform, offering ComfyUI online environment and services, along with ComfyUI workflows featuring stunning visuals. RunComfy also provides AI Playground, enabling artists to harness the latest AI tools to create incredible art.