ComfyUI Node

NB2 Mask Generator

NB2 Mask Generator — the manual rectangle for people who know exactly where to edit

By amortegui84·Created 5 months ago·Updated 3 months ago· 3
NB2 Mask Generator
  • image
  • mask
  • nb2_width
  • nb2_height
  • preview_image
aspect_ratio16:9
resolution2K
center_x512
center_y512
crop_width960

Nano Banana 2 doesn't inpaint, and this node is the most literal version of the pack's workaround: you draw a rectangle, the pack crops to it, Nano Banana regenerates it, and the stitch pastes it back. No segmentation model, no API call, no guesswork - just a positioned box on your image.

NB2 Mask Generator is the "manual" entry point into the NB2 crop/stitch path, for when you know the exact region you want regenerated and don't need a Florence-2 or SAM model to find it for you. It's the node the pack's demo workflow (00_manual_nb2_crop_stitch_nano_banana2.json) starts from, and it's the easiest way to verify the whole roundtrip works before you add smart selectors.

The inputs that matter

Required inputs are image, the geometry, and the shape:

  • center_x / center_y - the center of your crop rectangle, in pixels on the original image. These are what you'll actually drag around as you dial in the region. Defaults of 512/512 are rarely where you want to be.
  • crop_width - width of the rectangle on the source. Height is auto-calculated from the aspect ratio, so you only set one dimension. Clamped if it would exceed the image.
  • aspect_ratio (16:9, 9:16, 1:1) and resolution (1K, 2K, 4K) - the shape and budget. These must match what you set on NB2 Crop later, because together they pick the exact Nano Banana output size (16:9 @ 2K → 2752×1536, etc.).

Outputs: mask (the rectangle mask, into NB2 Crop), nb2_width / nb2_height (the exact NB2 output dimensions, if you want them as ints), and preview_image - a copy of your source with the crop rectangle drawn on it. Wire that into any Preview Image node and you get instant visual feedback on where the rectangle sits before you waste a generation on it. That preview is genuinely the most useful output here; without it you're flying blind.

The flow

NanoBanana2MaskGen -> mask -> NB2 Crop -> Nano Banana 2 Edit -> NB2 Stitch

If you'd rather not hand-place the box, skip this node and feed a semantic mask from NB2Florence2RegionSelector or NB2SAM3ImageSegmenter into NB2 Smart Region, which auto-fits the rectangle. But for a first test, or for edits where the smart models keep grabbing the wrong thing, manual is faster and more predictable.

Install

Search comfyui-inpaint-cropstitch-nb2 in ComfyUI Manager, or:

cd ComfyUI/custom_nodes
git clone https://github.com/amortegui84/comfyui-inpaint-cropstitch-nb2

Restart. Nothing to download - this node is pure local geometry, no FAL key needed for it (the edit node downstream is the part that needs the key).

Gotchas

The classic mistake is setting the rectangle to cover more than you intend. Nano Banana will regenerate the whole crop, not just the mask, so a loose rectangle means the model rewrites background it shouldn't have touched - that's the drift that crop-and-stitch exists to prevent. Keep the box tight around what you want changed, then use the preview_image output to confirm. And remember the matching rule: whatever aspect_ratio and resolution you pick here, NB2 Crop must be set identically, or the stitch resamples and the seam shows.

Categoryinpaint/nb2

Inputs (6)

NameTypeDefaultDescription
imageIMAGE
aspect_ratioCOMBO16:93 options: 16:9, 9:16, 1:1
resolutionCOMBO2K3 options: 1K, 2K, 4K
center_xINT5120–16384Horizontal centre of the crop rectangle in pixels.
center_yINT5120–16384Vertical centre of the crop rectangle in pixels.
crop_widthINT96064–16384Width of the crop region on the original image in pixels. Height is auto-calculated from the aspect ratio. Clamped if larger than the image.

Outputs (4)

NameTypeDescription
maskMASK
nb2_widthINT
nb2_heightINT
preview_imageIMAGE