心宝❤局部裁切预处理
The crop half of 'fix one region, keep the rest identical'
- image
- mask
- ref_image
- image_1
- image_2
- region_data
This is the node that cuts a masked region out of an image, preps it so Gemini can regenerate it in its own pass, and hands the geometry forward so the result can be pasted back later. It's the "zoom in on the mask" step of the local-edit chain - the same idea the KB's detection-and-detailing doc describes, but pointed at a cloud image model instead of a local sampler.
It takes two things you almost certainly already have: an image and a mask (any mask you can produce - a hand-painted one, or one from the pack's SAM node). Then it turns that masked region into a crop sized and padded for a clean second generation, and emits the region_data that the paste node needs to put the result back.
The inputs that matter
Most of the controls are geometry, and they read like a crop-and-pad utility:
padding_slider(0–10, default 3) - padding around the masked region, as a fraction. Give the model a little context outside the mask; that's what keeps the regenerated region blending with its surroundings.expand_slider(-1 to 1, default 0.3) - expands (positive) or shrinks (negative) the crop region beyond the raw mask bounds.blend_slider(0–1, default 0.5) - how much the edges of the crop blend, which controls seam softness when you paste back.scale_to_length(64–8192, default 2048) - the long edge the crop gets scaled to. This is your detail budget: Gemini resolves more detail at a bigger crop, at the cost of a slower, pricier call.target_size(64–8192, default 1536) - the size the final prepped crop is set to for the generation pass.round_to_multiple(default 8) - snaps the crop dimensions to a multiple of N, so the region stays model-friendly (the API and image codecs both like aligned dimensions).overlay_color(default#7f7f7f) - the color used to fill the masked area in one of the outputs, so you can see what's being treated as "region to regenerate."
There's one optional ref_image input - feed it a reference and the preprocess includes it in the crop prep, which is useful when you want the regenerated region to match a style or content reference.
The three outputs
image_1andimage_2- two prepared crops. One is typically the padded crop with the region masked for regeneration; the other the crop with the region area filled, ready to be the model's canvas. You wire one of these into the Banana node'simage_1reference input.region_data(BANANA_REGION_DATA) - the geometry: where the crop came from, what scale it's at, and the offset. This is the message-in-a-bottle that letsBananaLocalCropPasteput the regenerated crop back at the exact same spot.
How it fits the workflow
The full local-edit chain is:
load image → mask (SAM or hand-painted) → BananaLocalCropPreprocess
→ 心宝❤Banana (with binding_context, crop as reference) → BananaLocalCropPaste → output
BananaBindingGenerate supplies the binding_context that keeps the model anchored to the original image, the Banana node regenerates the region, and BananaLocalCropPaste composites. This node is the geometry bookkeeper in the middle - get the padding and scale right and the paste is seamless; get them wrong and you'll see the seam, or the model will hallucinate content in the padding area.
Installing
Part of the comfyui-banana-li-linux pack:
cd ComfyUI/custom_nodes
git clone https://github.com/98624017/comfyui-banana-li-linux
Restart ComfyUI. The pack's opencv-contrib-python and Pillow dependencies cover the actual crop math. No model downloads - the only models involved are the ones you already use to produce the mask and the Gemini API that regenerates the region.
A practical tip: watch the preview (image_1) before running the full chain. If the crop is clipping your subject or the padding is swallowing it, adjust expand_slider and padding_slider before spending API credits on a generation pass you'll throw away.
Inputs (10)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| mask | MASK | — | |
| padding_slider | FLOAT | 3.000–10 | — |
| blend_slider | FLOAT | 0.500–1 | — |
| expand_slider | FLOAT | 0.30-1–1 | — |
| scale_to_length | INT | 204864–8192 | — |
| target_size | INT | 153664–8192 | — |
| round_to_multiple | INT | 81–64 | — |
| overlay_color | STRING | #7f7f7f | — |
| ref_imageopt | IMAGE | — |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| image_1 | IMAGE | — |
| image_2 | IMAGE | — |
| region_data | BANANA_REGION_DATA | — |