neversettle7 / image-color-sorter

A little Python software that creates a color-sorted image from any image

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Image color sorter

What does this program do?

Basically, it gets an image as input, then outputs the same image with his pixels sorted by color. There are gonna be more informations about the algorithms used at the end of this page.

Examples

Original image:

Alt text

Output with hue sorting:

Alt text

Output with hsp:

Alt text

Output with relative luminance:

Alt text

Output with rgb sorting (red):

Alt text

Output with HSL sorting:

Alt text

Why did you decide to develop this (in)utility?

I wanted to learn Python development and I just kinda leaned towards this little idea that I had in mind for a long time.

How do I get this stuff running?

Assuming you don't have Python already installed (especially if you're on windows), go grab it at Python official site.

Note that this project requires Python 3.

Go ahead with the installation, then open a prompt window and type

$ pip install Pillow

This will install Pillow (Python Imaging Library), which is the library I'm currently using to work on images.

Looks like you're set!

Now go to the folder where you downloaded my software using your prompt window/terminal and type:

$ python pixelsorter.py

If you have Python 2 and Python 3 installed at the same time you should probably type:

$ python3 pixelsorter.py

Have fun!

Your code sucks, bro.

Yes, I already know that. It's gonna be full of errors and poor-optimized code, but this is my first Python project, so take it easy.

Algorithms used

Hue sorting

Based on the HSV color representation where the color are expressed by cylindrical-coordinates. The three values of HSV are hue, saturation and value. This algorithm sorts the colors by ordering the pixels based on their hue values. Read the linked Wikipedia article to get to know more.

Perceived brightness - HSP color model

Based on the HSP color model, which is an alternative to HSV. The red, green and blue values from the RGB model are multiplied by three costants which represent the different degrees to which each of the primary (RGB) colors affects human perception of the overall brightness of a color. The linked article is a very interesting read on the subject.

Relative luminance

The relative luminance is a value to get the luminance of a color. Again, we get the RGB values and multiply them by three costants. Note that the three constants are, like in the HSP model, based on the luminosity function: the green value is more important because contributes the most to how the intensity is perceived by the human eye (then red and blue).

Red scale - RGB model

This is a very simple algorithm (which is not really effective, but I originally wrote it for testing purposes then decided to leave it there as a simple demonstration) sorting the colors based on the first value of the RGB model (red intensity).

HSL sorting

This algorithm is based on this Stack Overflow question. I hadn't tried an HSL algorithm before, so I figured I'd give it a shot. The pixels are sorted based on different weights assigned to the values of the HSL model.

Additional resources

Having zero experience in Python and color theory these are the resources I mainly used to gather informations, in addition to the sources I've already linked previously, if you're interested in knowing more.

About

A little Python software that creates a color-sorted image from any image

License:GNU General Public License v3.0


Languages

Language:Python 100.0%