ComfyUI Node

NB2 Smart Region

NB2 Smart Region — turn any semantic mask into a Nano Banana-ready rectangle

By amortegui84·Created 5 months ago·Updated 3 months ago· 3
NB2 Smart Region
  • image
  • region_mask
  • mask
  • nb2_width
  • nb2_height
  • preview_image
  • center_x
  • center_y
  • crop_width
  • crop_height
  • info
aspect_ratioauto
resolution2K
padding_percent8.0
crop_scale1.00
depad_florencetrue
region_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 to auto, which is the interesting one. In auto mode the node first checks the Florence region metadata (via region_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 force 16:9 / 9:16 / 1:1.
  • resolution (1K, 2K, 4K) - generation budget, and it needs to match what you set on NB2 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, the info string from the selector. Feed it in and aspect_ratio = auto can 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.

Categoryinpaint/nb2

Inputs (8)

NameTypeDefaultDescription
imageIMAGE
region_maskMASK
aspect_ratioCOMBOauto4 options: auto, 16:9, 9:16, 1:1
resolutionCOMBO2K3 options: 1K, 2K, 4K
padding_percentFLOAT8.00–100Expands the detected region before rectangle fitting.
crop_scaleFLOAT1.001–4Additional scale multiplier applied after aspect-ratio fitting.
depad_florenceBOOLEANtrueRemove 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_infooptSTRING

Outputs (9)

NameTypeDescription
maskMASK
nb2_widthINT
nb2_heightINT
preview_imageIMAGE
center_xINT
center_yINT
crop_widthINT
crop_heightINT
infoSTRING