← 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

Sam2AutoSegmentation

Sam2AutoSegmentation Node Documentation

Overview

The Sam2AutoSegmentation node is a part of the ComfyUI framework's "SAM2" functionality. This node automatically segments an image into different regions based on specified parameters. It's designed to perform advanced image segmentation with a variety of adjustable options, allowing users to customize the segmentation process to suit specific needs. The node leverages the SAM2Automatic Mask Generator model to process images efficiently.

Functionality

The Sam2AutoSegmentation node takes an image as an input and segments it into various regions, returning masks, segmented images, and bounding boxes. The process is highly customizable with numerous parameters available to fine-tune the segmentation.

Inputs

The node requires a set of inputs, essential for its function:

  • sam2_model: The model to be used for segmentation, which must be an instance of SAM2AutomaticMaskGenerator.
  • image: The input image to be segmented.
  • points_per_side: Number of points per side for grid sampling.
  • points_per_batch: Number of points to process per batch.
  • pred_iou_thresh: IOU threshold for prediction filtering.
  • stability_score_thresh: Threshold for stability scoring.
  • stability_score_offset: Offset for stability scoring.
  • mask_threshold: Threshold to determine mask generation.
  • crop_n_layers: Number of layers for cropping.
  • box_nms_thresh: Non-max suppression threshold for bounding boxes.
  • crop_nms_thresh: Non-max suppression threshold for crops.
  • crop_overlap_ratio: Overlap ratio allowed in crops.
  • crop_n_points_downscale_factor: Downscale factor for points in cropping.
  • min_mask_region_area: Minimum mask region area.
  • use_m2m: Boolean option to use M2M.
  • keep_model_loaded: Boolean option to retain the model in memory post-execution.

Outputs

Upon execution, the node returns the following outputs:

  • mask: The combined mask of all segmented regions within the input image.
  • segmented_image: The input image with segmented regions overlayed in distinct colors for visualization.
  • bbox: A list of bounding boxes surrounding each segmented region.

Use in ComfyUI Workflows

The Sam2AutoSegmentation node can integrate into ComfyUI workflows where automated image segmentation is required. It can be used in various scenarios, like object detection, image preprocessing, and detailed analytics within visual content. The node's adjustable parameters allow users to control the granularity and accuracy of the segmentation, making it versatile for different applications such as scientific imaging, content moderation, and machine learning data preprocessing.

Special Features and Considerations

  • Model Specificity: This node requires the input image and model type to align. The model must be configured specifically for automatic mask generation.
  • Customizability: Users can customize segmentation outputs extensively through the available parameters, providing flexibility to cater to diverse project requirements.
  • Device Configuration: The node can manage resource allocation, including GPU device handling, to optimize performance during operation.
  • Visualization: Besides generating the masks, it offers an overlayed visual representation of segmented regions, which can be crucial for validating the segmentation results.
  • Performance: Performance can vary significantly based on the parameters set and image complexity; users should consider these factors to optimize execution speed and accuracy.

With its advanced segmentation capabilities and customization options, the Sam2AutoSegmentation node is a powerful tool within ComfyUI for automated image processing tasks.

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