Technique

Pixel Sorting

Pixel sorting is a foundational glitch art technique where you algorithmically reorder pixels in an image to create smeared, melting, or crystalline distortions without adding new colors.

Pixel Sorting Example - Spiral Sort

Below is a concise, practice-focused guide to how it works, how to do it, and how to control it creatively.


What is pixel sorting?

Pixel sorting is an image-altering algorithm that takes pixels in an image and selectively reorders them along rows or columns based on some property, usually brightness (luminance), hue, or saturation.

Rather than replacing or generating pixels, the algorithm works only with the image’s existing colors: it shuffles their positions to create glitch aesthetics such as:

  • Vertical or horizontal “data melt” drips
  • Crystalline streaks that follow light or dark regions
  • Fragmented blocks that reveal image structure through ordered chaos

The technique was popularized in glitch art by Kim Asendorf, who released a Processing implementation that inspired many later tools.


How the pixel sorting algorithm works

Most pixel sorting implementations follow the same general structure.

1. Choose a direction

You decide whether to sort:

  • Horizontally: process each row as a 1D array of pixels
  • Vertically: process each column as a 1D array

Asendorf’s original code applies sorting twice, first vertically, then horizontally, for a more complex effect.

2. Define “intervals” to sort

Instead of sorting an entire row/column, you usually sort segments called intervals.

Typical process:

  1. Scan along the row or column.
  2. Use a rule to decide where an interval starts and ends, for example:
    • Pixels above a certain lightness threshold
    • Pixels below a certain darkness threshold
    • Edge-detected regions or masked areas

The edges of bright or dark regions in the source image often define interval boundaries.

3. Sort pixels inside each interval

For each interval, you:

  1. Extract its pixels as a list.
  2. Compute a property for each pixel, such as:
    • Luminance / value (common and intuitive)
    • Hue or saturation
    • Custom metrics (e.g. distance from a color, channel differences)
  3. Sort that list (ascending or descending) and write the pixels back into the same spatial interval.

The result: the structure of the intervals stays, but the internal ordering becomes smooth gradients or jagged bands depending on the metric and thresholds.


Creative techniques and variations

Once you understand the core loop (interval selection → sorting), you can push it in many directions.

1. Sorting criteria

  • Sort by brightness for classic “melting” drips and soft gradients.
  • Sort by hue to create rainbow-like streaks.
  • Sort by saturation to pull vivid colors apart from muted backgrounds.

You can invert the order (dark-to-light vs light-to-dark) to flip the visual flow.

2. Interval strategies

  • Threshold-based

    • Only sort pixels within a brightness range, leaving other regions intact.
    • Tighter thresholds = smaller, more fragmented glitches.
    • Looser thresholds = long, smeared streaks.
  • Mask-based

    • Use a black-and-white mask image to restrict sorting to selected areas (e.g. a subject’s face or sky).
  • Edge-aware

    • Build intervals based on edges or contrasts to emphasize outlines and structures.

3. Direction and layering

  • Apply only vertical sorting for waterfall-like drips.
  • Apply horizontal then vertical (or rotated directions) for cross-glitch textures.
  • Run multiple passes with different settings and blend results in an image editor.

Tools and workflows

You can approach pixel sorting via code or GUI-based tools.

Code-based approaches

  • Python scripts inspired by Asendorf’s Processing code or custom implementations that:
    • Load an image
    • Iterate rows/columns
    • Define intervals
    • Sort by luminance/hue etc.
  • Processing sketches using Asendorf’s original algorithm or derivatives.
  • Rust / creative coding libraries under development for open-source glitch tools.

These give you the most control over thresholds, masks, angles, and custom sort metrics.

GUI / non-code approaches

While “authentic” pixel sorting is algorithmic, you can approximate the look in image editors:

  • Photoshop: use selections plus filters like Wind to stretch pixels vertically, producing a pixel-sorting-like distortion.
  • Some glitch apps and plugins include a dedicated “pixel sort” or “data melt” effect built on similar logic.

These are useful for rapid experimentation or combining with more precise coded passes.


Practical tips for glitchologists

  • Choose source images with contrast. High-contrast scenes, bright highlights, and deep shadows give more interesting intervals and visible ordering.
  • Exploit thresholds. Treat upper/lower thresholds as your main “brush size” for glitch: tiny, scattered intervals vs long, continuous stripes.
  • Work non-destructively. Keep the original, and export different parameter sets; glitch art benefits from iteration and unexpected accidents.
  • Combine with masks. Use hand-painted or photographic masks to constrain glitches to faces, skies, or architectural lines for strong compositions.
  • Rotate the canvas. Run vertical sorting on a rotated image so you can get “diagonal” or unconventionally oriented drips when rotated back.
  • Layer and blend. Overlay multiple pixel-sorted versions with different blend modes and opacities for dense, nuanced textures.
  • Document your settings. For reproducible glitch practice, log sort metrics, thresholds, directions, and mask types for each piece.

Used intentionally, pixel sorting is less about random corruption and more about revealing hidden order in the image’s own color structure, turning raw pixel data into a controllable glitch aesthetic.