Color Quantizer and Clustering
This function block reduces the number of distinct colors in an image by grouping similar colors into clusters. It is useful to simplify color information for visualization, segmentation, or to speed up subsequent processing steps.
π₯ Inputs
Image AnyImage to be quantized and clustered.
π€ Outputs
Image AnyImage with reduced color palette (quantized result).Clustered Colors (B,G,R)List of cluster color values representing the palette found (one color per cluster).
πΉοΈ Controls
K CoefficientSlider β Choose how many color clusters the block will compute. Lower values produce fewer colors, higher values preserve more color detail.
π¨ Features
Color palette reduction for easier visual inspection or downstream processing.
Returns both the processed image and the resulting color palette so you can reuse the palette for annotation, visualization, or comparison.
Fast clustering suitable for interactive tuning via the slider.
βοΈ Running mechanism
When active, the block examines the input image, groups similar colors into K clusters (as set by
K Coefficient) and replaces each pixel with its cluster color.The quantized image and the list of cluster colors are produced as outputs so you can preview and use the palette in other blocks.
π How to use
Connect an image-producing block to the
Image Anyinput.Move the
K Coefficientslider to select the number of color clusters you want.Observe the quantized image from the
Image Anyoutput and inspect the cluster list from theClustered Colors (B,G,R)output.
π‘ Tips and Tricks
For large images, use
Image Resizerbefore this block to speed up processing while keeping representative colors.If the image is noisy, add a small
Blurblock upstream to stabilize clustering results.To visualize the result at full size, connect the output to
Show Image.If you want to analyze or compare individual channels, use
Split Imagebefore clustering orColor Spaceconversions to adjust color interpretation.Use
Image LoggerorImage Writeafter this block to save quantized images for later review.To enhance color contrast before quantization, try
Auto ContrastorContrast Optimizationupstream.
π οΈ Troubleshooting
If the output looks overly posterized or loses important detail, increase
K Coefficient.If clustering is too slow on large images, reduce image size with
Image Resizeror lower theK Coefficient.If colors do not match expectations (e.g., due to color space), add a
Color Spaceblock to convert between BGR/RGB or other spaces before clustering.
Last updated