Nodes/WAS Node Suite v3/Bounds to Numbers
ComfyUI Node Runs on cloud

Bounds to Numbers

Open a rectangle into x, y, width, height

By WASasquatch·Created 3 years ago·Updated 4 days ago· 1,844
Bounds to Numbers
  • image_bounds
  • x
  • y
  • width
  • height
  • right
  • bottom
  • row_count
  • rectangle
index0
out_of_rangewrap

WAS Node Suite's bounds value is deliberately a single object - a region that travels down one wire, keeping a row per image in a batch. That's great until you need the region as numbers: an x to feed a mask node, a width and height to build an empty latent at the region's size, four edges to hand to a crop. Bounds to Numbers is the node that unzips a rectangle into the plain integers the rest of the graph can wire anywhere.

Under WAS Suite/Image/Bound, it takes image_bounds (from Image Bounds, Inset Image Bounds, Mask to Bounds, or Image Crop by Mask) and an index choosing which row to read - 0 is the first, -1 counts back from the end. If the bounds came from a batch, it holds one row per image, and row_count reports how many. Ask for a row outside that range and an out_of_range setting decides: wrap (default) loops around, clamp pins to the last row, error stops the prompt. A bounds value holding no rows stops the prompt whichever you choose - there's nothing to read and it says so.

The outputs are the rectangle taken apart:

  • x / y - the top-left corner, in pixels from the left and top. Wire these to any x or left input - Mask Rect Area's x, Image Crop Location's left.
  • width / height - how many pixels the rectangle spans. Feed these to an empty latent or empty image node and you can generate or work at exactly the region's own size. Divide width by height for the aspect ratio an upscale should respect.
  • right / bottom - one column/row past the far edge (x + width, y + height). That's the convention crop-location nodes read: Image Crop Location takes left 10 and right 138 to crop 128 columns. Missing this off-by-one convention is how people crop a 127-pixel sliver and blame the wrong node.
  • row_count - how many rows the bounds value holds, so you can loop over a batch's regions without guessing.
  • rectangle - the whole thing as one string, x,y,width,height: a region at column 10, row 20, 128 wide and 96 high reads 10,20,128,96. Useful for filenames, captions, or a text note next to a render.

Why unzip a rectangle at all?

Bounds exist so a region can travel as one value; numbers exist so a region can reach any node, including ones that never heard of bounds. The classic need: you measured a region with Mask to Bounds, you want to re-render just that area at its own resolution, and the sampler path wants width, height, and a coordinate - not a custom type. Unzip here, and the same measured rectangle becomes the exact inputs of a dozen unrelated nodes. For the past-tense version of the job - getting a region back into the rectangle system after working on it - the mirror-image converters in the same menu (Bounds to Crop Data, Bounds to Bounding Boxes) are your friends.

Installing

Part of WAS Node Suite v3 (WASasquatch/was-node-suite-comfyui), WASasquatch's MIT pack - going since 2023, over a million downloads, and the historical home of most of these image/region utilities in ComfyUI. Pure number plumbing: no packages, no models, no downloads. Requires ComfyUI 0.14.0+ since v3 is built on ComfyUI's newer node backend.

Via ComfyUI Manager, search WAS Node Suite v3, or clone:

cd ComfyUI/custom_nodes
git clone https://github.com/WASasquatch/was-node-suite-comfyui

Restart ComfyUI and it appears under WAS Suite/Image/Bound. Missing after install? Update ComfyUI before anything else.

CategoryWAS Suite/Image/Bound

Inputs (3)

NameTypeDefaultDescription
image_boundsIMAGE_BOUNDSThe rectangle to read, from Image Bounds, Inset Image Bounds, Mask to Bounds or Image Crop by Mask. A bounds measured over a batch holds one row per image, which row_count reports.
indexINT0-16384–16384Which row to read. 0 = the first row; -1 = the last, counting back from the end; -2 = the one before it. A row that is not there is settled by out_of_range.
out_of_rangeCOMBOwrapIndex outside 0..row_count-1. With 3 rows and index 4: `wrap` = row 1, `clamp` = row 2, `error` stops the prompt. A bounds value holding no rows stops the prompt whichever is chosen.

Outputs (8)

NameTypeDescription
xINTFirst pixel column the rectangle covers, counting from the left of the image. Wire it to an x or left input, such as Mask Rect Area's x or Image Crop Location's left.
yINTFirst pixel row the rectangle covers, counting from the top of the image. With x it gives the rectangle's top left corner.
widthINTPixel columns the rectangle covers, so a row running from column 10 to column 137 is 128 wide. Feed it to an empty latent or image to work at the region's own size.
heightINTPixel rows the rectangle covers. Divide width by height for the aspect the region wants an upscale or a generation to keep.
rightINTOne column past the last the rectangle covers, which is x plus width. That is what Image Crop Location's right input reads: left 10 with right 138 crops 128 columns.
bottomINTOne row past the last the rectangle covers, which is y plus height. Image Crop Location's bottom input reads the same way.
row_countINTRectangles the bounds value holds, which is 1 for a single mask and one per image for a batch. index runs from 0 to row_count-1.
rectangleSTRINGThe rectangle as `x,y,width,height`: a region at column 10, row 20, 128 wide and 96 high reads `10,20,128,96`. Useful in a filename, a caption or a note beside a render.