AutomaticMask(segment anything)
Let SAM segment the whole image, then just pick what you wanted
- sam_model
- image
- mask
- Image
- Mask
- Segment Image
There's a small thread on r/comfyui where someone asks how to replicate the A1111 "segment anything" extension in ComfyUI: let SAM slice the whole image into segments, then black out the parts you actually want. They answer their own post in a follow-up comment, linking this exact repo. That's the whole story of ComfyUI_Segment_Mask. It's one node, from April 2024, unmaintained since, and it does exactly that one job.
AutomaticMask(segment anything) is a direct port of Meta's SamAutomaticMaskGenerator from the original segment-anything package - not SAM 2, not FastSAM, the original ViT model. Instead of you clicking a point or drawing a box, the node generates a whole grid of prompts and asks SAM to find every plausible object in the frame. Then it throws away all but the pieces you care about. "Automatic" is doing a lot of work in that name.
The trick nobody explains: the mask input is your selector
Automatic segmentation is usually useless on its own - it returns forty overlapping regions and you didn't ask for any of them. This node solves that with its mask input: it keeps only the detected segments that overlap your mask, unions them, and discards the rest. So you draw a rough blob over the thing you want (or threshold anything), and SAM snaps it to clean, object-level edges. It's the "black dot to select" workflow from A1111, minus the clicks. This is the reason the node exists, and it's also the trap: the shipped example workflow in the repo never connects the mask, and the node won't run without it. Wire in the MASK output of your LoadImage, or draw one.
The inputs that actually matter
sam_model- aSAM_MODELfrom Impact Pack's SAMLoader (see install below). This is where your weights come from.mask- your rough selection. Only segments overlapping it survive.points_per_side(default 32) - grid density. 32 per side means 1,024 point prompts; more points, slower run. For coarse subjects 8–16 is plenty.pred_iou_thresh(0.86) andstability_score_thresh(0.92) - quality filters. Higher = fewer, more confident segments.min_mask_region_area(100) - drops tiny speckle regions. Its post-processing needs OpenCV, which isn't in the pack'srequirements.txt(it usually arrives transitively withsegment_anything); if it errors,pip install opencv-python.crop_n_layers(1) andcrop_n_points_downscale_factor(2) - SAM's multi-crop pass for finding small objects in big images.
Three outputs: Image, a color-coded annotation overlay (each segment a random translucent color, big ones under small ones); Mask, the union of the surviving segments - feed this straight into a Set Latent Noise Mask or a detailer; and Segment Image, the original pixels as an RGBA cutout with alpha set from the mask, ready for compositing. Heads up: the two image outputs are 4-channel, which some downstream nodes don't expect, and only image[0] / mask[0] are used, so batches and video are out.
Installing it
ComfyUI Manager → search "ComfyUI_Segment_Mask", or the manual route:
cd ComfyUI/custom_nodes
git clone https://github.com/MarkoCa1/ComfyUI_Segment_Mask
Restart ComfyUI; the install script pip-installs segment_anything, torch, numpy, pillow on first launch. The real prerequisite is ComfyUI-Impact-Pack (ltdrdata) - the SAM_MODEL type isn't defined here, it comes from Impact Pack's SAMLoader, which is exactly why the README's only link points there. Then drop a SAM checkpoint into ComfyUI/models/sams/ - the shipped workflow uses sam_vit_b_01ec64.pth (~375MB), the smallest of the three. The pack itself is fine; just don't expect it to track the upstream SAM line, which has moved on to SAM 2.
When to reach for something else
For clean background removal, don't - SAM's automatic mode is region selection, not matting, and a dedicated BiRefNet or Inspyrenet node will beat it on hair and transparency every time. But for "select this one object out of a busy image" with nothing but a blob, this is the rare node that does exactly what it claims, and it's still what people reach for.
Inputs (9)
| Name | Type | Default | Description |
|---|---|---|---|
| sam_model | SAM_MODEL | — | |
| image | IMAGE | — | |
| mask | MASK | — | |
| points_per_side | INT | 320–100 | — |
| pred_iou_thresh | FLOAT | 0.860–1 | — |
| stability_score_thresh | FLOAT | 0.920–1 | — |
| crop_n_layers | INT | 10–100 | — |
| crop_n_points_downscale_factor | INT | 20–100 | — |
| min_mask_region_area | INT | 1000–100 | — |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| Image | IMAGE | — |
| Mask | MASK | — |
| Segment Image | IMAGE | — |