Coder Social home page Coder Social logo

z2oh / chromatic_confinement Goto Github PK

View Code? Open in Web Editor NEW
13.0 2.0 2.0 13.58 MB

Rust implementation of k-d tree to efficiently perform color quantization to predefined sets

Home Page: http://blog.krum.io/k-d-trees/

Rust 89.92% Shell 10.08%
quantization kdtree rust algorithm

chromatic_confinement's Introduction

chromatic_confinement

See the article for this repo here: http://blog.krum.io/k-d-trees/

An implementation of a k-d tree to quantize color images down to a defined set.

After cloning, use cargo build --release to download dependencies and compile. From there, you can invoke the binary directly in ./target/release/chromatic_confiner <args> or you can use cargo run --release -- <args>.

There are three required files to be passed into the program.

-c <FILE> The color specification file to be used in restricting the image. This should be formatted as a list of r,g,b color values, with one color per line. See https://github.com/z2oh/chromatic_confinement/blob/master/color_files/css4.colors for an example.

-i <FILE> The input image to quantize

-o <FILE> The path of the resultant output image (this should end in .png).

You can pass the -n flag to run the slow version of this algorithm. This is the non k-d tree version, which runs much more slowly than the k-d tree version when the number of colors is large. See http://blog.krum.io/k-d-trees/#results for a more detailed comparison.

Example usage (can be run immediately after cloning):

cargo run --release -- -c color_files/1kcolors.colors -i images/bridge_4096_2304.jpg -o image.png will produce this image (in ./image.png, the image you see here is scaled down to reduce load time of this repo. Image provided courtesy of Julian Herzog, see LICENSE for more information):

Exmaple output, scaled to 25% size, image of bridge quantized to 1024 random colors

If you would like to try out this code on huge images, I recommend searching for images on Wikimedia Commons. Here is a 30,000 x 23,756 pixel image of Starry Night, for example.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.