ComfyUI Node

Mpi Box

Package a rectangle as a real object

By MadPonyInteractive·Created 11 months ago·Updated 5 days ago· 3
Mpi Box
    • mpi_box
    width512
    height512
    x0
    y0

    Every time you crop, mask, or region-process an image you're describing a rectangle: width, height, and where it sits. In most of ComfyUI that means dragging four loose INT wires across your graph, and after the third one you start losing track of which width goes with which x. Mpi Box exists to make the rectangle itself a value. You type width, height, x, y - where x/y are the top-left corner - and out comes a single MPI_BOX that travels on one wire into any box-aware node.

    It's the same idea as ComfyUI's core PrimitiveBoundingBox, but done as an explicit builder: four widgets in, one bundled type out, nothing else. The mpi_box output feeds the pack's own consumers - Mpi Box Crop, Mpi Box Mask, Mpi From Box - and any other node that declares an MPI_BOX socket.

    The clever bit, and the reason this rectangle is safer than four loose ints, is that consumers clamp. The docs are explicit that a box-aware consumer clamps the box to the image, so out-of-bounds values are safe rather than a crash. And the x/y widgets go negative - down to -4294967295 in the schema, with a tooltip spelling it out: "Left edge of the box, in pixels. May be negative to start outside the image." That's a deliberate feature, not an oversight: a box that starts left of the image lets you sit tight on a subject at the frame edge without growing until it swallows the neighbor. A normal crop node would refuse or silently misbehave on a negative coordinate; this type is built to tolerate it.

    Inputs: width and height (INT, default 512, 0 to 4.29 billion - 0 width or height is legal and just produces an empty region), plus x and y with the negative range and the top-left semantics. Output: mpi_box, an MPI_BOX.

    Where this fits in a real workflow: you're doing localized work - a region crop for a detail pass, a mask for an inpaint, a "get the face region" box from a detector. Rather than threading x/y/w/h as four loose wires and praying the order stays right, build the box once, carry it on one wire, and every box consumer downstream agrees on what "the region" means. It's the region-bundling pattern from the KB's plumbing doc applied to rectangles: fewer wires, fewer order-of-operations bugs, and a single value you can reroute and inspect.

    The honest trade-off is the standard one for bundled types: an MPI_BOX is only useful where another node speaks MPI_BOX. The pack ships Mpi From Box as the escape hatch (unpack back to four INTs), so you're never stranded - but if you live entirely in a non-MPI ecosystem, four loose wires may still be simpler for you. Within this pack's workflows, though, the box type is the backbone of the crop/mask tooling.

    Install is pack-standard: ComfyUI Manager → search ComfyUi-MpiNodes → install, or clone it:

    cd ComfyUI/custom_nodes
    git clone https://github.com/MadPonyInteractive/ComfyUi-MpiNodes
    

    Restart, and it's under MpiNodes/ImgOps. No requirements file, no model downloads - pure Python on top of ComfyUI, the same pack behind the Cubric Vision app.

    CategoryMpiNodes/ImgOps

    Inputs (4)

    NameTypeDefaultDescription
    widthINT5120–4294967295
    heightINT5120–4294967295
    xINT0-4294967295–4294967295Left edge of the box, in pixels. May be negative to start outside the image.
    yINT0-4294967295–4294967295Top edge of the box, in pixels. May be negative to start outside the image.

    Outputs (1)

    NameTypeDescription
    mpi_boxMPI_BOX