Blazingly fast interpolated LUT generator and applicator for arbitrary and popular color palettes.

Overview

lutgen-rs

crate aur license ci publish

A blazingly fast interpolated LUT generator and applicator for arbitrary and popular color palettes. Theme any image to your dekstop colorscheme!


Example

Catppuccin Mocha Hald Clut
Example Image (Original)
Example Image (Corrected)

Usage

Note: The binary and library are still in a fairly experimental state, and breaking changes are made quite often. Any release that does make any changes as such, are bumped to 0.X.0

CLI

Install

  • Crates.io (source):
    cargo install lutgen
  • AUR:
    yay -S lutgen-bin

Helptext

A blazingly fast interpolated LUT generator and applicator for arbitrary and popular color palettes.

Usage: lutgen [OPTIONS] [CUSTOM_COLORS]... [COMMAND]

Commands:
  apply  Correct an image using a hald clut, either generating it, or loading it externally
  help   Print this message or the help of the given subcommand(s)

Arguments:
  [CUSTOM_COLORS]...  Custom hexidecimal colors to add to the palette. If `-p` is not used to specify a base palette, at least 1 color is required

Options:
  -o, --output <OUTPUT>          Path to write output to
  -p, --palette <PALETTE>        Predefined popular color palettes. Use `lutgen -p` to view all options. Compatible with custom colors
  -l, --level <LEVEL>            Hald level (ex: 8 = 512x512 image) [default: 8]
  -a, --algorithm <ALGORITHM>    Algorithm to remap the LUT with [default: gaussian-rbf] [possible values: shepards-method, gaussian-rbf, linear-rbf, gaussian-sampling, nearest-neighbor]
  -n, --nearest <NEAREST>        Number of nearest palette colors to consider at any given time for RBF based algorithms. 0 uses unlimited (all) colors [default: 16]
  -s, --shape <SHAPE>            Gaussian RBF's shape parameter. Higher means less gradient between colors, lower mean more [default: 96]
      --power <POWER>            Shepard algorithm's power parameter [default: 4]
  -m, --mean <MEAN>              Gaussian sampling algorithm's mean parameter [default: 0]
      --std-dev <STD_DEV>        Gaussian sampling algorithm's standard deviation parameter [default: 20]
  -i, --iterations <ITERATIONS>  Gaussian sampling algorithm's target number of samples to take for each color [default: 512]
  -h, --help                     Print help (see more with '--help')
  -V, --version                  Print version

Examples

Generating a LUT

lutgen -p catppuccin-mocha -o mocha_lut.png

Correcting an image with a LUT generated on the fly

lutgen -p catppuccin-mocha apply assets/simon-berger-unsplash.jpg -o mocha_version.png

Correcting an image with a pre-generated LUT

lutgen apply --hald-clut mocha_lut.png input.jpg

Correcting Videos (using ffmpeg):

ffmpeg -i input.mkv -i hald_clut.png -filter_complex '[0][1] haldclut' output.mp4

Library

By default, the bin feature and dependencies are enabled. When used as a library, it's recommended to use default-features = false to minimalize the dependency tree and build time.

Generating a LUT (simple):

use exoquant::SimpleColorSpace;
use lutgen::{
    GenerateLut,
    interpolation::{
        GaussianRemapper, GaussianSamplingRemapper
    },
};
use lutgen_palettes::Palette;

// Get a premade palette
let palette = Palette::CatppuccinMocha.get();

// Setup the fast Gaussian RBF algorithm
let (shape, nearest) = (96.0, 0);
let remapper = GaussianRemapper::new(&palette, shape, nearest);

// Generate and remap a HALD:8 for the provided palette
let hald_clut = remapper.generate_lut(8);

// hald_clut.save("output.png").unwrap();

// Setup another palette to interpolate from, with custom colors
let palette = vec![
    [255, 0, 0],
    [0, 255, 0],
    [0, 0, 255],
];

// Setup the slower Gaussian Sampling algorithm
let (mean, std_dev, iters, seed) = (0.0, 20.0, 512, 420);
let remapper = GaussianSamplingRemapper::new(
    &palette, 
    mean, 
    std_dev, 
    iters, 
    seed, 
    SimpleColorSpace::default()
);

// Generate and remap a HALD:4 for the provided palette
let hald_clut = remapper.generate_lut(4);

// hald_clut.save("output.png").unwrap();

Applying a LUT:

use image::open;

use lutgen::{
    identity::correct_image,
    interpolation::GaussianRemapper,
    GenerateLut,
};
use lutgen_palettes::Palette;

// Generate a hald clut
let palette = Palette::CatppuccinMocha.get();
let remapper = GaussianRemapper::new(&palette, 96.0, 0);
let hald_clut = remapper.generate_lut(8);

// Save the LUT for later
hald_clut.save("docs/catppuccin-mocha-hald-clut.png").unwrap();

// Open an image to correct
let mut external_image = open("docs/example-image.jpg").unwrap().to_rgb8();

