Nodes/Canvas/Canvas Selector
ComfyUI Node

Canvas Selector

Crop a region out of a huge canvas and make it generation-ready

By leocbehe·Created about a year ago·Updated about a year ago· 0
Canvas Selector
  • input_canvas_image
  • selector_mask
  • selection
  • selection_mask
  • canvas_context
scale_factor1.00
pixel_padding128

The workhorse of the leocbehe/canvas pack. You've got a big canvas and you want to generate into a small corner of it at full resolution - not push the whole slab through the sampler. Canvas Selector cuts a region out, pads it, sizes it to the multiples of 8 the latent model demands, and hands you the crop plus a context token you'll need to put it back.

The mechanism

You feed it the full canvas (input_canvas_image) and a mask (selector_mask). It finds the bounding box of the nonzero pixels - the part you actually want to regenerate - and snaps that box to multiples of 8, because ComfyUI latent sizes don't play nice otherwise. Then it applies pixel_padding (default 128) to all four sides, shrinking each side's padding if it would run past the canvas edge. That's the same reasoning as classic inpaint padding: a little surrounding context makes the model blend instead of pasting a floating island. Finally, if scale_factor isn't 1.0, the crop gets resized with bilinear interpolation to a multiple-of-8 size, so you can generate a 512×512 patch into a region that was only 300px on the canvas.

Empty mask? It treats the whole canvas as the selection. That's not a bug, it's a graceful fallback, but it probably means something upstream is off.

The three outputs

  • selection - the cropped, padded, optionally scaled region as an IMAGE. This is what you feed to your sampler's latent or an inpaint pipeline.
  • selection_mask - the same crop as a MASK, so you can mask the inpaint region, control denoise strength, or feather edges.
  • canvas_context - a CONTEXT object. This is the pack's own tuple: the original canvas plus the bounding box and scale factor. It's not a generic pipe; don't try to feed an rgthree or Efficiency-Nodes context into it. Wire it straight into the pack's Canvas Merger and nothing else.

Why you'd bother

This is the "only masked at full resolution" pattern the community has converged on: a 64px feature gets a full generation budget, not a few blurred pixels. The KB's crop-edit-stitch crowd does the same thing with dedicated crop/stitch nodes; this pack is the hand-rolled version, and Selector is where the crop half happens. The mask itself can come from anywhere that produces a MASK - manual paint, SAM, a VLM-grounded box expanded to a mask. The author even keeps the scale factor in the context so the merger knows how to resize your generated piece back to its original slot.

Practical notes

scale_factor runs 0.1–4.0 in 0.05 steps; values under 1 downscale (generating a smaller piece to paste up), over 1 upsample the crop. pixel_padding runs 0–1024 in steps of 8; 128 is a decent starting point, 64 for tight detail fixes. Since it's an output node it always executes, and it prints a few shape lines to the console that are harmless.

Installing

It's in the same pack as the rest of the Canvas nodes. ComfyUI Manager → search "Canvas", or:

cd ComfyUI/custom_nodes
git clone https://github.com/leocbehe/canvas

Restart ComfyUI. No extra dependencies, no model downloads. Full walkthrough lives on the Canvas Loader page; the loop is Loader → Selector → generate → Canvas Merger.

CategoryCanvasNodes

Inputs (4)

NameTypeDefaultDescription
input_canvas_imageIMAGE
selector_maskMASK
scale_factorFLOAT1.000.1–4
pixel_paddingINT1280–1024

Outputs (3)

NameTypeDescription
selectionIMAGE
selection_maskMASK
canvas_contextCONTEXT