Nodes/tri3d-comfyui-nodes/Smart Box v5.1.0
ComfyUI Node

Smart Box v5.1.0

Turn a lower-body mask into one smart rectangle

By TRI3D-LC·Created 3 years ago·Updated about a year ago· 27
Smart Box v5.1.0
  • image
  • IMAGE
keypoints_json

For a lot of virtual try-on, you don't want a precise garment mask for the second pass - you want a solid rectangle covering the lower body, so the inpaint has free rein to redraw the whole region without fighting an exact boundary. That's what Smart Box does: it takes your lower-body mask, anchors the top of the box at your actual hips (from pose keypoints, not the image edge), and fills the occupied area with solid white.

Part of the tri3d-comfyui-nodes pack (TRI3D-LC, v5.1.0), and pure OpenCV. No model, no downloads.

How it works

Feed it a mask image and a DWPose keypoint JSON. It:

  1. extracts the torso keypoints - indices 8–13 (MidHip, RHip, RKnee, RAnkle, LHip, LKnee),
  2. takes the topmost of those as the hip line,
  3. finds contours of the mask below that line,
  4. drops tiny specks (contour area ≤ 20 px),
  5. draws one bounding rectangle around everything that remains - filled white.

That's the "smart" part: the box is driven by where the pose says the hips are, and only spans actual mask content below them, so it hugs the legs instead of spanning the full image width.

Output is an IMAGE - a mask with a solid white box over the lower body. You'll typically convert it to MASK or feed it straight into your inpainting/inpaint-anything node.

The inputs

  • image - the mask. Only channel 0 is read, so a grayscale or white-on-black mask works.
  • keypoints_json - STRING with the file path to the keypoints file, same 130-point OpenPose layout used across this pack (tri3d_SaveFlattenedPoseKpsAsJsonFile produces it directly from DWPose).

Two inputs, one output. That's the whole node.

Install

ComfyUI Manager → search tri3d-comfyui-nodes, or:

cd ComfyUI/custom_nodes
git clone https://github.com/TRI3D-LC/tri3d-comfyui-nodes

Restart ComfyUI. No model weights needed for this node.

Gotchas

If the pose has no valid torso keypoints, hip_y falls back to 0 and the node returns the image unchanged - a silent pass-through, so check that DWPose actually detected a person. The box is a single rectangle across all surviving contours, which is what you want for a dress or trousers but wrong if you're trying to isolate a single leg. And if your mask is noisy, the 20px area filter is your friend - the only difference between this and the pack's Smart Depth twin, which fills black instead and keeps near-tiny specks. Grab the white-fill one for inpainting; you almost certainly don't want the black one.

CategoryTRI3D

Inputs (2)

NameTypeDefaultDescription
imageIMAGE
keypoints_jsonSTRING

Outputs (1)

NameTypeDescription
IMAGEIMAGE