// Correct the image using the hald clut we generated
correct_image(&mut external_image, &hald_clut);

// Save the edited image
external_image.save("docs/catppuccin-mocha.jpg").unwrap()

Remapping an image directly (advanced):

Note: While the remappers can be used directly on an image, it's much faster to remap a LUT and correct an image with that.

use lutgen::{
    GenerateLut,
    interpolation::{GaussianRemapper, InterpolatedRemapper},
};

// Setup the palette to interpolate from
let palette = vec![
    [255, 0, 0],
    [0, 255, 0],
    [0, 0, 255],
];

// Setup a remapper
let (shape, nearest) = (96.0, 0);
let remapper = GaussianRemapper::new(&palette, shape, nearest);

// Generate an image (generally an identity lut to use on other images)
let mut hald_clut = lutgen::identity::generate(8);

// Remap the image
remapper.remap_image(&mut hald_clut);

// hald_clut.save("output.png").unwrap();

Tasks

  • Basic hald-clut identity generation
  • Gaussian Sampling interpolation for generating LUTs (thanks Gengeh for the original imagemagick strategy!)
  • Support a bunch of popular base color palettes (thanks Wezterm!)
  • Basic applying a lut to an image
  • Radial basis function interpolation for generating LUTs
  • Interpolation for more accuracy when correcting with low level luts (<16)
  • Replace exoquant and kiddo with a unified implementation of a k-d tree

Sources

You might also like...
Bonk - The blazingly fast touch alternative written in rust
Bonk - The blazingly fast touch alternative written in rust

Bonk The blazingly fast touch alternative written in rust. Made for the sole purpose to create files. Explore the docs » View Demo · Report Bug · Requ

Print your git contributions in your terminal, blazingly fast
Print your git contributions in your terminal, blazingly fast

Takoyaki Blazingly fast git contribution graph in your terminal Features ✔️ Customizable ✔️ Plugins to support a bunch of cloud based git repositories

Blazingly fast Rust CLI app to sync data from a folder of excel workbooks into generated c# code for unity usage
Blazingly fast Rust CLI app to sync data from a folder of excel workbooks into generated c# code for unity usage

Extensions supported ( .xls, .xlsx, .xlsm, .xlsb, .xla, .xlam, .ods ) Speed Test Image shows the results of 5000defs synced from 2 workbooks and 5 she

A blazingly fast & lightweight Obsidian CLI ⚡️
A blazingly fast & lightweight Obsidian CLI ⚡️

obs - the Obsidian CLI ⚡️ Connecting your second brain to the termainl - blazing fast ⚡️ Note 🚧 obs is under active development and currently only su

Get your github contributions right in your terminal, blazingly fast!
Get your github contributions right in your terminal, blazingly fast!

GitColorScripts Get your github contributions right in your terminal! Installation Install via yay yay -S gitcolorscripts Install manually Download t

A library that allows for the arbitrary inspection and manipulation of the memory and code of a process on a Linux system.
A library that allows for the arbitrary inspection and manipulation of the memory and code of a process on a Linux system.

raminspect raminspect is a crate that allows for the inspection and manipulation of the memory and code of a running process on a Linux system. It pro

Traversal of tree-sitter Trees and any arbitrary tree with a TreeCursor-like interface

tree-sitter-traversal Traversal of tree-sitter Trees and any arbitrary tree with a TreeCursor-like interface. Using cursors, iteration over the tree c

AI-TOML Workflow Specification (aiTWS), a comprehensive and flexible specification for defining arbitrary Ai centric workflows.

AI-TOML Workflow Specification (aiTWS) The AI-TOML Workflow Specification (aiTWS) is a flexible and extensible specification for defining arbitrary wo

Encode and decode dynamically constructed values of arbitrary shapes to/from SCALE bytes

scale-value · This crate provides a Value type, which is a runtime representation that is compatible with scale_info::TypeDef. It somewhat analogous t

