Skip to content

Instantly share code, notes, and snippets.

@softworkz
Created September 24, 2021 23:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save softworkz/deef5c2a43d3d629c3e17f9e21544a8f to your computer and use it in GitHub Desktop.
Save softworkz/deef5c2a43d3d629c3e17f9e21544a8f to your computer and use it in GitHub Desktop.
Color Palette Quantization in Photoshop

Here's an example regarding the image color quantization I've been talking about.

This is an original subtitle bitmap having a palette of 4 or 5 colors:

@softworkz
Copy link
Author

softworkz commented Sep 24, 2021

image

Now we convert it to RGBA for scaling to 58%.

The result is this:

image

Magnified to 200%:

image

Now, the task is to reduce the amount of discrete colors as much as possible while keeping the quality of appearance.

This is something that Photoshop can do very well:

image

The image is reduced to only 8 palette colors and it's still looking fine

The palettization can be controlled in several ways and the results are pretty good, even with a small number of colors.
It looks easy when working with PS, but choosing the right set of colors and properly replacing them in the image, while retaining borders and blending smoothly - that's not as easy as it seems. A basic implementation and logic can be implemented quickly, but it probably won't provide results at a similar level of quality. Though, I haven't tried yet.

@softworkz
Copy link
Author

softworkz commented Sep 25, 2021

Palettized via palettegen and palleteuse (8 colors max):

paltest3

Palettized via Photoshop (8 colors max):

image

Palettized via palettegen and palleteuse after adding alpha support (8 colors max):

image

via elbg with the new alpha patch

image

via palettegen and palleteuse (8 colors max): - 200% magnified

image

Palettized via Photoshop max):: - 200% magnified

image

via palettegen and palleteuse after adding alpha support (8 colors max): - 200% magnified

image

via elbg with the new alpha patch

image

@softworkz
Copy link
Author

Rainbow Ring

Original (from 32bpp PNG)

fate-suite\apng\o_sample.png

Original

o_sample1

400%

image

All following images are zoomed to 400% and taken as screenshots from Photoshop

Photoshop (to 8-bit alpha palette)

image

PngQuant (to 8-bit alpha palette)

image

Paletteuse/gen Regular (to 8-bit non-alpha palette; only single transparent color)

ffmpeg -y -loglevel verbose -i "fate-suite\apng\o_sample.png" -filter_complex "split[split1][split2];[split1]palettegen=max_colors=255:use_alpha=1[pal1];[split2][pal1]paletteuse=use_alpha=1" -frames:v 1 out.png

image

Paletteuse/gen New Alpha-Patch (to 8-bit alpha palette)

ffmpeg -y -loglevel verbose -i "fate-suite\apng\o_sample.png" -filter_complex "split[split1][split2];[split1]palettegen=max_colors=255[pal1];[split2][pal1]paletteuse" -frames:v 1 out.png

image

@softworkz
Copy link
Author

ELBG Filter (to 8-bit alpha palette)

ffmpeg -y -loglevel verbose -i "..\fate-suite\apng\o_sample.png" -filter_complex "elbg=pal8=1" -frames:v 1 out.png

image

ELBG with new Alpha-Patch (to 8-bit alpha palette)

ffmpeg -y -loglevel verbose -i "..\fate-suite\apng\o_sample.png" -filter_complex "elbg=pal8=1:use_alpha=1" -frames:v 1 out.png

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment