Nodes/ComfyDL/Box Center→Corner
ComfyUI Node

Box Center→Corner

Bounding boxes in (cx, cy, w, h)? Convert them to corners in one step

By Cynthia-lxx·Created 2 months ago·Updated 2 days ago· 6
Box Center→Corner
  • boxes
  • boxes_xyxy

CdlBoxCenterToCorner is a format converter for bounding boxes: it takes boxes written as center-x, center-y, width, height and rewrites them as top-left / bottom-right corners (x1, y1, x2, y2). Boring on its own, but it's the kind of boring that saves you from the classic object-detection bug - feeding a center-format box into a corner-format function and silently getting nonsense. In ComfyDL, almost everything downstream (IoU, anchor assignment, NMS, drawing) expects corners, so this node is the glue.

How it works

It's four lines of arithmetic per box. Given a box (cx, cy, w, h):

x1 = cx - 0.5 * w
y1 = cy - 0.5 * h
x2 = cx + 0.5 * w
y2 = cy + 0.5 * h

In other words: the center is known, and the width and height tell you how far the corners are from it in each direction. The node takes your boxes tensor, applies that to every row, and stacks the result back into an [N, 4] tensor. It calls a shared _ensure_2d helper first, so a single box or a batch both work.

Inputs and output

  • boxes - a cdlTensor of [N, 4] boxes in (cx, cy, w, h) format.

The output is boxes_xyxy, a cdlTensor of [N, 4] boxes in (x1, y1, x2, y2) format. It's a pure transform - shape in, shape out, nothing learned.

Where it fits

Object detection in ComfyDL has a defined box currency: cdlBbox tensors in corner format. Anchor generation and prior boxes are often specified in center format (it's how SSD and similar detectors think about them), so anything produced by a center-style node needs converting before it can be scored or matched. The sibling node CdlBoxCornerToCenter does the exact inverse, and the two round-trip cleanly - run both and you get your original boxes back. If you're following the README's detection pipeline (CdlMultiboxPrior → CdlAssignAnchorToBbox → CdlMultiboxTarget), this is the node that keeps the formats consistent.

Installing it

It ships with ComfyDL - one install, 106 nodes:

cd ComfyUI/custom_nodes
git clone https://github.com/Cynthia-lxx/ComfyDL
pip install -r ./ComfyDL/requirements.txt

Restart ComfyUI, or search "ComfyDL" in ComfyUI Manager. No extra dependencies beyond what the pack already brings.

Gotchas

  • There's no validation that w and h are positive. A negative width or height produces inverted corners silently - and a box with negative area will then poison any IoU calculation downstream. If your converted boxes look wrong, check the sign of your input widths first.
  • Keep an eye on which format each node expects. This pack mostly standardizes on corners, but the inverse node exists precisely because people keep tripping on the other direction too. When in doubt, convert, then sanity-check one box by hand.
Categoryd2l/ObjectDetection

Inputs (1)

NameTypeDefaultDescription
boxesTENSOR

Outputs (1)

NameTypeDescription
boxes_xyxyTENSOR