Nodes/ComfyUI Sokes Nodes 🦬/Generate Random Background 🦬
ComfyUI Node

Generate Random Background 🦬

A procedural background generator that also writes its own prompt

By m-sokes·Created 3 years ago·Updated 16 days ago· 4
Generate Random Background 🦬
    • image
    • description
    • alpha_matte_path
    â—„width512â–º
    â—„height512â–º
    â—„seed0â–º
    ◄bg_type▾►
    â—„bg_colorâ–º
    â—„compositionally_soundtrueâ–º
    â—„alpha_matte_folderâ–º
    â—„custom_alpha_colorâ–º
    â—„minimal_colorsfalseâ–º
    â—„num_shapes3â–º
    ◄shape_color_mode▾►
    â—„custom_shapes_colors#FF00FF, #552288, 993322â–º
    â—„noise_level0â–º
    ◄post_processing▾►
    â—„post_processing_amount0â–º
    â—„primary_color#000000â–º
    â—„secondary_color#FFFFFFâ–º

    This is the most fun node in the Sokes Nodes 🦬 pack, and possibly the most underrated. Generate Random Background draws a procedural background - solid, gradient, or fog - with shapes, noise, and post-processing, entirely from math and a seed. Then it does the thing that makes it special: it outputs a description of what it just drew, written in natural language, ready to paste into a text-to-image prompt.

    So you get an infinite supply of test backgrounds and the words to describe them. That's a genuinely clever combo for anyone doing compositing, product-shot mockups, or building a dataset.

    How it works

    Everything is seeded and deterministic: same seed, same image. It builds a color palette (respecting primary_color/secondary_color, or random), picks a background type from bg_type (Random, Solid, Gradient, Fog - Random just rolls one of the other three), then draws.

    • compositionally_sound (on by default) places a focal spot on a rule-of-thirds intersection or a split/horizon line - i.e. it tries to look like a designer did it, not a test pattern.
    • alpha_matte_folder - point it at a folder of PNG/WEBP mattes and it overlays a random one, tinted by custom_alpha_color if you like.
    • num_shapes scatters random shapes (circles, stars, polygons) in shape_color_mode: any color, neutral, or your custom_shapes_colors.
    • noise_level adds grain; post_processing applies Blur, Pixelate, Vignette, Chromatic Aberration, Halftone (a real dot-grid halftone), etc.

    Outputs are image (IMAGE), description (STRING - the generated caption), and alpha_matte_path (STRING, the matte it used, if any).

    The inputs you'll actually touch

    • seed - the whole thing is reproducible from this.
    • bg_type - start with Random to explore, lock to Solid/Gradient/Fog once you know the vibe.
    • compositionally_sound - leave on. Trust me.
    • post_processing_amount - note this only applies if post_processing isn't "None" and the amount is above 0.

    Install

    Standard Sokes Nodes 🦬 install - ComfyUI Manager → "ComfyUI Sokes Nodes" → Install, restart:

    cd ComfyUI/custom_nodes
    git clone https://github.com/m-sokes/ComfyUI-Sokes-Nodes.git
    pip install -r requirements.txt
    

    This is the one node that actually leans on the pack's heavier deps - it uses opencv-python for the fog's smoothed noise and Pillow for drawing. Nothing to download, but those need to be present, which the requirements file handles.

    Where it shines

    • Compositing backplates - generate a background, generate a subject, composite, and the description tells you (or the model) what the scene was.
    • Style consistency tests - seed a palette, lock minimal_colors, and sweep backgrounds to see which prompts hold up.
    • Feed the description into a T2I model - the node gives you a prompt that matches the image, which is a great way to test how well your model follows a generated scene.

    Gotcha to know: if the folder path for the alpha matte is wrong or empty, it silently proceeds without a matte - no crash, just no overlay. And num_shapes: 0 is the "clean background" button. Cheap, seedable, and it narrates its own work. What's not to like?

    CategorySokes 🦬/Generators

    Inputs (17)

    NameTypeDefaultDescription
    widthINT51264–4096—
    heightINT51264–4096—
    seedINT00–18446744073709550000—
    bg_typeCOMBO4 options: Random, Solid, Gradient, Fog
    bg_colorSTRING—
    compositionally_soundBOOLEANtrue—
    alpha_matte_folderSTRING—
    custom_alpha_colorSTRING—
    minimal_colorsBOOLEANfalse—
    num_shapesINT30–50—
    shape_color_modeCOMBO3 options: Any color, Neutral colors, Custom colors
    custom_shapes_colorsSTRING#FF00FF, #552288, 993322—
    noise_levelINT00–10—
    post_processingCOMBO9 options: Random, None, Blur, Pixelate, Brightness, Sharpen, +3
    post_processing_amountINT00–100—
    primary_colorSTRING#000000—
    secondary_colorSTRING#FFFFFF—

    Outputs (3)

    NameTypeDescription
    imageIMAGE—
    descriptionSTRING—
    alpha_matte_pathSTRING—