Nodes/tri3d-comfyui-nodes/Narrowfy Image v5.1.0
ComfyUI Node

Narrowfy Image v5.1.0

The node that makes garment crops the tall, skinny shape try-on models want

By TRI3D-LC·Created 3 years ago·Updated about a year ago· 27
Narrowfy Image v5.1.0
  • image
  • mask
  • cropped_image
  • cropped_mask
  • cropped_width
  • cropped_height
aspect_ratio0.33
border_margin15

If you've ever tried a garment virtual-try-on workflow, you know the pain this node exists to solve. The models that warp a garment onto a person don't want your whole photo - they want the clothing alone, cropped tight and stretched into a tall, narrow strip. Narrowfy Image does exactly that: it crops an image around a mask's bounding box, then pads the bottom with black until the result is tall enough to hit whatever aspect ratio you set.

It's the kind of thing you'd otherwise hand-roll with a Crop node, a math node, and a prayer. This is that, pre-baked, plus a matching mask that comes out of the other end. For a pack aimed at garment pipelines, it's one of the more useful utility nodes in the box.

How it works

The mechanism is straightforward OpenCV. It finds the mask's contours, keeps only the ones bigger than 100 pixels (so a speck of noise doesn't set the crop box), takes the combined bounding box, and pads it out by border_margin. Both image and mask get cropped to that box.

Then the "narrowfy" part: if the crop isn't tall enough for aspect_ratio - which is width / height, so a value of 0.33 means the output is about 1:3 - it extends the bottom of the image with solid black and extends the mask with solid white. The black extension is intentional: the model treats it as empty space around the garment, and the mask says "nothing here." It's a resize-free way to hit the tall format without warping the clothing itself.

The inputs that matter

Only four inputs, and honestly only two of them are things you'll touch:

  • image / mask - both plain IMAGE tensors. The mask is what defines the crop region. Feed it the same image and its alpha/segmentation mask.
  • aspect_ratio (FLOAT, 0.25–1, default 0.33) - the target width/height. Lower is taller and skinnier. 0.33 is a good starting point for most garment warpers; push toward 0.25 if your model wants really narrow inputs.
  • border_margin (INT, 10–100, default 15) - breathing room around the garment in pixels.

Outputs: cropped_image, cropped_mask (wire both into your warping/inpainting step), plus cropped_width and cropped_height as INTs if a downstream node needs the crop size.

Installing it

Standard for this pack. ComfyUI Manager - search "tri3d-comfyui-nodes" - or by hand:

cd ComfyUI/custom_nodes
git clone https://github.com/TRI3D-LC/tri3d-comfyui-nodes
cd tri3d-comfyui-nodes
pip install -r requirements.txt

Restart ComfyUI and it appears under the TRI3D category. Note this pack's requirements are heavy (opencv, torch, transparent-background, facer, and friends) even though this node only needs OpenCV - it's one pack serving a whole try-on pipeline, so you get the kitchen sink.

Where people get burned

The one real trap is a bug in the early-return path. If the mask has no contour bigger than 100px - say, a tiny or all-black mask - the code bails out and returns three values where ComfyUI expects four, which throws an error that looks nothing like the cause. The fix is boring: make sure your mask actually covers a decent area before it reaches this node. If the crop comes out the wrong shape, your aspect_ratio is the first thing to check, and remember the black padding at the bottom is normal - that's the feature, not a failure.

CategoryTRI3D

Inputs (4)

NameTypeDefaultDescription
imageIMAGE
maskIMAGE
aspect_ratioFLOAT0.330.25–1
border_marginINT1510–100

Outputs (4)

NameTypeDescription
cropped_imageIMAGE
cropped_maskIMAGE
cropped_widthINT
cropped_heightINT