Nodes/ComfyUI Fictiverse Nodes/Clamp Images To Megapixels
ComfyUI Node

Clamp Images To Megapixels

Force every image into a resolution band

By Fictiverse·Created 3 years ago·Updated 23 days ago· 27
Clamp Images To Megapixels
  • images
  • images
min_mp0.6
max_mp1.0
multiple_of32

Clamp Images To Megapixels resizes an actual image tensor so its total pixel count lands inside a band you define - between min_mp and max_mp megapixels - while keeping its aspect ratio. It's the sibling of the pack's Resize To Megapixels, but that one computes numbers for you to use elsewhere; this one does the resizing on real pixels.

The use case is batch and pipeline hygiene. If you're feeding a grab-bag of images into something that cares about resolution - an image-to-video pass, a tagger, an upscaler chain, a batch of reference frames - you don't want some at 0.3 MP and others at 4 MP. A model trained around 1 MP will do strange things with a 0.3 MP input, and a 4 MP input will eat VRAM for no benefit. Clamping everything into a sane band (say 0.6 to 1.0 MP) gives every frame the same fighting chance, which is why "target resolution in megapixels" is such a common pattern in the upscaling and video side of the ecosystem.

How it works

For each image it computes the current pixel count and compares it to your band:

  • Already inside the band → left completely untouched, returned as-is.
  • Above max_mp → scaled down to max_mp.
  • Below min_mp → scaled up to min_mp.

The scaling preserves aspect ratio and then rounds each side to the nearest multiple_of (default 64), so the output stays on the divisibility grid diffusion models like. The resize itself uses bilinear interpolation - a reasonable, fast choice, though it's a plain resize, not a generative upscale. Don't expect detail invention when it scales small images up; it just makes them bigger and softer. If you need real quality upscaling, run this to normalize dimensions first, then a proper ESRGAN/SeedVR-style pass on the result.

One nuance: the code only resizes when the image is outside the band, so images already in range pass through untouched with zero quality cost. And it operates on the whole batch at once, so it's one node per batch, not one per frame.

Inputs and outputs

  • images (IMAGE) - the batch to normalize.
  • min_mp (FLOAT, default 0.6) - floor in megapixels; smaller images get upscaled.
  • max_mp (FLOAT, default 1.0) - ceiling in megapixels; bigger images get downscaled.
  • multiple_of (INT, default 64) - divisibility rounding.

Output:

  • images (IMAGE) - the normalized batch. Same name as the input, which is mildly confusing but standard.

Installing it

In ComfyUI Fictiverse Nodes. ComfyUI Manager → search "ComfyUI Fictiverse Nodes" → install → restart, or:

cd ComfyUI/custom_nodes
git clone https://github.com/Fictiverse/ComfyUI_Fictiverse

Dependencies are just torch and torch.nn.functional, which ComfyUI already has. No model downloads. Apache 2.0.

Common issues

Pack gotcha: ModuleNotFoundError: No module named 'custom_nodes.ComfyUI_Fictiverse' means the folder isn't named exactly ComfyUI_Fictiverse; rename and restart.

Node-specific, three things. First, if min_mp is set high, upscaling small images with bilinear gives soft mush - set a realistic floor and do real upscaling separately. Second, the rounding to multiple_of can nudge a result outside the band; with a 64 multiple and a tight band (like 0.95–1.0), the nearest multiple might land just over. Give the band a little slack. Third, the mask/output naming - the returned tensor is a new object, so if something else was holding the original you'll want to rewire the output forward rather than assume in-place mutation.

CategoryFictiverse/Image

Inputs (4)

NameTypeDefaultDescription
imagesIMAGE
min_mpFLOAT0.60.1–100
max_mpFLOAT1.00.1–100
multiple_ofINT321–512

Outputs (1)

NameTypeDescription
imagesIMAGE