[go: nahoru, domu]

Skip to content

Apply tricolor posterization to images with specified colors

License

Notifications You must be signed in to change notification settings

rdancer/tricolor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Tricolor

Apply tricolor posterization to images with specified colours.

Colours in colors.txt shamelessly stolen from (accessed 2024-10-22) https://webflow.com/blog/best-color-combinations

Examples

More examples in examples/

Lena Lego Starry Night

Installation

$ pip install -r requirements.txt

Usage

$ python3 tricolor.py --help
positional arguments:
  images         Paths to input image files.

options:
  -h, --help     show this help message and exit
  --color COLOR  Hex color code (e.g., 0x1E2761). Specify exactly three times.
  --plot         If set, generates a plot with the original, tricolor image, and color swatches.

Normal usage

$ python3 tricolor.py test/Lena.jpeg --color 0xFF0000 --color 0xFFFFFF --color 0x0000FF
Saved: Lena_0xFF0000_0xFFFFFF_0x0000FF.png

Produce test images in all the colour combinations from test/colors.txt

$ ./test/tricolor_test.sh
Saved: Lego_0x1E2761_0x408EC6_0x7A2048.png
Saved plot: Lego_plot_0x1E2761_0x408EC6_0x7A2048.png
Saved: Lena_0x1E2761_0x408EC6_0x7A2048.png
Saved plot: Lena_plot_0x1E2761_0x408EC6_0x7A2048.png
Saved: Starry_Night_0x1E2761_0x408EC6_0x7A2048.png
Saved plot: Starry_Night_plot_0x1E2761_0x408EC6_0x7A2048.png
...

Colour theory

Colour sorting

I don't know much about colour theory, so it has surprised me that there is only one correct way to order the palette (top left in the above picture). I expected the results of different orderings to be slightly off, or even interesting, but no, they look downright wrong and unappealing. We divide the image into dark, mid, and light regions, and likewise always reorder the user-supplied palette from dark to bright.

Note on spelling

We use American English (in particular, "color") in code. In comments and documentation, it matters not (I prefer to use British English --rdancer).

About

Apply tricolor posterization to images with specified colors

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published