Uncrop Mask
Stitch the mask back into the full frame
- original_mask
- cropped_mask
- uncropped_mask
Masks get cropped too. When you crop an image to edit a region, the mask that describes that region usually travels with it - and when the edit comes back, you need both the image and the mask stitched back into full-frame coordinates. UncropImage handles the image side; UncropMask is its sibling for the mask side. It takes the original full-frame mask (which defines where the crop came from) and the cropped mask, and splices the cropped one back into a zero-filled canvas at the position the original mask's bounding box describes.
It's the completion of the crop-and-stitch loop the Rebalance Pack is built around - crop, edit, paste image back with UncropImage, paste mask back with UncropMask. If you've ever hand-built that last step with tensor slicing and cursed, this node exists for you.
How it works
The mechanics mirror UncropImage exactly, but for masks. It finds the bounding box of the non-zero region in original_mask, uses its top-left corner as the anchor, and pastes cropped_mask into a fresh all-zero mask of the original size. The batch handling is the same generous story as the image version: a single cropped mask broadcasts across the batch, the paste is clipped to frame bounds, and the result is a uncropped_mask the same shape as the original, with the cropped content sitting exactly where it belongs.
Because the anchor comes from the original mask's bounding box, everything stays in the same coordinate space automatically. The trick that makes this robust: the mask that defined the crop is the same one you hand back in, so there's no drift between where you think the crop was and where the paste lands. Soft or feathered masks work fine - the node only needs the bounding box, not the values.
The inputs that matter
- original_mask - the full-frame mask that marked the crop region.
- cropped_mask - the mask from the edited region, to be pasted back.
Install
Part of the Rebalance Pack. ComfyUI Manager: search "ComfyUI-Conditioning-Rebalance" (or "Rebalance Pack"). Manual:
cd ComfyUI/custom_nodes
git clone https://github.com/nova452/ComfyUI-ConditioningKrea2Rebalance
Restart afterwards. No models, no dependencies.
Troubleshooting
The usual problems are shape mismatches, and they're almost always upstream. If cropped_mask was produced at a different resolution than the region you're pasting into - say the edit pipeline upscaled it - the paste will land truncated or misaligned; resize the cropped mask to the crop's original dimensions first. If the original_mask is empty (all zeros), there's no bounding box to anchor on and the node returns a zero canvas - check your mask isn't blank before feeding it. And if you're feeding a 2D mask where a batched one is expected, don't worry: the node normalizes 2D/4D masks to the standard 3D batch shape on the way through. Wire this with UncropImage on the image side and your crop-edit-paste loop stays perfectly in sync on both channels.
Inputs (2)
| Name | Type | Default | Description |
|---|---|---|---|
| original_mask | MASK | — | |
| cropped_mask | MASK | — |
Outputs (1)
| Name | Type | Description |
|---|---|---|
| uncropped_mask | MASK | — |