Nodes/ComfyUI_BadgerTools/GetColorFromBorder-badger
ComfyUI Node

GetColorFromBorder-badger

Read the border color of an image and hand it back as a hex string

By AbyssBadger0·Created 3 years ago·Updated 2 years ago· 8
GetColorFromBorder-badger
  • image
  • STRING
detection_width1
classification_threshold10

Lots of generated images come out with a border you didn't ask for - a matte frame, letterbox bars, a solid background bleed around a subject. If you want to do something about that border, the first step is knowing its color. GetColorFromBorder-badger samples the outer edge of an image and returns the dominant border color as a hex string like #2a2a2a. It's the "what color is the frame?" node, and it feeds the rest of this pack's color chain.

The useful thing about the hex output is that it plugs straight into the pack's other color nodes. Loop it into IdentifyColorToMask-badger and you get a mask of exactly that border region - which you can then inpaint out or use to keep the border during an outpaint. Or feed it to ExpandImageWithColor-badger to recreate a matching frame on a differently-sized image. Hex in, hex out, the pack is internally consistent that way.

How it works

The node scans each row of the image from both edges inward, collecting the first detection_width opaque pixels it hits per side, plus the same for columns. Then it groups all those sampled colors by fuzzy similarity and returns the average color of the largest group. Two things are doing real work here:

  • detection_width (INT, default 1) - how many pixels in from the edge to sample. At 1 you're reading only the outermost pixel ring; bump it to 3–5 if the very edge is noisy or has a stray anti-aliased pixel.
  • classification_threshold (INT, default 10) - how close two colors must be to count as "the same." Too low and every shade is its own group (the winner becomes the most common exact-ish color); too high and the border and the subject blur together into one average.

It only counts non-transparent pixels (alpha != 0), so a transparent frame reads as "no data" for that spot rather than black.

Inputs and outputs

  • image - the IMAGE to inspect.
  • detection_width - border sample depth.
  • classification_threshold - color-grouping fuzziness.

One output: a STRING, the hex color, e.g. #ffffff.

Installing it

From ComfyUI_BadgerTools: ComfyUI Manager → search "BadgerTools" → install, or

cd ComfyUI/custom_nodes
git clone https://github.com/AbyssYuan0/ComfyUI_BadgerTools

Restart afterwards. No model downloads. Standard pack note: heavy requirements import at startup even for this Pillow-only node.

Gotchas

  • A busy edge defeats the average. If the border is a gradient or has watermarks, the "largest group" is still just the most common sampled color - check what you're sampling.
  • Threshold tuning is the whole game. With a clean solid border, default values (1 / 10) return the right answer on the first try. With anything textured, expect to raise detection_width first and only then touch the threshold.
  • Transparent edges are skipped, so a transparency-bordered image returns the color of the visible content near the edge instead.

There's no community lore for this node - it's a small personal-pack utility. But the chain it enables (border → color → mask → inpaint) is a genuinely tidy way to scrub letterbox bars out of generations, and the node is the quiet first step of it.

Categorybadger

Inputs (3)

NameTypeDefaultDescription
imageIMAGE
detection_widthINT11–4096
classification_thresholdINT101–4096

Outputs (1)

NameTypeDescription
STRINGSTRING