π Gemini Mask Crop
Cut every mask region out of an image in one pass
- image
- masks
- cropped_images
- cropped_alphas
- bbox_info
- images_list
- alphas_list
Gemini Mask Crop is the local, no-API utility that sits right in the middle of the detect β crop β refine β stitch loop: give it an image and a batch of masks, and it cuts the image into one crop per mask. Each crop is the image content inside that mask's tight bounding box, with optional padding for context. This is the node that turns "Gemini gave me a segmentation mask" into "here's a clean tile I can refine."
It's pure local - no Google key, no network, runs in a few tens of milliseconds. Like every utility in this pack it lives under the AI/Image Analysis/Google menu, which reads odd for a node that never touches Google, but that's just where the author parked it.
How it works
Feed in image (the full-resolution original; a single image) and masks (a MASK batch, one per segment you want cropped - wire straight from Gemini Segmentation's comfy_masks or Gemini Object Detection's masks). The node computes each mask's tight bounding box, crops the image at that box, and pads all the crops with black to a common max size so the result is a valid ComfyUI IMAGE batch. Per-crop silhouette alphas and bbox metadata come out alongside, so downstream nodes can put everything back exactly where it came from.
Two knobs matter. bbox_padding adds pixels of context around each mask's tight box - almost always worth setting to a small value like 16β32, because refinement models like to see surrounding fabric rather than an exact silhouette. apply_mask (default off) zeros everything outside the silhouette inside each crop; leave it off, because "most refinement models want surrounding context" is the author's own advice and it's right.
Outputs - read the list one
The five outputs are where this node earns its keep:
- cropped_images - the crops as one padded batch, for nodes that want a batch.
- cropped_alphas - per-crop alpha masks.
- bbox_info - JSON with the crop rectangles, if you need the numbers.
- images_list - the same crops as a native-size list, no padding, each crop at its own exact dimensions.
- alphas_list - the matching list of alphas.
The two list outputs are the important ones. ComfyUI auto-iterates downstream nodes over a list, and Gemini Batch Refine is explicitly built to consume images_list (its images input tooltip says so) - each entry gets refined separately against your reference shots. Then Gemini Mask Stitch takes the refined results and the alphas and composites them back onto the original.
The list-versus-batch thing
This is a ComfyUI engine fact, not a node bug: an IMAGE batch is one tensor, so every slice must share HΓW. That's why there are two flavors of output here - a padded batch for nodes that demand a batch, and a list for nodes that iterate. If your downstream node errors with a shape mismatch, you grabbed the wrong one. Use images_list/alphas_list for the refinement loop; use cropped_images when something needs a single tensor.
Install
Same pack as everything here: ComfyUI Manager search "ComfyUI_Gemini", or git clone https://github.com/aarnoatchi/ComfyUI_Gemini into custom_nodes and pip install -r requirements.txt. This node itself needs nothing exotic - no scipy requirement, no API key - though the pack's shared install pulls google-genai and python-dotenv along anyway. Restart ComfyUI after installing and you're done. If crops come back with zero-width or the node throws on a weird mask shape, check that your masks match the image's dimensions - the node resizes masks to the image internally, but a mask batch with a zero area will produce an empty crop, so filter tiny masks upstream (Gemini Separate Mask Components' min_area is the natural tool for that).
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | Original full-resolution image. Single-batch (1, H, W, 3); batch[0] is used. | |
| masks | MASK | Batched masks (N, H, W). One image segment is cropped per mask. | |
| bbox_paddingopt | INT | 00β512 | Pixels of context to include around each mask's tight bbox before cropping. |
| apply_maskopt | BOOLEAN | false | If true, zero pixels outside the silhouette within each crop. Default False keeps the bbox tile intact β most refinement models want surrounding context. |
Outputs (5)
| Name | Type | Description |
|---|---|---|
| cropped_images | IMAGE | β |
| cropped_alphas | MASK | β |
| bbox_info | STRING | β |
| images_list | IMAGE | β |
| alphas_list | MASK | β |