Nodes/comfyui_cv/CV Color Range From Sample
ComfyUI Node

CV Color Range From Sample

Learns a colour band from the image itself: it samples the pixels (inside `region` if given, else the whole image), takes their per-channel center and spread, and keeps everything within `sigma` * spread of that center. Spread is the standard deviation for linear channels and the CIRCULAR standard deviation for a hue channel (set via `format`), so a reddish sample straddling the 179/0 seam is measured correctly. Seed `region` with a scribble or the polygon mask of 'CV Annotate Points' over the colour you want. Outputs the mask plus the derived `center` and `tolerance` (feed them to 'CV Color Range' to reuse the band on another image, or inspect them).

By bmad4ever·Created 3 months ago·Updated 2 days ago· 0
CV Color Range From Sample
  • image
  • region
  • mask
  • center
  • tolerance
sigma2.5
formatlinear - no circular channel (BGR/RGB/Lab/Luv/YCrCb/gray)
Categoryimage/CV/segmentation

Inputs (4)

NameTypeDefaultDescription
imageNPARRAY,IMAGEColour array to sample and threshold (set 'format' to match its colour space). A ComfyUI IMAGE arrives as BGR uint8. Accepts a ComfyUI IMAGE/MASK directly (frame 0 of a batch) or an NPARRAY. Arithmetic ops (add, multiply, etc.) process the full IMAGE batch when both inputs have the same batch size.
sigmaFLOAT2.50–20Band half-width in standard deviations: tolerance = sigma * spread per channel. ~2-3 keeps most of a normally-distributed colour; raise to be more permissive.
formatCOMBOlinear - no circular channel (BGR/RGB/Lab/Luv/YCrCb/gray)Which channel (if any) is a circular hue, and its period. The hue center/spread are then computed circularly.
regionoptNPARRAY,MASKMask marking which pixels to sample (non-zero = sample). The polygon output of 'CV Annotate Points' plugs in directly. Omit to sample the whole image. Accepts a ComfyUI IMAGE/MASK directly (frame 0 of a batch) or an NPARRAY. Arithmetic ops (add, multiply, etc.) process the full IMAGE batch when both inputs have the same batch size.

Outputs (3)

NameTypeDescription
maskNPARRAYuint8 0/255 mask of the in-range pixels.
centerNPARRAYPer-channel sampled center (circular mean for the hue channel) - float64, one element per channel.
toleranceNPARRAYPer-channel sigma * spread used for the band - feed it and 'center' into 'CV Color Range'.