Resolution Selector (RMBG) ⛶
Resolution Selector (RMBG)
- latent
- width
- height
Every workflow has the same little moment. You decide you want a 16:9 image at roughly a megapixel, so you type 1365 into the width box, get a ratio that's a hair off, and then remember the number has to be divisible by something. Then you do it again for the next generation.
Resolution Selector (RMBG) does that arithmetic for you, and then hands you an empty latent so you can delete the Empty Latent Image node. That's the whole pitch - it's a calculator with a latent output.
Why you should be thinking in megapixels anyway
The durable way to talk about image size is a ratio plus a pixel budget, because that's how the models see it. SDXL is native at 1024x1024 and only really likes its trained aspects; Flux wants dimensions divisible by 64; the 2026 crop is looser, mostly taking anything in a 1–2 megapixel band and degrading softly rather than sprouting a second head. HiDream-O1 is the exception that proves the point: it's forced to 2048² and produces noise at 1024.
Once you're thinking "9:16, about 1.5 megapixels," the actual numbers are your node's problem, not yours. That's the abstraction this node bakes in.
How it works
It keeps a ratio table - thirteen square and landscape options plus the seven portrait mirrors, from 1:1 (Square) through 16:9, 21:9 (Ultrawide), 2.39:1 (Panavision) and 3:1 (Panorama) down to 9:16 (Portrait Widescreen) and 1:3 (Portrait Panorama).
From the ratio and your megapixel target it computes total = megapixels × 1024², then scale = sqrt(total / (width_ratio × height_ratio)), then rounds each dimension to the nearest multiple of your multiple value with a floor of multiple itself. Finally it builds a latent of zeros shaped [batch_size, 4, height//8, width//8] on ComfyUI's intermediate device and dtype, and returns it with downscale_ratio_spacial: 8 - the same shape and metadata a stock Empty Latent Image produces. So it isn't a fake latent; downstream samplers treat it identically.
The inputs worth setting
aspect_ratio and megapixels (range 0.01–16, default 1.0) are the pair you think about. The tooltip is honest about the conversion: "1.0 MP ≈ 1024×1024 for square."
multiple is the one with teeth, and it's what most people never touch. Default 8 is right for SD 1.5 and SDXL-family checkpoints. Set it to 64 for Flux.1-era models, which require divisibility by 64. If you're generating for a model in the 1–2MP band, megapixels 1.0–2.0 is the sensible window; don't push Z-Image past roughly 2MP.
batch_size is the number of latents in the batch, not a folder of images.
The outputs
latent goes straight into your sampler's latent input - that's the Empty Latent Image node replacement. width and height come out as plain integers, which is the underrated half: feed them to an ImageScale, to a hires-fix second pass, or to anything else that wants to know how big the first pass was.
They're also useful when you're sizing a smaller first pass on purpose. Comfy Org's own handbook recommends dropping a soft source to 0.35 megapixels before a SeedVR2-style generative upscale, on the logic that a blurry image has no detail to keep at full size. Set megapixels to 0.35, take the width and height, and scale to them.
Installing it
Manager: search Comfyui-RMBG, install, restart. Manual:
cd ComfyUI/custom_nodes
git clone https://github.com/1038lab/ComfyUI-RMBG
cd ComfyUI-RMBG
./ComfyUI/python_embeded/python -m pip install -r requirements.txt
Be aware of what you're signing up for. The installer pulls the whole pack's dependency tree - transparent-background, segment-anything, groundingdino-py, both onnxruntime and onnxruntime-gpu, transformers, diffusers, plus hydra/omegaconf for SAM2. There are dependency-free resolution pickers out there. You install RMBG because you want the background removers; this node is the freebie.
Gotchas
batch_size goes to 4096 and the slider is not a licence. megapixels going to 16 is worse - a 16MP latent will not fit on a consumer card, and the widget won't warn you.
You can't hit an SDXL train bucket exactly. There's no 7:4 in the ratio list, so 16:10 at 1MP lands around 1280x800 rather than SDXL's trained 1344x768. On 2026 models that barely matters. If you're strictly reproducing an SDXL bucket, this node is not the tool.
Rounding is to the nearest multiple, not the floor, so your real output usually lands slightly above the megapixel target.
Pack-level stuff that bites people. Both onnxruntime and onnxruntime-gpu are in requirements.txt, and installing them in the wrong order leaves you on CPU inference without any error. On Windows, if the desktop app crashes after the install, set PYTHONUTF8=1 and reinstall the requirements. And if a GroundingDINO or SAM2 node throws a 401, it's a stale HuggingFace token - delete the token file and let it download anonymously.
Inputs (4)
| Name | Type | Default | Description |
|---|---|---|---|
| aspect_ratio | COMBO | 1:1 (Square) | The aspect ratio for the output dimensions. |
| megapixels | FLOAT | 1.000.01–16 | Target total megapixels. 1.0 MP ≈ 1024×1024 for square. |
| multiple | INT | 88–128 | Round the result to the nearest multiple of this value. |
| batch_size | INT | 11–4096 | Number of latent images in the batch. |
Outputs (3)
| Name | Type | Description |
|---|---|---|
| latent | LATENT | Empty latent image at the calculated resolution. |
| width | INT | Calculated width in pixels (rounded to the selected multiple). |
| height | INT | Calculated height in pixels (rounded to the selected multiple). |