appalette · affinity propagation on an image's colors

Keep a few colors, gray the rest

The colors of the image are clustered by affinity propagation, comparing them with the CIEDE2000 color difference. Each cluster is represented by an exemplar, a color taken from the image. Choose which exemplars keep their colors; every other pixel turns gray. Press and hold the image to see the original.

Hold to compare

Kept colors

Palettes bar: how long it holds

    One row per number of colors. The bar is the range of preferences over which affinity propagation keeps finding that many exemplars; the three widest with 3 or more colors, in blue, are the image's most stable palettes (2 colors almost always holds longest, so it is left out).

    Preference sweep

    Each dot is one run. The preference is what a color must "pay" to become an exemplar: raising it towards 0 gives more colors. Click a dot to see its palette.

    Settings

    every color counts oncecolors weigh by area

    In ΔE00 units: colors close to both a kept and a gray exemplar are blended.

    How it works
    1. The pixels are binned at 5 bits per channel, and the bins are cut into at most 256 colors by a median cut in CIELAB.
    2. The similarity of color i to color k is minus their CIEDE2000 difference, scaled by how many pixels i covers (to the power set by Area or variety). The CIEDE2000 code is the one in chroma.
    3. Affinity propagation (naffprop's Nim code, damping 0.9) runs for preferences from the one that gives a single exemplar upwards, each 10% closer to 0, until there are more than 24 exemplars.
    4. A palette is stable when the same number of exemplars comes back over a wide range of preferences.
    5. Each pixel keeps its color when its cluster's exemplar is kept; otherwise it becomes the gray of the same luminance.

    Everything runs in this page: the clustering is Nim compiled to JavaScript, and your own images never leave the browser.