Playing With Pixel Sorting

September 21, 2020

A few years back I wrote a small program to “pixel sort”, or rearrange the pixels of an image to create surreal distortions. This is a photo of a dancer, taken when I was in college:

Dancer distorted with pixel sorting

The program produces this result by sorting each row of pixels in an image. First, a “weight” is assigned to each pixel, then the row is sorted by that weight.

The “weight” is a combination of a pixel’s brightness, as well as its position within the row. By including a pixel’s position in its weight calculation, we can keep pixels from straying too far from home.

pixel weight = brightness + (position in row * sort strength)

I result, I think, is beautiful!