NB2 Smart Region
NB2 Smart Region — turn any semantic mask into a Nano Banana-ready rectangle
- image
- region_mask
- mask
- nb2_width
- nb2_height
- preview_image
- center_x
- center_y
- crop_width
- crop_height
- info
NB2 Crop wants a rectangle. Florence-2 and SAM give you an organic blob. NB2 Smart Region is the adapter: it takes a semantic mask - from NB2Florence2RegionSelector, NB2SAM3ImageSegmenter, kijai's Florence2Run, or any segmentation node - and fits the tightest Nano Banana-sized rectangle around it, expanding, padding, and aspect-correcting so the downstream crop and stitch stay in lockstep.
It's the node you reach for when you want the convenience of "click a semantic region, let the model find it" but still want to run the manual NB2 crop/stitch path. The README's recommended flow puts it right in the middle:
NB2Florence2RegionSelector or Florence2Run (kijai) -> mask
-> NB2 Smart Region -> NB2 Crop -> Nano Banana 2 Edit -> NB2 Stitch
Inputs
Required: image, region_mask (the semantic mask), and the shape controls:
aspect_ratio- defaults toauto, which is the interesting one. Inautomode the node first checks the Florence region metadata (viaregion_info) for a shape hint - face → 1:1, glasses → 16:9, full body → 9:16 - and falls back to the mask's bounding box if there's no hint. Otherwise you can force16:9/9:16/1:1.resolution(1K,2K,4K) - generation budget, and it needs to match what you set onNB2 Crop.padding_percent(default 8) - expands the detected region before rectangle fitting, so the model gets breathing room around the object. Faces want more (10–18 per the README), small objects less (5–12).crop_scale(1.0–4.0) - an extra scale multiplier applied after the aspect fit. Handy when you want to zoom the crop out further than padding alone.depad_florence(default True) - here's a real trap worth understanding. Florence-2 letterboxes images to a square internally before processing, which shifts the detected bbox on non-square images. Keep this True when the mask came from Florence (Florence2Run/ this pack's selector) to correct for that. Set it False only when your mask is already at exact source resolution - a hand-drawn mask or a SAM output, for example.region_info- optional, theinfostring from the selector. Feed it in andaspect_ratio = autocan use the region's shape hint.
Outputs: mask (the fitted rectangle, into NB2 Crop), nb2_width/nb2_height, preview_image (source with the rectangle drawn on - wire it to a Preview node, it's your sanity check), plus center_x/center_y/crop_width/crop_height and info for scripting.
The depad trap in practice
Most "why is my crop off to one side?" reports in this pack trace back to depad_florence. If you run Florence-2 locally via kijai's pack, the mask arrives with the internal square padding baked in, and without depadding the rectangle lands shifted - the README explicitly calls this out. Keep the default True for Florence masks, flip to False for SAM or hand-drawn ones, and the rectangle lands where the region actually is.
Install
One pack, all nodes:
cd ComfyUI/custom_nodes
git clone https://github.com/amortegui84/comfyui-inpaint-cropstitch-nb2
or search comfyui-inpaint-cropstitch-nb2 in ComfyUI Manager, restart. This node itself is local and keyless - the selector upstream (if you use this pack's FAL one) and the edit node downstream are the parts that need FAL_KEY.
Inputs (8)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | — | |
| region_mask | MASK | — | |
| aspect_ratio | COMBO | auto | 4 options: auto, 16:9, 9:16, 1:1 |
| resolution | COMBO | 2K | 3 options: 1K, 2K, 4K |
| padding_percent | FLOAT | 8.00–100 | Expands the detected region before rectangle fitting. |
| crop_scale | FLOAT | 1.001–4 | Additional scale multiplier applied after aspect-ratio fitting. |
| depad_florence | BOOLEAN | true | Remove Florence2's internal square letterbox padding before resizing the mask. Keep True when the mask comes from Florence2Run (kijai). Disable only if your mask is already at the exact source image resolution. |
| region_infoopt | STRING | — |
Outputs (9)
| Name | Type | Description |
|---|---|---|
| mask | MASK | — |
| nb2_width | INT | — |
| nb2_height | INT | — |
| preview_image | IMAGE | — |
| center_x | INT | — |
| center_y | INT | — |
| crop_width | INT | — |
| crop_height | INT | — |
| info | STRING | — |