Nodes/ComfyPanel/ImageMask_ScaleRestore
ComfyUI Node

ImageMask_ScaleRestore

Undo the resize without remembering the numbers

By Ginolazy·Created 6 months ago·Updated 2 days ago· 23
ImageMask_ScaleRestore
  • scaled_image
  • scaled_mask
  • scale_data
  • restored_image
  • restored_mask
restore_modeoriginal

ImageMask_ScaleRestore is the "undo" half of the scale-then-restore workflow: it takes an image (and mask) that were scaled down, plus the scale_data from the scaling step, and resizes everything back to the original dimensions. You never have to remember what the original size was or type it in - the metadata carries it for you. It's the return trip that ImageMask_Scale sets up, and together they're the pack's answer to "process small, restore big."

The mechanism is nearly trivial and that's the point: the node reads original_width and original_height out of the SCALE_DATA input and resizes the scaled inputs back to them with bicubic interpolation (nearest-neighbor for masks, clamped to 0–1 afterward so masks don't pick up out-of-range values). If the scaled input already matches the original dimensions, it passes through untouched - a fast path, not an error. It requires at least one of scaled_image or scaled_mask, and it raises if scale_data is missing, because without it there's literally nothing to restore to.

The one input that changes behavior meaningfully is restore_mode. In the default "original" mode you get back a plain restored image and mask, ready to composite onto the original canvas. In "masked" mode it packs the mask into the image's alpha channel and returns an RGBA image - image in RGB, mask as the alpha. That's a genuinely handy output shape if you're feeding the result somewhere that wants a single image-plus-transparency bundle (like pasting onto a layer in Photoshop, which is the ComfyPanel use case), rather than a separate image and mask pair.

Where it fits in a real workflow: the same place as CropByMaskRestore and ImageConcatRestore - at the end of a pipeline that did work at reduced resolution. Run your heavy processing on the scaled-down version (fast, low VRAM), then restore the original size for compositing. If you've ever hand-resized an image in a graph, run a pass, and then had to re-enter the original dimensions in a resize node - and gotten them subtly wrong - this node exists so that whole class of mistake stops happening.

The honest limitation: it only knows how to go back to the size recorded in the scale_data. Pair it with ImageMask_Scale (same pack) and it's seamless; feed it a SCALE_DATA from a different pack and it may or may not line up, since this is a pack-specific type.

Installing it

cd ComfyUI/custom_nodes
git clone https://github.com/Ginolazy/ComfyPanel
# restart ComfyUI

or ComfyUI Manager → "ComfyPanel". No models, standard dependencies. If you hit "Missing scale_data input," the wire is the problem - scale_data is required, not optional, even though the UI shows it as an optional socket. If the restored image looks slightly soft, that's bicubic upscaling of a downscaled image; it's the standard trade, not a bug.

CategoryComfyPanel/Process & Restore

Inputs (4)

NameTypeDefaultDescription
restore_modeCOMBOoriginal2 options: original, masked
scaled_imageoptIMAGE
scaled_maskoptMASK
scale_dataoptSCALE_DATA

Outputs (2)

NameTypeDescription
restored_imageIMAGE
restored_maskMASK