Display the sorting process of different sorting algorithms on image pixels
Six sorting algorithms:
- bubble sort
- selection sort
- insertion sort
- quick sort
- merge sort
- heap sort
Dependencies: numpy, opencv-python, matplotlib
git clone https://github.com/Matoi647/pixel-sort.git
cd ./pixel-sort
pip install -r requirements.txt
# realtime display with matplotlib
pyhton pixel-sort.py [image path] [arguments]
# save video
pyhton video.py [image path] [arguments]
some arguments:
Parameter | Type | Default | Description |
---|---|---|---|
--resolution |
int | 360 | Resample image to given resolution (image height) |
--algorithm |
str | bubble | Sorting algorithm to apply. Choices: bubble, selection, insertion, quick, merge, heap |
--interval |
int | 10 | Time interval between two frames (in milliseconds). |
--step |
int | 1 | Number of pixels swapped per frame. |
--sort_by_col |
boolean | False | Sort by column instead of row. |
--split_rgb |
boolean | False | Split image into RGB channels and sort each channel separately. |
--reverse |
boolean | False | Sort pixel values in descending order. |
python pixel-sort.py "assets\StarryNight.jpg" --algorithm bubble --sort_by_col --step 10 --reverse
python pixel-sort.py "assets\StarryNight.jpg" --algorithm selection --reverse
python pixel-sort.py "assets\StarryNight.jpg" --algorithm insertion --step 10
python pixel-sort.py "assets\StarryNight.jpg" --algorithm quick
python pixel-sort.py "assets\StarryNight.jpg" --algorithm merge
python pixel-sort.py "assets\StarryNight.jpg" --algorithm heap