Nodes/ComfyUI_pixel_snapping/Powerful Mask Restore
ComfyUI Node

Powerful Mask Restore

The paste-back that undoes all of Powerful Mask Crop's work

By flywhale-666·Created 8 months ago·Updated 7 months ago· 58
Powerful Mask Restore
  • original_image
  • processed_crop
  • original_mask
  • crop_info
  • restored_image

The crop is easy. Pasting the edited crop back so it lines up, at the right scale, with no seam and without wrecking the rest of the image - that's where local-edit workflows fall apart. Powerful Mask Restore is the back half of this pack's crop → process → restore loop, and it exists so you never have to think about any of that. You feed it the original, the edited crop, a mask, and the crop_info dictionary from Powerful Mask Crop, and it handles the resize, the padding removal, and the blending.

This is the node that makes the whole "swap a face, re-render a region" pattern in this pack feel like it costs you nothing. The well-known alternative is ImageCompositeMasked, which pastes a crop back with a simple mask blend - but it leaves scaling, padding, and coordinate bookkeeping to you. This node inherits all of that from crop_info, which is a genuine ergonomic win when you're doing it a hundred times.

How it works

It's mostly bookkeeping with a mask blend at the end. First it reads the crop info: the original image size, the exact crop rectangle, the cropped size, and how much padding was added. The processed crop gets resized to the recorded cropped size (in case your editing step changed its dimensions), then the recorded padding is stripped off, then the valid region is scaled back to the crop rectangle's real pixel size on the original. Finally it blends the pasted region against the original using your original_mask, so only the pixels you actually want replaced get replaced.

That last step is the part people undersell. Because the blend is driven by the mask, you can limit a face replacement to just the face - feed a mask that's white only over the face and black over the hair, and the hair stays untouched. This is exactly the "paste only the masked region back" advice in the inpainting playbook, and it also keeps the untouched parts of the image from ever passing through a VAE cycle, which is a known source of subtle color drift.

The inputs that matter

  • original_image - the untouched original.
  • processed_crop - whatever your processing step produced, at any size. It gets scaled to fit.
  • original_mask - controls which pixels of the crop region get replaced. White = replace, black = keep the original. A soft/feathered mask makes the seam vanish.
  • crop_info - the CROP_INFO output from Powerful Mask Crop (or Face Hand Crop, which emits the same structure). This is the contract; don't swap it between different images.

Outputs

  • restored_image - the full original with the processed crop composited in. That's the whole output; it goes straight to a preview or save.

Install

It ships with the pack, so it's the standard drill. ComfyUI Manager, search "Pixel Snapping", or:

cd ComfyUI/custom_nodes
git clone https://github.com/flywhale-666/ComfyUI_pixel_snapping
cd ComfyUI_pixel_snapping
pip install -r requirements.txt

Full restart of ComfyUI afterwards - this pack's README warns that a refresh won't pick up node changes.

Common issues

  • White edges around the pasted region - the README's most-answered question, and it's usually a mask problem. If you cropped with white padding and the mask doesn't cover the padding area on the original, the border shows. Check that original_mask is white exactly where you want the replacement.
  • Pasted region looks wrong or blurry - the crop got rescaled up or down to fit, and if your processing step changed the aspect ratio the restore can't fix that. Edit the crop at the same aspect ratio you cropped it at.
  • Only the first batch image - same limitation as every node in this pack; loop if you need batches.

For the common "face detail / local swap" workflow this pair - crop, process at a clean resolution, restore - is hard to beat for simplicity, and it quietly avoids the whole class of "my edited region doesn't match my original" problems.

Categoryimage/transform

Inputs (4)

NameTypeDefaultDescription
original_imageIMAGE
processed_cropIMAGE
original_maskMASK
crop_infoCROP_INFO

Outputs (1)

NameTypeDescription
restored_imageIMAGE