This is a Python script that sorts the pixels in an image. It implements Quicksort as its sorting algorithm. I wrote it as part of my algorithm class in university. The program requires a recent version of Python 3.
- Create a new environment using venv:
python -m venv venv
- Activate the environment:
Linux:Windows (PowerShell)source venv/bin/activate
.\venv\Scripts\activate.ps1
- Install requirements:
pip install -r requirements.txt
To use this script, you have to provide it with a source and destination filename:
python main.py source_file.jpg destination_file.jpg
By default, the scripts sorts each row of pixels by luminance. The script has been verified to work with JPEG and PNG. For a list of supported file formats, take a look at the Pillow image library wiki. Please note: Sorting a high-resolution image can take a long time, especially sorting it continuously.
The original image:
Each row sorted by luminance:
Each column sorted by luminance:
The whole image sorted by luminance continuously:
Each row sorted by the red value:
Argument | Values | Default | Explanation |
---|---|---|---|
--sort |
rows , columns , continuously |
rows |
Specifies how the image will be sorted. You can sort each row, each column or sort the image continuously. |
--sort-by |
red , green , blue , luminance |
luminance |
Specifies which value will be the sorting key. |