Coder Social home page Coder Social logo

iq's Introduction


Logo

iq - a little tool for image manipulation

Inspired by `jq`, iq is an experimental tool for manipulating images through expressions which transform pixels.

Usage

iq 0.1.0
[email protected]

USAGE:
    iq [OPTIONS] [ARGS]

ARGS:
    <input_path>     The path to the input image
    <output_path>    Where to write the output image

OPTIONS:
    -b, --blank <dimensions>    Use a blank canvas of provided size 'HxW' (ex. '100x300')
    -e, --expr <expressions>    The expressions to evaluate
    -f, --file <file>           Pass a file containing expressions to run
    -h, --help                  Print help information
    -V, --version               Print version information

Examples

Disclaimer: The tool is a work in progress and in its very early stages. There are certainly bugs and plenty of things to improve.

iq is passed an image and a set of expressions and produces an output image. For example:

iq -e "_ => p(_.y, _.x, _.r, 0, 0)" assets/dalle_logo.png out.jpg

Would produce an output image out.jpg with the green and blue color channels removed.

Logo

Slice Ranges

Expressions can do much more complex actions than simply uniformly changing colors. For example given this DALLE generated image of Philip Seymour Hoffman in the Disney film "Cars":

Logo

We can crop patches of the image using "slice ranges":

# Crop out a circle and replace the outside with a gradient
iq -e "[0:100, 0:100]" \
    assets/examples/dalle_philip_seymour_in_cars_movie.jpg \
    cropped_seymour.jpg
Logo

Match Expressions

We can use match expressions to apply other expressions conditionally

# Change any pixel with a green channel value greater than 128 to white
iq -e "_.g > 128 => p(_.y, _.x, 255, 255, 255) : _" \
    assets/examples/dalle_philip_seymour_in_cars_movie.jpg \
    highlight_mcqueen.jpg
Logo
# Crop out a circle and replace the outside with a gradient
iq -e "
    ([].w/2) >= sqrt(sq(_.x - center().x) + sq(_.y - center().y)) =>
        p(_.y, _.x, _.r, 255 - _.r, _.r) :
        p(_.y, _.x, (_.r * _.y) / [].h, (_.g * _.x) / [].w, 0)
" \
    assets/examples/dalle_philip_seymour_in_cars_movie.jpg \
    circle_seymour.jpg
Logo

Layering

If we provide more than one expression separated by semicolons they will be alpha composited together. For example consider this DALLE generated bottle of ranch testifying in court;

Logo
# Superimpose a rotated version on the original;
iq -e "
    _ => p(_.y, _.x, _.r, _.g, _.b, _.a * 0.5);
    _ => p(_.x, _.y, _.r, _.g, _.b, _.a * 0.5);
" \
    assets/examples/dalle_ranch_testifying_in_court.jpg \
    rotate.jpg
Logo

Pixel Functions

There are a few builtin pixel functions like:

  • color_norm
  • color_add
  • color_scale
  • neighbors

That when combined with other standard features can even do some convolutions like this sobel edge detection:

# Crop into a circle and do sobel edge detection
iq -e "
  ([].w/2) >= sqrt(sq(_.x - center().x) + sq(_.y - center().y)) => color_norm(color_add(
      color_scale(neighbors(_, -1, -1), -1.0),
      color_scale(neighbors(_,  0, -1), -2.0),
      color_scale(neighbors(_,  1, -1), -1.0),
      color_scale(neighbors(_,  1, -1), 1.0),
      color_scale(neighbors(_,  1,  0), 2.0),
      color_scale(neighbors(_,  1,  1), 1.0)
  ));
" \
    assets/examples/dalle_ranch_testifying_in_court.jpg \
    circle_edge_ranch.jpg
Logo

Language Reference

Coming soon...

How it works

iq is written in rust and uses LALRPOP for parser/lexer generation.

Installation

Right now the tool is only distributed as source. Clone the repo and do a standard cargo build

Contributing

All contributions are welcome!

License

Distributed under the MIT License. See LICENSE.txt for more information.

(back to top)

iq's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

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.