Nodes/yiu_comfy_nodes/✂ Item Cropper
ComfyUI Node

✂ Item Cropper

Tighten a cutout to its own mask — and fix the mask while you're at it

By leizingyiu·Created about a year ago·Updated 3 months ago· 1
✂ Item Cropper
  • ori_img
  • ori_mask
  • cutout_img
  • cutout_mask
  • croped_img
  • croped_msk
  • croped_msk_i
  • help_text
padding0
x_pos0
y_pos0

After a background-removal pass, your cutout is rarely snug. Most cutout nodes return the product sitting in a full-size canvas with a mask that says "transparent here, product here" - and the empty padding around the subject is dead weight that drags through every downstream resize and composite. yiuItmCropper crops the cutout down to the bounding box of its own mask, optionally with padding, and produces cleaned-up masks to match.

It's the tidy-up step in the same product pipeline as yiuFitItm2Msk and yiuImgCnvPlacer: cut out → crop tight → place. If your cutout node already returns a tight crop, you don't need this; if it leaves a padded frame, this is where you reclaim the pixels.

How it works

The node finds the bounding box of the cutout_mask (its nonzero pixels), then crops cutout_img to that box. padding adds breathing room around the bbox, and x_pos/y_pos shift that padding asymmetrically - positive x puts more padding on the left, negative on the right (and likewise for y, top vs bottom), which is useful when your subject leans one way. The interesting part is the two mask outputs:

  • croped_msk = cutout_mask × inverted ori_mask - the cutout mask minus whatever the original mask covered. If the original cutout preserved a bit of background, this subtracts it.
  • croped_msk_i = cutout_mask + ori_mask - the union of both, for when you want to keep every bit of the original region.

Both are cropped to the same window as the image, so all three outputs line up pixel-for-pixel.

The inputs that matter

  • cutout_img / cutout_mask - the result of your background-removal node. Required; the node errors if they're missing.
  • ori_img / ori_mask - the original image and mask. ori_mask is optional but important (see below).
  • padding (0–500 px), x_pos / y_pos (−100 to 100).

Outputs

croped_img (the tight crop), croped_msk (cutout minus original mask), croped_msk_i (cutout plus original mask), and the pack's usual help_text string.

Installing it

Part of yiu_comfy_nodes by leizingyiu. ComfyUI Manager → search yiu_comfy_nodes, or:

cd ComfyUI/custom_nodes
git clone https://github.com/leizingyiu/yiu_comfy_nodes

Restart after. No extra dependencies or model downloads.

Where people get burned

  • Omitting ori_mask silently zeroes croped_msk. If you leave it unconnected, the node treats it as fully white, so the subtract becomes cutout_mask × black = all black. If you only care about croped_img that's fine; if you wire croped_msk downstream expecting a real mask, you'll get nothing. Connect the original mask.
  • All-black cutout mask is handled, not errored. The node detects an empty bbox and returns the cutout image unchanged with a black mask and a "cutout_mask 全黑" note in the help text. Not a crash - just check why your cutout came back empty.
  • The two masks are different. croped_msk removes the original subject region; croped_msk_i keeps it. Pick deliberately - using the wrong one either erases your product or reintroduces the background you cut out.
Categoryyiu_nodes

Inputs (7)

NameTypeDefaultDescription
ori_imgIMAGE
ori_maskMASK
cutout_imgIMAGE
cutout_maskMASK
paddingINT00–500
x_posINT0-100–100
y_posINT0-100–100

Outputs (4)

NameTypeDescription
croped_imgIMAGE
croped_mskMASK
croped_msk_iMASK
help_textSTRING