Nodes/Mosaica/Random LUT
ComfyUI Node

Random LUT

The 'I'll roll the dice on a palette' node

By Mason-McGough·Created 2 years ago·Updated 2 years ago· 6
Random LUT
    • IMAGE
    num_rows256

    Random LUT is the most honest node in the Mosaica pack: it generates a random palette of RGB colors and outputs it as a lookup table. That's the entire feature. It exists because sometimes a mosaic recolor looks better when the palette is a surprise - you don't want k-means' boring cluster averages or a scientific colormap, you want whatever chaos the random number generator serves up, and you'll re-roll until one lands right.

    It's a utility node in a niche pack, so expectations should be calibrated: one input, one output, no cleverness. But it fills a real slot in the label-image pipeline.

    How it works

    The mechanism is one line of PyTorch: torch.rand((num_rows, 3)). Each row is a random RGB color with channels in the 0–1 range, and the output is that 2D table - num_rows rows by 3 columns. There's no correlation between colors, no perceptual balancing, no attempt to make the palette pretty. It's uniform random noise, straight up.

    The single input is num_rows (default 256, 1–4096). This is the number of colors in the LUT - i.e., the number of distinct labels it can color. In practice you rarely need more than a few dozen, but the default 256 matches what you'd get from a matplotlib colormap, so a RandomLUT and a LoadLUTFromMatplotlib drop into the same socket interchangeably.

    Wiring it in

    The LUT output plugs into Apply LUT To Label Image alongside a label_image from one of the Analyze nodes:

    KMeanslabel_imageApplyLUTToLabelImageRandomLUTlut.

    Watch the label-count math: a random LUT has as many rows as you asked for, so if your label map has more distinct labels than rows, indexing will run off the end. Enable scale_labels_to_lut_range on the apply node to stretch labels onto the LUT's range, or just raise num_rows.

    The gotcha the author will tell you about

    RandomLUT has no seed input. Re-running the workflow with the same settings produces a different random palette every time. If you find a palette you love, you can't reproduce it - save the output image, because you won't be able to regenerate it exactly.

    The pack's own TODO list knows about this. It's the reason for two planned improvements: a random-seed option, and switching to LAB color space so random palettes are more perceptually uniform instead of occasionally vomit-green. Neither has landed yet, so what you get is what the code ships: fully random RGB, and sometimes that means a palette only a synthetic person could love. That's kind of the point - roll, look, re-roll.

    Install

    Identical to the rest of the pack:

    cd ComfyUI/custom_nodes
    git clone https://github.com/Mason-McGough/ComfyUI-Mosaica
    

    restart, or search "Mosaica" in ComfyUI Manager. Dependencies are scikit-learn, opencv-python, and matplotlib - CPU-side, no models. RandomLUT itself only needs torch and numpy, which you already have.

    If you like curated palettes, use LoadLUTFromMatplotlib instead and skip the dice. If you want a happy accident every now and then, this is the node.

    CategoryMosaica/LUT

    Inputs (1)

    NameTypeDefaultDescription
    num_rowsINT2561–4096

    Outputs (1)

    NameTypeDescription
    IMAGEIMAGE