✂ Item Cropper
Tighten a cutout to its own mask — and fix the mask while you're at it
- ori_img
- ori_mask
- cutout_img
- cutout_mask
- croped_img
- croped_msk
- croped_msk_i
- help_text
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× invertedori_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_maskis 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_masksilently zeroescroped_msk. If you leave it unconnected, the node treats it as fully white, so the subtract becomescutout_mask × black= all black. If you only care aboutcroped_imgthat's fine; if you wirecroped_mskdownstream 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_mskremoves the original subject region;croped_msk_ikeeps it. Pick deliberately - using the wrong one either erases your product or reintroduces the background you cut out.
Inputs (7)
| Name | Type | Default | Description |
|---|---|---|---|
| ori_img | IMAGE | — | |
| ori_mask | MASK | — | |
| cutout_img | IMAGE | — | |
| cutout_mask | MASK | — | |
| padding | INT | 00–500 | — |
| x_pos | INT | 0-100–100 | — |
| y_pos | INT | 0-100–100 | — |
Outputs (4)
| Name | Type | Description |
|---|---|---|
| croped_img | IMAGE | — |
| croped_msk | MASK | — |
| croped_msk_i | MASK | — |
| help_text | STRING | — |