Nodes/Region Edit Toolkit/图像分区 · 像素区间尺寸规划
ComfyUI Node

图像分区 · 像素区间尺寸规划

Plan the edit size before you touch a pixel, and stop guessing at megapixels

By Liu-Bot24·Created 2 months ago·Updated about a month ago· 1
图像分区 · 像素区间尺寸规划
  • image
  • original_width
  • original_height
  • editor_width
  • editor_height
  • resize_required
  • report_json
min_megapixels1.00
max_megapixels1.50
multiple16

Ask a hundred ComfyUI users why their local edit came out soft or blurry and half of them will be wrong in the same way: they fed the model a crop that's too small to resolve detail, or too big for its native resolution, or just a weird off-multiple that made the VAE do something unkind. RegionEditBoundedImageSizePlan is the node that answers "what size should this crop be" before you ever resize - it computes a target edit size for a crop, keeping the aspect ratio and staying inside a pixel budget you define.

It's part of the Region Edit Toolkit (the ComfyUI-Smart-Removal pack, "Region Edit Toolkit" in the menu). Its job in the pipeline is planning, not resizing: it outputs the numbers - original width/height, planned editor width/height, and a resize_required flag - that you then feed to whatever actually does the resize and, later, to the strict composite that pastes the result back. Getting the "editor size" agreed on before anything else moves is the whole point.

How it works

You give it three numbers: min_megapixels (default 1.0), max_megapixels (default 1.5), and multiple (default 16). It looks at the crop, and:

  • If the crop is below the floor, it plans an upscale to hit the minimum.
  • If it's above the ceiling, it plans a downscale to the maximum.
  • If it's already inside the band, it plans no resize at all - as long as both dimensions are already aligned to multiple.

Alignment to multiple is the bit that saves you pain later: a 16-aligned crop lands cleanly on VAE tile boundaries, which is why the smart-removal workflows care so much about it. The alignment logic deliberately mirrors ComfyUI's mature ImageScaleToTotalPixels behavior - round both axes independently to the step, rather than forcing one axis outward. There's also a hard safety cap: no single axis can exceed 2048px (MAX_EDITOR_LONG_SIDE), and if your crop's aspect ratio is so extreme it can't satisfy both the megapixel floor and that cap, it errors with "increase crop context" instead of silently planning something broken.

Inputs and outputs that matter

Three inputs, and you'll mostly leave them alone: min_megapixels / max_megapixels for the budget band, multiple for alignment. The 1.0–1.5MP band with 16-alignment is a sane default for a 1024-class model.

Outputs: original_width, original_height, then editor_width, editor_height, then the resize_required boolean. That boolean is the one worth wiring somewhere visible - it tells you whether this crop even needs a resize pass, which saves you a wasted upscale on crops that already fit. report_json gives you the whole decision: target pixels, direction (upscale/downscale/none), alignment tolerance, and aspect-ratio error.

Install

ComfyUI Manager → search "Region Edit Toolkit" (package ID native-region-tile-planner-merge) → install → restart. Or clone https://github.com/Liu-Bot24/ComfyUI-Region-Edit-Toolkit.git into ComfyUI/custom_nodes and pip install -r requirements.txt into ComfyUI's actual Python. Python 3.10+; deps are numpy, Pillow, scipy, argostranslate. No models.

Gotchas

The classic trap is min_megapixels > max_megapixels - the node rejects it, so you can't paint yourself into a corner silently. The other one: this node plans the size, it doesn't resize. Beginners plug editor_width into a KSampler and wonder why nothing changed; you need a resize node (or RegionEditExactIntegerDownscale / a standard ImageScale) between the plan and the model. And remember the 2048 long-side cap - plan a huge crop and it'll tell you to widen the context rather than produce an unwieldy image.

CategoryRegion Edit Toolkit/Geometry

Inputs (4)

NameTypeDefaultDescription
imageIMAGE
min_megapixelsFLOAT1.000.1–8
max_megapixelsFLOAT1.500.1–8
multipleINT168–64

Outputs (6)

NameTypeDescription
original_widthINT
original_heightINT
editor_widthINT
editor_heightINT
resize_requiredBOOLEAN
report_jsonSTRING