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 (SAM2)

ComfyUI Node: Mask to Coordinates (SAM2)

Class Name

MaskToSAMCoords

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 (SAM2) Description

Converts masks to coordinates for image analysis, object detection, and segmentation.

Mask to Coordinates (SAM2):

The MaskToSAMCoords node is designed to convert a given mask into a set of coordinates that can be used for further processing or analysis. This node is particularly useful in scenarios where you need to extract specific regions of interest from an image based on a mask. By analyzing the mask, it identifies contours and generates coordinates within these regions, which can then be used for tasks such as object detection or segmentation. The node is capable of handling masks with varying levels of detail and can adapt to different thresholds and region specifications, making it a versatile tool for AI artists looking to refine their image processing workflows.

Mask to Coordinates (SAM2) Input Parameters:

mask

The mask parameter is a tensor that represents the input mask from which coordinates will be extracted. This mask is typically a binary or grayscale image where different pixel values indicate different regions of interest. The quality and detail of the mask directly impact the accuracy and precision of the coordinates generated by the node.

threshold

The threshold parameter determines the cutoff value for distinguishing between foreground and background in the mask. Pixels with values above this threshold are considered part of the region of interest. Adjusting this value can help refine the regions detected, especially in masks with varying intensity levels. The threshold should be set based on the specific characteristics of the mask being used.

max_regions

The max_regions parameter specifies the maximum number of distinct regions to extract from the mask. This is useful for controlling the complexity of the output, especially in masks with numerous small regions. By limiting the number of regions, you can focus on the most significant areas of interest.

points_per_region

The points_per_region parameter defines how many coordinate points should be generated for each detected region. This allows for a more detailed representation of each region, which can be beneficial for tasks requiring precise localization. The number of points should be chosen based on the level of detail needed for subsequent processing.

Mask to Coordinates (SAM2) Output Parameters:

coords_str

The coords_str output is a JSON-formatted string containing the coordinates extracted from the mask. Each coordinate is represented as an object with x and y properties, indicating its position within the image. This output provides a structured and easily interpretable format for further use in image processing or analysis tasks.

Mask to Coordinates (SAM2) Usage Tips:

  • Adjust the threshold parameter to fine-tune the regions of interest, especially if the mask has varying intensity levels.
  • Use the max_regions parameter to limit the number of regions processed, which can help focus on the most relevant areas and reduce computational load.
  • Increase the points_per_region parameter for tasks that require high precision in region localization, such as detailed object tracking.

Mask to Coordinates (SAM2) Common Errors and Solutions:

Warning: Mask to Coordinates (SAM2) received a solid color mask. Returning default coordinate (0,0).

  • Explanation: This warning occurs when the input mask does not have any variation in pixel values, making it impossible to distinguish regions of interest.
  • Solution: Ensure that the input mask has distinct regions with varying pixel values. You may need to preprocess the mask to enhance contrast or apply a different threshold.

Warning: Mask to Coordinates (SAM2) did not find any regions above the threshold. Returning default coordinate (0,0).

  • Explanation: This warning indicates that no regions in the mask met the specified threshold criteria, resulting in no coordinates being generated.
  • Solution: Lower the threshold value to include more regions or verify that the mask is correctly aligned with the intended regions of interest.

Mask to Coordinates (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 (SAM2)