π Gemini Segmentation
Pixel masks from Gemini β but only if you pick the right model
- image
- visualization
- raw_masks
- comfy_masks
- union_mask
- segments_json
- summary
Gemini Segmentation gives you proper per-object pixel masks from a natural-language description, which sounds like a superpower until you read the fine print: the model dropdown decides whether you get masks at all. That's the single most important thing about this node, and it's exactly where people get burned.
The model trap
Read the tooltip on model - it's the author being honest with you. Gemini 2.5 Pro and 2.5 Flash return native pixel masks (2.5 Pro is the default and the recommended pick). Gemini Robotics-ER 1.6 is Google's specialized spatial model and also does strong mask fidelity. But Gemini 3.x does not return pixel masks - boxes only. Pick 3.5 Flash or any of the 3.x names and your mask outputs come back empty. The 3.x models are in the list anyway, presumably as a convenience or a mistake, but for segmentation you want gemini-2.5-pro and you want it set to fixed in control-after-generate so nothing silently bumps it.
How it works
Send an image and a segmentation_prompt ("Segment all people and vehicles") to the API, get masks back, and the node binarizes them into ComfyUI MASK tensors using mask_confidence_threshold (default 127, the midpoint of 0β255 - raise it if masks come out noisy, lower it if they come out anemic). Then it draws the visualization image for you, with real choices: overlay, masks_only, side_by_side, or all. The overlay is tinted per segment with a color_mode (random, class_based, or single_color), and you can toggle draw_boxes and draw_labels on the visualization independently of the masks themselves.
The seed behaves like the rest of this pack's API nodes: image bytes + seed + params are hashed, so identical input means a cache hit and no API call. Free reruns while you fiddle with the visualization settings - a genuinely nice touch.
Outputs and what to wire them into
- visualization - the colored annotated image, for previewing or saving.
- raw_masks - the per-segment masks laid out as an IMAGE, if you want to inspect them.
- comfy_masks - the actual MASK batch, one mask per segment. This is the workhorse output.
- union_mask - everything unioned into one mask, handy for background removal.
- segments_json and summary - structured labels + a text summary.
Wire comfy_masks into Gemini Mask Crop and you're running the automated detailing loop from the KB - crop each segment, refine it, stitch it back. That loop is usually driven by local YOLO/SAM detectors; this is the cloud version that needs no weights and understands arbitrary classes.
Install and the bill
ComfyUI Manager (search "ComfyUI_Gemini") or git clone into custom_nodes, then pip install -r requirements.txt. Dependencies: google-genai - not google-generativeai, the classic wrong-package trap - plus python-dotenv and scipy. The pack auto-fixes a wrong google-generativeai install at startup. API key goes in the pack's .env (GOOGLE_API_KEY) or an environment variable; leave the node field empty so workflows stay shareable.
Costs are real: every unique image is a paid API call, and segmentation at 2.5 Pro is one of the pricier Gemini jobs. This is a small single-author pack (barely any community footprint by name), so treat the detailed console logs as your primary support channel. And remember the model rule: 2.5 for masks, 3.x for boxes-only.
Inputs (13)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | Input image for segmentation | |
| model | COMBO | gemini-2.5-pro | Pick 2.5 Pro for best masks (default). Robotics-ER 1.6 = Google's specialized spatial model. Gemini 3.x does NOT return pixel masks β boxes only. |
| segmentation_prompt | STRING | Give the segmentation masks for all objects. | Describe what to segment (e.g., 'Segment all people and vehicles') |
| visualization_mode | COMBO | overlay | How to visualize the segmentation results |
| seed | INT | 00β2147483647 | Same seed + same image + same params β cached (no API call). Set 'control after generate' to 'fixed' to keep the result; 'increment'/'randomize' to re-run on each queue. |
| use_descriptive_labelsopt | BOOLEAN | true | Use descriptive labels |
| mask_confidence_thresholdopt | INT | 1270β255 | Binarization threshold for masks (127 = midpoint) |
| overlay_alphaopt | FLOAT | 0.500β1 | Transparency of mask overlay (0 = transparent, 1 = opaque) |
| color_modeopt | COMBO | random | How to color different segments |
| single_coloropt | STRING | #00FF00 | Color for single_color mode (hex) |
| draw_boxesopt | BOOLEAN | true | Draw bounding boxes around segments |
| draw_labelsopt | BOOLEAN | true | Draw text labels on segments |
| temperatureopt | FLOAT | 0.20β2 | Model temperature |
Outputs (6)
| Name | Type | Description |
|---|---|---|
| visualization | IMAGE | β |
| raw_masks | IMAGE | β |
| comfy_masks | MASK | β |
| union_mask | MASK | β |
| segments_json | STRING | β |
| summary | STRING | β |