Nodes/ComfyUI-SmartImageTools/Smart Image Region
ComfyUI Node

Smart Image Region

Drag a rectangle or polygon, get a mask and a bbox

By slvslvslv·Created about a year ago·Updated 24 days ago· 2
Smart Image Region
  • image
  • mask
  • bbox
type
region_data{"x1":0.25,"y1":0.25,"x2":0.75,"y2":0.75}

Almost every inpainting, cropping, or regional-editing workflow needs the same two things: "where is the region?" and "what does it look like as a mask?" Smart Image Region lets you answer both by literally dragging on the image - it draws your rectangle or polygon right in the node, then outputs both a MASK and a BBOX for whatever is downstream.

How it works

Like SmartImagePoint, this is one of the pack's interactive nodes backed by a JavaScript extension. The node renders your image inside itself and gives you a draggable selection; the selection is stored as JSON in a hidden widget so it persists in the saved workflow. When the graph runs, it parses that JSON and produces the two outputs.

  • type - Rectangle or Polygon. Rectangle is a two-corner drag (stored as {"x1","y1","x2","y2"}, normalized 0–1). Polygon lets you place multiple points and gets filled with OpenCV, which is what you want for irregular regions that a box can't express.
  • mask - a proper [batch, height, width] mask, 1.0 inside the region, 0.0 outside. This plugs straight into inpaint nodes, regional conditioning, or the pack's own SmartColorFillMask.
  • bbox - the region as a normalized [x, y, width, height] box, matching ComfyUI's BBOX convention. Great for crop/paste round-trips where you'll reinsert content at the same spot later.

The y-axis is handled consistently (top-left origin, no surprise flips), so what you draw is what you get.

Inputs and outputs

  • image - the image to select on.
  • type - Rectangle or Polygon.
  • region_data - the hidden JSON holding your selection (editable by hand if you like).

Outputs: mask (MASK) and bbox (BBOX).

Installing it

Same pack as the rest:

cd ComfyUI/custom_nodes
git clone https://github.com/slvslvslv/ComfyUI-SmartImageTools
pip install -r ComfyUI-SmartImageTools/requirements.txt

Restart ComfyUI, or install "SmartImageTools" via ComfyUI Manager. The interactive front end loads from the pack's js/ folder - if the image preview isn't interactive, hard-refresh the browser after install.

How to actually use it

The classic setup: SmartImageRegion → (mask) → Inpaint/regional node, with the bbox saved for an uncrop after. For polygon work, remember you need at least three points for a valid region, and the node falls back to a default triangle if your JSON is malformed. One tip from experience: keep the region a touch inside the subject's true edge rather than hugging it - masks with zero margin produce hard artifacts when you blur or inpaint at the boundary.

CategorySmartImageTools

Inputs (3)

NameTypeDefaultDescription
imageIMAGE
typeCOMBO2 options: Rectangle, Polygon
region_dataSTRING{"x1":0.25,"y1":0.25,"x2":0.75,"y2":0.75}

Outputs (2)

NameTypeDescription
maskMASK
bboxBBOX