Nodes/ComfyUI-RMBG/Resolution Selector (RMBG) ⛶
ComfyUI Node Runs on cloud

Resolution Selector (RMBG) ⛶

Resolution Selector (RMBG)

By 1038lab·Created 2 years ago·Updated 4 days ago· 2,199
Resolution Selector (RMBG) ⛶
    • latent
    • width
    • height
    ◄aspect_ratio1:1 (Square)►
    ◄megapixels1.00►
    ◄multiple8►
    ◄batch_size1►

    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.

    Category🧪AILab/🖼️IMAGE

    Inputs (4)

    NameTypeDefaultDescription
    aspect_ratioCOMBO1:1 (Square)The aspect ratio for the output dimensions.
    megapixelsFLOAT1.000.01–16Target total megapixels. 1.0 MP ≈ 1024×1024 for square.
    multipleINT88–128Round the result to the nearest multiple of this value.
    batch_sizeINT11–4096Number of latent images in the batch.

    Outputs (3)

    NameTypeDescription
    latentLATENTEmpty latent image at the calculated resolution.
    widthINTCalculated width in pixels (rounded to the selected multiple).
    heightINTCalculated height in pixels (rounded to the selected multiple).