Skip to content

kanvolu/kquantizer

Repository files navigation

KQuantizer

KQuantizer is a very simple CLI color quantizer for images. It takes a path and a mode as required arguments and returns an image quantized with the desired mode. It works best with high contrast images that have a big focal object.

Currently, it has 5 modes:

  • search
  • equidistant
  • self
  • self-sort
  • bw

Search

Searches for the nearest color from the selected palette to each pixel of the image.

Equidistant

Quantizes each pixel to a band based on its brightness and then assigns a color from the palette to each band.

Self

Quantizes each channel to a band given the selected resolution, for example a resolution of 2 -r 2 will give a total of 8 bands since RGB is 3 channels.

Self-Sort

Similar to equidistant but creates a palette based on the brightness of the pixels in the input file.

BW

Quantizes each pixel to a band in greyscale based on brightness given the selected resolution.

Options and Flags

Not every mode supports all flags or options, here is the possible options that you can pass for each one:

  • All
    • -b Detect edges and blur everything except edges before processing, pass a radius for the blur.
    • -o Select the file output, if not passed the program will append mode and palette to the name of the file.
    • -q If the output file is in .jpg format you can pass a number between 1 and 100 to select the export quality, if not passed it will default to 80.
    • --print Print image to the console (only kitty protocol supported). It will prevent the image from being saved unless -o is also passed.
    • --dry Run the program without saving the output. Good for testing performance.
  • Search
    • -p Select palette, defaults to nord.
  • Equidistant
    • -p Select palette, defaults to nord.
  • Self
    • -r Select resolution of the quantization.
  • Self-Sort
    • -r Select resolution of the quantization.
  • BW
    • -r Select resolution of the quantization.

You can always see what options are available by passing -h without any other arguments.

Palettes

Currently, has only 3 palettes, but you can add your own since it sources them from the palettes.txt file that is located in ../palettes.txt. You can also move it to ~/.config/kquantizer/palettes.txt.

The syntax is quite simple, you denote a new palette with [] and then you just list your RGB values between 0 and 255. Here is an example:

[my_palette]
67 76 94
76 86 106
216 222	233
229	233	240

It will automatically detect the end of the palette, and it also supports comments as lines starting with #.

Installation

Currently, there is no way to install it in your system, however you can compile it and run it from its directory.

Dependencies to compile:

  • git
  • cmake
  • g++ (or your compiler of preference)

To download and compile:

git clone https://github.com/kanvolu/kquantizer.git
cd kquantizer/build
cmake -DCMAKE_BUILD_TYPE=Release ..
cmake --build .

And to execute it you have to cd to the directory that contains the executable, if you compiled the code yourself it will be kquantizer/build, and run

./KQuantizer <input> <mode> [OPTIONS]

As a workaround you can set up an alias to the path of the executable and copy palettes.txt to ~/.config/kquantizer/, that way you can access it from anywhere in your system. You can set it up without breaking anything this way:

cd kquantizer
ln palettes.txt ~/.config/kquantizer/palettes.txt

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published