π Gemini Mask Stitch
Put the refined patch back with no visible seam
- original_image
- refined_image
- mask
- composited
- top_layer
- bottom_layer
- alpha
Gemini Mask Stitch is the "paste back" half of the automated detailing loop - the counterpart to Gemini Mask Crop. Mask Crop cut a region out; this node takes the refined version of that region and composites it onto the original at exactly the right place, with a seam that's actually invisible. It's local, no API, no key, and it's where the quality of a whole refinement pipeline gets decided. A perfect inpaint that's pasted back with a hard edge reads as a bad edit; this node exists to stop that.
The KB's detailing loop is detect β crop β upscale β re-render β paste, and every one of those steps has a Gemini node in this pack except the paste - until now. Mask Stitch closes it.
How it works
Three inputs: original_image (the full-resolution base, which becomes the bottom layer), refined_image (your inpainted/edited region), and mask (where to place it - if you feed a batch of masks they collapse via amax into a single union alpha). The refined image is sized into the mask's bounding box according to fit_mode:
- cover (default) - preserve aspect, scale to fill the bbox, crop the overflow. Best for Nano Banana inpaint output, which tends to fill its frame.
- contain - preserve aspect, fit inside the bbox; gaps reveal the bottom layer underneath.
- stretch - fill the bbox exactly, distorting aspect. The legacy behavior; avoid unless you know the aspect already matches.
Then the seam work happens. pre_shrink_alpha (default 2) erodes the alpha by a couple of pixels before anything else, which kills the classic 1-pixel halo of original color that bleeds at the boundary - the author's description is "kills the 1-px halo," and it does. feather_pixels (default 8) then softens the alpha edge so the transition is gradual. And match_color runs a Reinhard mean/std color transfer from the underlying original region onto the refined patch, which fixes the "this patch looks brighter" tell that plagues cloud-refined regions with slightly different white balance.
Outputs
- composited - the finished merge.
- top_layer and bottom_layer - the two layers separately, so you can re-blend or debug non-destructively.
- alpha - the actual alpha used, so you can inspect exactly where the blend happened.
Having the layers and alpha out is the genuinely nice part: if the seam still shows, you don't have to rerun the pipeline - grab the alpha, shrink it with Gemini Mask Resize, and recombine.
Wiring it up
The intended chain is right in the node names: Gemini Segmentation or Object Detection β Gemini Mask Crop (images_list/alphas_list) β Gemini Batch Refine β Gemini Mask Stitch. Wire Mask Crop's alphas_list into the mask input, Batch Refine's refined_images into refined_image, the original into original_image, and the loop closes.
Install
Standard for the pack: ComfyUI Manager search "ComfyUI_Gemini", or git clone https://github.com/aarnoatchi/ComfyUI_Gemini into custom_nodes and pip install -r requirements.txt. No scipy, no API key - pure torch on the input device. If your seam shows a colored edge, that's pre_shrink_alpha too low; if it looks like a soft smear, feather_pixels too high. And if the patch is squashed, your refined_image came from a stretch-oriented crop path - switch fit_mode to cover and it'll stop distorting.
Inputs (7)
| Name | Type | Default | Description |
|---|---|---|---|
| original_image | IMAGE | Full-resolution base image β becomes the bottom layer. | |
| refined_image | IMAGE | Inpainted / upscaled / edited region. Sized to the mask bbox according to fit_mode. | |
| mask | MASK | Where to place the refined image. Batched masks collapse via amax to a single union alpha. | |
| fit_modeopt | COMBO | cover | How to fit refined into the mask bbox when aspect ratios differ: cover β preserve aspect, scale to fill bbox, crop overflow (best for Nano Banana inpaint) contain β preserve aspect, scale to fit inside bbox, gaps reveal the bottom layer stretch β fill bbox exactly, distorts aspect (legacy behaviour) |
| feather_pixelsopt | INT | 80β256 | Soft alpha edge in pixels. Higher = smoother seam. |
| pre_shrink_alphaopt | INT | 20β32 | Erode alpha by N px before feathering β kills the 1-px halo of original colour that bleeds at the boundary. |
| match_coloropt | BOOLEAN | false | Reinhard mean/std transfer from the underlying original region to the refined image. Reduces 'this patch looks brighter' seams. |
Outputs (4)
| Name | Type | Description |
|---|---|---|
| composited | IMAGE | β |
| top_layer | IMAGE | β |
| bottom_layer | IMAGE | β |
| alpha | MASK | β |