kubakub canvas restore
Crop the padding, land on the exact matrix size
- image
- canvas_plan
- mask
- image
- mask
What it's for
The last third of the canvas sandwich. Your whole-picture pass ran at some grid-friendly work size with a bit of padding on two sides; canvas restore crops the padding off, resizes uniformly back to your exact target, trims the extra video frames the model's frame rule added, and checks the arithmetic on the way out.
The reason this node matters more than it looks: it accepts any uniform scale of the padded canvas. That's the sentence that lets you put a 4× model upscaler - SeedVR2, a 4× ESRGAN, whatever your upscaler of choice is - between the generation and this node. You generate at 1280×720-ish, upscale 4×, and restore lands you on 3840×2160 with no separate resizing step and no accidental non-uniform scale. This is the KB's "upscale after you generate, not instead of generating" advice, wired in.
How it works
Crop the padding (from the plan's pad_align), then uniform resize to the target. resize_method on auto means area when shrinking and lanczos when growing, which is the right pair - area averaging for downscale keeps detail instead of aliasing, lanczos for upscale keeps edges.
Then it verifies. A non-uniformly resized input - anything whose aspect drifted, i.e. someone stretched it somewhere upstream - is refused rather than quietly resampled again. On video it also drops the frames that the model family's frame rule added on top of what you asked for, if trim_frames is on (it is, by default).
Inputs and outputs
image- the generated work canvas, the cropped work canvas, or the target at any uniform scale. All three are accepted, which is the point.canvas_plan- the same plan you gave canvas to work. If the two plans differ, everything downstream is subtly off, so wire from one plan node, don't build two.resize_method-auto, or force a filter if you're chasing a specific look.trim_frames- video: drop the model's extra frames. On by default; turn it off only if you genuinely want the longer clip.mask(optional) - a mask on the work canvas gets restored the same way.
Outputs: image at the exact target size, and mask at the target size - zeros if you fed it nothing, so it's always safe to wire onward. That's the pair you hand to colour matching, a save node, or kubakub export video / frames.
Install
Manager → kubakub nodes → install → restart. By hand:
cd ComfyUI/custom_nodes
git clone https://github.com/kubakubkub/ComfyUI_KubaNodes
python -m pip install -r ComfyUI_KubaNodes/requirements.txt
The only package it adds is opencv-python-headless (keep your own OpenCV if you have one). Needs ComfyUI 0.37.0+. No models, no Blender, no ffmpeg.
Common issues
- "non-uniform" refusal. Something resized the frame on one axis only. Classic causes: an upscale node with separate width and height fields set unevenly, or a Load Image that resized to fit. Fix it upstream; the node is protecting you from a matrix that would land skewed on the building.
- The output size isn't quite the matrix. Read the report - restore does a size check and says what it produced. The usual culprit is a stale plan from a different target size.
- Frames came back one or two short. You turned
trim_framesoff, or the model family's frame rule rounded down, which this pack doesn't do - video families round up. Checktarget_frameson the plan. - Padding showing up in the corner. You fed the padded canvas to something that resized it first, breaking the uniform-scale assumption. The upscaler goes immediately before restore, nowhere else in the chain.
Inputs (5)
| Name | Type | Default | Description |
|---|---|---|---|
| image | IMAGE | The generated (or upscaled) work canvas. | |
| canvas_plan | KUBA_CANVAS_PLAN | The same plan used for canvas to work. | |
| resize_method | COMBO | auto | Final resize to the target: auto = area when shrinking, lanczos when growing. |
| trim_frames | BOOLEAN | true | Video: drop the frames added by the model's frame rule. |
| maskopt | MASK | Optional mask on the work canvas, restored the same way. |
Outputs (2)
| Name | Type | Description |
|---|---|---|
| image | IMAGE | The image at the exact target size. |
| mask | MASK | The mask at the target size (zeros if none). |