ComfyUI > Nodes > ComfyUI-Grounding > Sam2 Segment

ComfyUI Node: Sam2 Segment

Class Name

Sam2Segment

Category
SAM2
Author
PozzettiAndrea (Account age: 2240days)
Extension
ComfyUI-Grounding
Latest Updated
2025-12-22
Github Stars
0.03K

How to Install ComfyUI-Grounding

Install this extension via the ComfyUI Manager by searching for ComfyUI-Grounding
  • 1. Click the Manager button in the main menu
  • 2. Select Custom Nodes Manager button
  • 3. Enter ComfyUI-Grounding 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

Sam2 Segment Description

Sam2Segment node enables precise image segmentation using SAM2 for detailed digital art tasks.

Sam2 Segment:

The Sam2Segment node is designed to perform advanced image segmentation using the SAM2 segmentation method. This node is particularly beneficial for AI artists and designers who need to isolate and manipulate specific parts of an image with precision. By leveraging the SAM2 model, it allows for the segmentation of images into distinct regions based on user-defined criteria, such as positive and negative coordinates, bounding boxes, and masks. This capability is essential for tasks that require detailed image analysis and manipulation, such as creating complex compositions or enhancing specific image features. The node's ability to handle individual objects and refine masks ensures that users can achieve high-quality segmentation results, making it a valuable tool in the digital art and design workflow.

Sam2 Segment Input Parameters:

image

The image parameter is a tensor representing the image to be segmented. It is crucial as it serves as the input data on which the segmentation will be performed. The image should be in the format of a ComfyUI IMAGE tensor with dimensions (B, H, W, C), where B is the batch size, H is the height, W is the width, and C is the number of color channels.

sam2_model

The sam2_model parameter is a dictionary containing the model configuration, including the model itself, data type, device, segmentor type, and version. This parameter is essential as it defines the specific SAM2 model to be used for segmentation, impacting the accuracy and efficiency of the process.

keep_model_loaded

The keep_model_loaded parameter is a boolean that determines whether the SAM2 model should remain in memory after the segmentation process. Keeping the model loaded can improve performance for consecutive segmentation tasks by reducing loading times.

coordinates_positive

The coordinates_positive parameter is a JSON string that specifies the positive point coordinates for segmentation. These coordinates guide the model to focus on specific areas of the image that should be included in the segmented output.

coordinates_negative

The coordinates_negative parameter is a JSON string that specifies the negative point coordinates for segmentation. These coordinates help the model identify areas of the image that should be excluded from the segmented output.

individual_objects

The individual_objects parameter is a boolean that indicates whether each object in the image should be segmented individually. This option is useful for isolating distinct objects within a scene, allowing for more detailed manipulation.

bboxes

The bboxes parameter provides bounding boxes as input, which can be used to define specific regions of interest within the image. This helps in focusing the segmentation process on particular areas, enhancing precision.

mask

The mask parameter is an optional input mask that can be used to refine the segmentation process. It allows for the incorporation of pre-existing segmentation data to improve the accuracy of the final output.

mask_threshold

The mask_threshold parameter is a float that sets the threshold for mask binarization. It determines the sensitivity of the mask, affecting which areas are considered part of the segmented region. The default value is 0.0.

max_hole_area

The max_hole_area parameter is a float that specifies the maximum area of holes to be filled within the segmented regions. This helps in creating smoother and more contiguous segments by eliminating small gaps.

max_sprinkle_area

The max_sprinkle_area parameter is a float that defines the maximum area of isolated regions to be removed from the segmented output. This ensures that small, irrelevant segments are not included in the final result.

Sam2 Segment Output Parameters:

mask_tensor

The mask_tensor is the primary output of the Sam2Segment node. It is a tensor that represents the segmented regions of the input image. This output is crucial for further image processing tasks, as it provides a clear delineation of the areas of interest, allowing for targeted manipulation and enhancement.

Sam2 Segment Usage Tips:

  • To achieve optimal segmentation results, carefully define the coordinates_positive and coordinates_negative parameters to guide the model accurately.
  • Utilize the individual_objects parameter when working with images containing multiple distinct objects to ensure each object is segmented separately for more precise control.

Sam2 Segment Common Errors and Solutions:

Cannot perform SAM2 segmentation: sam2 module failed to import. Check console for import errors.

  • Explanation: This error occurs when the SAM2 module is not properly imported, possibly due to missing dependencies or incorrect installation.
  • Solution: Verify that all necessary dependencies for the SAM2 module are installed and correctly configured. Check the console for specific import error messages and resolve any issues related to missing packages or incorrect paths.

Sam2 Segment Related Nodes

Go back to the extension to check out more related nodes.
ComfyUI-Grounding
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.