Back

Pixel sorting

Implementing Kjetil Golid pixel/color sorting.

For every pixel in the image, compute the average color of the current pixel's surrounding pixels. Within a maximum number of tries, find a different non-processed pixel with the most similar color to the computed average and swap them.

sRGB is not the best color space for a color difference function. I converted the colors to Oklab .

The orientation and result of this effect is a combination of:

  • The algorithm processes pixels from top to bottom. This is not a requirement. I've seen vastly cooler versions, such as a radial one and a seemingly noise-based one.
  • Which and how many of the 8 surrounding pixels are being used to compute the color difference. In this demo, I'm using the top-left, top, and left pixels.
Pixel Sorting
1 100