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 Any Image to be quantized and clustered.

πŸ“€ Outputs

  • Image Any Image 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 Coefficient Slider β€” 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

  1. Connect an image-producing block to the Image Any input.

  2. Move the K Coefficient slider to select the number of color clusters you want.

  3. Observe the quantized image from the Image Any output and inspect the cluster list from the Clustered Colors (B,G,R) output.

πŸ’‘ Tips and Tricks

  • For large images, use Image Resizer before this block to speed up processing while keeping representative colors.

  • If the image is noisy, add a small Blur block 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 Image before clustering or Color Space conversions to adjust color interpretation.

  • Use Image Logger or Image Write after this block to save quantized images for later review.

  • To enhance color contrast before quantization, try Auto Contrast or Contrast Optimization upstream.

πŸ› οΈ 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 Resizer or lower the K Coefficient.

  • If colors do not match expectations (e.g., due to color space), add a Color Space block to convert between BGR/RGB or other spaces before clustering.

Last updated