ComfyUI Node

Gpt Image Auto Restore

Put the edit back where it came from — and keep the pixels the model didn't touch

By comrender·Created a day ago·Updated a day ago· 0
Gpt Image Auto Restore
  • edited_image
  • raw_image
  • transform
  • edit_mask
  • image
  • restored_edit
  • edit_mask
  • info

What it's for

Gpt Image Auto Restore is the second half of a two-node pair: Gpt Image Auto Prepare pads your original into a canvas the edit model will accept and hands you a transform; the model does its thing; Restore throws the padding away, resamples the content back to your original width and height, and - if you give it a mask - copies every pixel outside that mask straight from your original tensor, untouched.

That last part is the reason the pair exists. Whole-frame edit models regenerate everything they see, so unmasked regions come back close to the original but not identical, and that drift compounds across a chain of edits. Masked editing's one remaining superpower is bit-identical pixels outside the mask (inpainting.md), and this node is how you get that property back after a closed model has already rewritten the frame (external-api-nodes.md).

How it works

Restore doesn't trust anything. It checks that raw_image's dimensions and batch match what the transform recorded, that edited_image's dimensions match the transform's canvas exactly, and that channel counts agree between original and edit. Any mismatch raises instead of guessing - "Restore rejects unexpected generated dimensions rather than guessing how the service transformed them," in the README's words.

Then it slices out the content rectangle, bicubic-resamples it back to your original size, and clamps. Half-precision tensors get upcast for the interpolation and cast back, so the original's dtype and device survive - the info string tells you so.

If you connected edit_mask, the composite is a three-way torch.where: alpha exactly 0 copies the original pixel verbatim, alpha exactly 1 takes the restored pixel, everything in between is a linear blend. That's the "white selects the edit, gray blends it" behavior from the author, implemented literally - zero really is a copy, not a near-copy.

No mask? Mask is all ones and the output is the whole restored frame, which means background drift is preserved along with the edit.

Inputs and outputs

Required: edited_image (what the model gave back), raw_image (the same original you fed Prepare - the input people mix up), and transform (from Prepare). Optional: edit_mask, "Optional raw-image mask; white pixels are replaced," at original resolution, batch 1 or matching.

Outputs: image (restored and composited - the one you save), restored_edit (the complete restored generated image before compositing, so you can see what the model actually changed before you blend it), edit_mask (all ones if you connected nothing), and info.

For a face swap or another local edit, mask at the original resolution: everything outside comes straight from your source, so you're not paying for the model's opinion about the background.

Install

cd ComfyUI/custom_nodes
git clone https://github.com/comrender/ComfyUI-Gpt-Image-Size-Calculator.git

Restart, then search "Gpt Image Auto Restore". In ComfyUI Manager the pack is listed as Gpt Image Size Calculator (registry id gpt-image-size-calculator, publisher comrender). Python 3.10+, no pip install and no API key - zero declared dependencies, on ComfyUI's own PyTorch. Prepare and Restore both came in with v1.1.0.

Where people get burned

Geometry restoration is not image registration. The README's best line, and the one to internalize: matching the canvas doesn't undo the model moving or reshaping your subject. If it shifted a face 40 pixels, you get the shifted face at the right size. Dimensions alone can't tell you whether the model cropped, stretched or recomposed anything, and they won't put it back.

Channels have to match. A three-channel API result against a four-channel RGBA original raises rather than guessing - so if you're feeding an alpha-channel PNG in, strip the alpha first. Three-channel output wants a three-channel source.

The mask must come from the original. Not from Prepare's resized mask output. If you connect the wrong one, you're compositing at the wrong resolution and Restore says so.

Resampling inside the mask still interpolates. The mask protects what's outside it. Everything inside gets resized back up, so don't read "zero is copied verbatim" as "the edited area is lossless."

Use restored_edit when something looks wrong. If the edit comes back misaligned, that output shows you the uncomposited result, which is the difference between "the model moved things" and "I wired the mask wrong" (comfyui-node-plumbing.md is the general reference for these optional-input behaviors - an unwired optional input simply isn't passed, which is why the mask output defaults to ones).

Finally, keep the pairing honest: the same original and the matching transform for each edit. Restore validates the batch it recorded for a reason, and one original can legitimately be broadcast across several generated variations. This is a new, single-maintainer MIT pack with no community track record, so read it before you trust it - though at two Python files, that's a five-minute job.

Categoryimage

Inputs (4)

NameTypeDefaultDescription
edited_imageIMAGE
raw_imageIMAGE
transformGPT_IMAGE_TRANSFORM
edit_maskoptMASKOptional raw-image mask; white pixels are replaced.

Outputs (4)

NameTypeDescription
imageIMAGE
restored_editIMAGE
edit_maskMASK
infoSTRING