← See All Custom Node Packs

ComfyUI-segment-anything-2

1206

Run ComfyUI Easily with InstaSD

Skip the complex setup and run ComfyUI online. InstaSD helps creative professionals build workflows and deploy them to the world:

  • One-click deployment
  • Any model, any node
  • Powerful GPUs for rapid iteration
Get Started

Sam2Segmentation

Sam2Segmentation Node Documentation

Overview

The Sam2Segmentation node is part of the ComfyUI toolkit for segmenting images using the SAM2 model. This node leverages a pre-trained segmentation model to generate masks from given images. It provides a flexible interface for image segmentation tasks, allowing users to specify positive and negative points for segmentation, handle bounding boxes, and determine individual objects in the image for more precise segmentation.

Functionality

What This Node Does

The Sam2Segmentation node processes input images and generates masks based on specified parameters. It allows users to segment images by selecting specific regions of interest. The node supports various modes of operation, depending on the type of input and the desired output. It is particularly useful for applications that require precise object identification and extraction from images.

Inputs

The node accepts the following inputs:

  1. SAM2 Model (sam2_model): The pre-loaded segmentation model, which contains the model details necessary for performing segmentation.

  2. Image (image): The image to be segmented. This is the primary data input for the node.

  3. Keep Model Loaded (keep_model_loaded): A boolean input that determines whether to keep the model loaded in memory after segmentation, allowing for faster processing of subsequent images.

Optional Inputs

  • Coordinates Positive (coordinates_positive): A string representation of coordinates marking regions of interest to be positively included in the segmentation.

  • Coordinates Negative (coordinates_negative): A string representation of coordinates marking regions to be excluded from the segmentation.

  • Bounding Boxes (bboxes): Optional bounding box data for the image, influencing the segmentation process by pre-defining regions of interest.

  • Individual Objects (individual_objects): A boolean input indicating whether segmentation should treat each object individually.

  • Mask (mask): An optional mask input that can be used to refine the segmentation.

Outputs

The node produces the following output:

  • Mask (mask): The resulting mask from the segmentation process, which highlights the segmented areas in the input image. The mask is useful for identifying and processing specific regions within an image.

Usage in ComfyUI Workflows

The Sam2Segmentation node is typically used in workflows that require image segmentation and object detection. Users can:

  • Load an image and a pre-trained SAM2 model using associated nodes in ComfyUI.
  • Define areas of interest using positive and negative coordinates, or by specifying bounding boxes.
  • Run the segmentation process to generate masks, which can then be used for further image processing tasks such as object recognition, background removal, or image analysis.

This node can be integrated into larger image processing or computer vision pipelines within ComfyUI, facilitating complex workflows where segmentation is a prerequisite step for additional processing.

Special Features and Considerations

  • Model Variants: The node supports different model variants, enabling flexibility in segmentation depending on the complexity and size of the input images.

  • Compatibility: The node is compatible with multiple computing devices, including CPU, CUDA-enabled GPUs, and Apple's Metal Performance Shaders (MPS).

  • Resource Management: Users should be mindful of resource constraints, as processing large images or using complex models may require significant computational resources.

  • Error Handling: The node includes built-in error handling for common issues such as incompatible precision settings or unsupported segmentor types.

For more information and to access the latest updates, visit the ComfyUI Segment Anything 2 repository.

Want to try ComfyUI-segment-anything-2 without installing anything? Run ComfyUI online on InstaSD's cloud GPUs — no setup required.