Releases(v0.6.1)
  • v0.6.1(Jun 15, 2023)

  • v0.6.0(Jun 15, 2023)

    RBF Based algorithms now operate within the Oklab colorspace. This is a much better perceptual colorspace that is really good for gradients between colors, and produces very consistent results in terms of luminosity and other perceptual factors.

    Breaking Changes

    • RBFRemapper and it's associated algorithm types no longer accept a generic exoquant colorspace
    • CLI argument euclide was renamed to shape for GaussianRBF

    Full Changelog: https://github.com/ozwaldorf/lutgen-rs/compare/v0.5.0...v0.6.0

    Source code(tar.gz)
    Source code(zip)
  • v0.5.0(Jun 13, 2023)

    New additions:

    • New RBF interpolation algorithms
      • Shepard's method (inverse distance weighting)
      • Gaussian RBF
      • Linear (1/distance) RBF

    Breaking changes:

    • interpolated_remap module is renamed to interpolation
    • lutgen::generate_lut<A> generic function has been moved into the new GenerateLut trait
    • InterpolatedRemapper trait no longer contains a new constructor or associated type Params; each implementation provides their own new function
    • GaussianV0 struct has been removed, the V1 implementation produces identical results now
    • GaussianV1 struct has been renamed to GaussianSampling

    Full Changelog: https://github.com/ozwaldorf/lutgen-rs/compare/v0.4.3...v0.5.0

    Source code(tar.gz)
    Source code(zip)
  • v0.4.3(Jun 9, 2023)

  • v0.4.2(Jun 2, 2023)

    • add Catppuccin OLED
    • binary will use new minor palette versions w/o needing a new release of the main crate

    Full Changelog: https://github.com/ozwaldorf/lutgen-rs/compare/v0.4.1...v0.4.2

    Source code(tar.gz)
    Source code(zip)
  • v0.4.1(Jun 2, 2023)

  • v0.4.0(Jun 2, 2023)

    • added simple color correction algorithm for applying luts
    • refactored and improved binary with new subcommand: apply <image>

    Full Changelog: https://github.com/ozwaldorf/lutgen-rs/compare/v0.3.2...v0.4.0

    Source code(tar.gz)
    Source code(zip)
  • v0.3.2(May 14, 2023)

  • v0.3.1(May 13, 2023)

  • v0.3.0(May 13, 2023)

    Refactor the library's algorithms around generic traits and some improvements to the binary

    Full Changelog: https://github.com/ozwaldorf/lutgen-rs/compare/v0.2.1...v0.3.0

    Source code(tar.gz)
    Source code(zip)
  • v0.2.1(May 13, 2023)

  • v0.2.0(May 13, 2023)

    Second release, with 750+ base colorschemes included in a new crate: lutgen-palettes !

    Full Changelog: https://github.com/ozwaldorf/lutgen-rs/compare/v0.1.0...v0.2.0

    Source code(tar.gz)
    Source code(zip)
  • v0.1.0(May 13, 2023)

    Initial release of the cli and library. Includes palettes for catppuccin flavors.

    Full Changelog: https://github.com/ozwaldorf/lutgen-rs/compare/v0.1.0-alpha.0...v0.1.0

    Source code(tar.gz)
    Source code(zip)
  • v0.1.0-alpha.0(May 13, 2023)

A blazingly fast rust-based bionic reader for blazingly fast reading within a terminal console 🦀

This Rust-based CLI tool reads text and returns it back in bionic reading format for blazingly fast loading and even faster reading! Bionic reading is

Ismet Handzic 5 Aug 5, 2023
A simple command line tool for creating font palettes for engines like libtcod

palscii A simple command line tool for creating font palettes for engines like libtcod. Usage This can also be viewed by running palscii --help. palsc

Steve Troetti 2 May 2, 2022
Rust flavor of the popular cron scheduler croner.

Croner Croner is a fully featured, lightweight, efficient Rust library for parsing and evaluating cron patterns. Designed with simplicity and performa

Hexagon 4 Nov 10, 2023
Warp is a blazingly fast, Rust-based terminal that makes you and your team more productive at running, debugging, and deploying code and infrastructure.

Warp is a blazingly fast, Rust-based terminal that makes you and your team more productive at running, debugging, and deploying code and infrastructure.

Warp 10.4k Jan 4, 2023
A comprehensive collection of resources and learning materials for Rust programming, empowering developers to explore and master the modern, safe, and blazingly fast language.

?? Awesome Rust Lang ⛰️ Project Description : Welcome to the Awesome Rust Lang repository! This is a comprehensive collection of resources for Rust, a

Shubham Raj 16 May 29, 2023
A blazingly fast Insertion Sort and Quick Sort visualizer built with Rust and WASM.

sortysort A blazingly fast Insertion Sort and Quick Sort visualizer built with Rust and WASM. Try it in your browser from here Testing locally cargo r

null 3 Jan 28, 2022
A robust, customizable, blazingly-fast, efficient and easy-to-use command line application to uwu'ify your text!

uwuifyy A robust, customizable, blazingly-fast, efficient and easy-to-use command line application to uwu'ify your text! Logo Credits: Jade Nelson Tab

Hamothy 43 Dec 12, 2022
🚀 A blazingly fast easy to use dotfile and global theme manager written in Rust

GTHEME A blazingly fast easy to use dotfile and global theme manager for *NIX systems written in Rust ?? Demo using wip desktop. To check out more des

David Rodriguez 19 Nov 28, 2022
A blazingly fast command-line tool for converting Chinese punctuations to English punctuations

A blazingly fast command-line tool for converting Chinese punctuations to English punctuations

Hogan Lee 9 Dec 23, 2022
A CLI calculator written in Rust that isn't blazingly fast.

Calcamabob A command line calculator Is written in Rust Is not blazing fast, and could be faster. Calcamabob can interpret operator precedence. For ex

Casey Kneale 4 Oct 24, 2022