Skip to main content

pixelsort

What is Pixel Sorting?

Have a look at this post or /r/pixelsorting

Dependencies

Should work in both Python 2 and 3, but Python 3 is recommended.

Usage

From the command line:

pip install pixelsort
python3 -m pixelsort %PathToImage% [options]

Tip: To replicate Kim Asendorf's original processing script, first sort vertically and then horizontally in threshold (default) mode:

python3 -m pixelsort %PathToImage% -a 90
python3 -m pixelsort %PathToSortedImage%

As a package:

>>> from pixelsort import pixelsort
>>> from PIL import Image
>>> a = Image.open("examples/image.jpg")
>>> a
<PIL.JpegImagePlugin.JpegImageFile image mode=RGB size=576x324 at 0x7F8F6A2AC208>
>>> pixelsort(a)
<PIL.Image.Image image mode=RGBA size=576x324 at 0x7F8F66AA57B8>

Parameters:

Parameter Flag Description
Interval function -i Controls how the intervals used for sorting are defined. See below for more details and examples. Threshold by default.
Output path -o Path of output file. Uses the current time for the file name by default.
Randomness -r What percentage of intervals not to sort. 0 by default.
Threshold (lower) -t How dark must a pixel be to be considered as a 'border' for sorting? Takes values from 0-1. 0.25 by default. Used in edges and threshold modes.
Threshold (upper) -u How bright must a pixel be to be considered as a 'border' for sorting? Takes values from 0-1. 0.8 by default. Used in threshold mode.
Char. length -c Characteristic length for the random width generator. Used in mode random and waves.
Angle -a Angle at which you're pixel sorting in degrees. 0 (horizontal) by default.
External interval file -f Image used to define intervals. Must be black and white.
Sorting function -s Sorting function to use for sorting the pixels. Lightness by default.
Mask -m Image used for masking parts of the image.
Logging level -l Level of logging statements made visible. Choices include DEBUG, INFO, WARNING, ERROR, and CRITICAL. WARNING by default.

Interval Functions

Interval function Description
random Randomly generate intervals. Distribution of widths is linear by default. Interval widths can be scaled using char_length.
edges Performs an edge detection, which is used to define intervals. Tweak threshold with threshold.
threshold Intervals defined by lightness thresholds; only pixels with a lightness between the upper and lower thresholds are sorted.
waves Intervals are waves of nearly uniform widths. Control width of waves with char_length.
file Intervals taken from another specified input image. Must be black and white, and the same size as the input image.
file-edges Intevals defined by performing edge detection on the file specified by -f. Must be the same size as the input image.
none Sort whole rows, only stopping at image borders.

Sorting Functions

Sorting function Description
lightness Sort by the lightness of a pixel according to a HSL representation.
hue Sort by the hue of a pixel according to a HSL representation.
saturation Sort by the saturation of a pixel according to a HSL representation.
intensity Sort by the intensity of a pixel, i.e. the sum of all the RGB values.
minimum Sort on the minimum RGB value of a pixel (either the R, G or B).

Examples

python3 -m pixelsort examples/image.jpg -i random -c 20

random

python3 -m pixelsort examples/image.jpg -i edges -t .5

edges

  • file: Intervals taken from image specified with -f. Must be black and white.

python3 -m pixelsort examples/image.jpg -i file -f examples/intervals.png

file

(generated with elementary-ca)

file

  • mask: Mask taken from image specified with -m. Must be black and white.

python3 -m pixelsort examples/image.jpg -i random -c 20 -m examples/mask.png

file

file

Todo

  • Allow defining different intervals for different channels.

Based on https://gist.github.com/prophetgoddess/667c5554e5d9d9a25ae6

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pixelsort-1.0.2.tar.gz (9.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pixelsort-1.0.2-py3-none-any.whl (10.4 kB view details)

Uploaded Python 3

File details

Details for the file pixelsort-1.0.2.tar.gz.

File metadata

  • Download URL: pixelsort-1.0.2.tar.gz
  • Upload date:
  • Size: 9.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for pixelsort-1.0.2.tar.gz
Algorithm Hash digest
SHA256 0143f861e501eb6edb758840beb3cb599117de333417a8b37ba8465eefc7fbbe
MD5 e5ffd8cebf9815cc7e3e4335ead09245
BLAKE2b-256 b7c2b292db978be0da4bd42088e20326acae4949e3ef68e07eb1274abe5df4b8

See more details on using hashes here.

Provenance

The following attestation bundles were made for pixelsort-1.0.2.tar.gz:

Publisher: publish.yml on satyarth/pixelsort

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pixelsort-1.0.2-py3-none-any.whl.

File metadata

  • Download URL: pixelsort-1.0.2-py3-none-any.whl
  • Upload date:
  • Size: 10.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for pixelsort-1.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 28ee83a3674fd1e88d5b28ff51a9855fb57b02492e5d7de713e8a2dd2877e7a6
MD5 7e402845d91b1b997ac406954cb77802
BLAKE2b-256 f9323d88f43e0f1640191316ac1100251c26dee3927d83338df93e3397e979e3

See more details on using hashes here.

Provenance

The following attestation bundles were made for pixelsort-1.0.2-py3-none-any.whl:

Publisher: publish.yml on satyarth/pixelsort

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

1.0.2 This release

2 files

1.0.1

2 files

1.0.0

2 files

0.0.10

1 file

0.0.1

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page