Save 4 hours! We auto-setup your workflow! Free!

Drop your workflow.json — we handle every dependency, custom node, and model. Just open the link and run.

Auto-Setup Workflow Json (Free) Now!
ComfyUI > Nodes > ComfyUI-lhyNodes > Mask to Coordinates V2 (SAM2)

ComfyUI Node: Mask to Coordinates V2 (SAM2)

Class Name

MaskToSAMCoordsV2

Category
lhyNodes/Mask
Author
lihaoyun6 (Account age: 3821days)
Extension
ComfyUI-lhyNodes
Latest Updated
2026-05-31
Github Stars
0.02K

How to Install ComfyUI-lhyNodes

Install this extension via the ComfyUI Manager by searching for ComfyUI-lhyNodes
  • 1. Click the Manager button in the main menu
  • 2. Select Custom Nodes Manager button
  • 3. Enter ComfyUI-lhyNodes 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 to Coordinates V2 (SAM2) Description

Converts masks to SAM coordinates for object detection and segmentation tasks, refining and extracting meaningful regions efficiently.

Mask to Coordinates V2 (SAM2):

MaskToSAMCoordsV2 is a specialized node designed to convert a given mask into coordinates suitable for use with the Segment Anything Model (SAM). This node is particularly useful for refining and extracting meaningful regions from a mask by identifying contours and generating coordinates within these regions. The primary goal of this node is to facilitate the transformation of a binary mask into a set of coordinates that can be used for further processing or analysis, such as object detection or segmentation tasks. By leveraging contour detection and random point sampling within detected regions, MaskToSAMCoordsV2 ensures that the output coordinates are representative of the most significant areas within the mask. This node is essential for AI artists and developers who need to bridge the gap between raw mask data and coordinate-based models like SAM, providing a streamlined and efficient method for mask-to-coordinate conversion.

Mask to Coordinates V2 (SAM2) Input Parameters:

mask

The mask parameter is a tensor representing the binary mask that you wish to convert into coordinates. This mask is typically a two-dimensional array where each element indicates whether a particular pixel is part of the object of interest. The mask is processed to identify contours and regions that exceed a specified threshold, which are then used to generate coordinates. The quality and detail of the mask directly impact the accuracy and relevance of the resulting coordinates.

threshold

The threshold parameter is a numerical value used to determine which parts of the mask are considered significant. Pixels with values above this threshold are treated as part of the object, while those below are ignored. This parameter is crucial for filtering out noise and ensuring that only the most relevant regions are converted into coordinates. The threshold value should be chosen based on the characteristics of the mask and the desired level of detail.

max_regions

The max_regions parameter specifies the maximum number of distinct regions to extract from the mask. This parameter helps control the complexity of the output by limiting the number of regions that are converted into coordinates. It is particularly useful when dealing with masks that contain multiple objects or areas of interest, allowing you to focus on the most significant regions.

points_per_region

The points_per_region parameter determines the number of random points to sample within each detected region. These points are used to generate the final set of coordinates, providing a representative sample of the region's shape and size. Increasing this parameter results in more detailed coordinate sets, while decreasing it simplifies the output.

Mask to Coordinates V2 (SAM2) Output Parameters:

coordinates

The coordinates output is a JSON-formatted string containing a list of coordinate objects, each with x and y properties. These coordinates represent points within the detected regions of the mask and are suitable for use with models like SAM. The output provides a concise and structured representation of the mask's most significant areas, facilitating further analysis or processing.

Mask to Coordinates V2 (SAM2) Usage Tips:

  • Ensure that the input mask is well-defined and accurately represents the regions of interest to achieve the best results.
  • Adjust the threshold parameter based on the mask's characteristics to filter out noise and focus on significant regions.
  • Use the max_regions parameter to control the complexity of the output, especially when dealing with masks containing multiple objects.
  • Experiment with the points_per_region parameter to balance between detail and simplicity in the output coordinates.

Mask to Coordinates V2 (SAM2) Common Errors and Solutions:

Warning: MaskToSAMCoords received a solid color mask. Returning default coordinate (0,0).

  • Explanation: This warning occurs when the input mask does not contain any variation, meaning all pixels have the same value. As a result, no meaningful regions can be extracted.
  • Solution: Verify that the input mask is correctly generated and contains the necessary variations to represent the regions of interest. Adjust the mask generation process if needed.

Warning: MaskToSAMCoords did not find any regions above the threshold. Returning default coordinate (0,0).

  • Explanation: This warning indicates that no regions in the mask exceeded the specified threshold, resulting in no coordinates being generated.
  • Solution: Review the threshold parameter and adjust it to ensure that significant regions are detected. Consider lowering the threshold if the mask contains subtle variations.

Mask to Coordinates V2 (SAM2) Related Nodes

Go back to the extension to check out more related nodes.
ComfyUI-lhyNodes
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 Models, enabling artists to harness the latest AI tools to create incredible art.

Mask to Coordinates V2 (SAM2)