Git Product home page Git Product logo

spice-lib's Introduction

spice-lib. an image processing library.

spice-lib. An image processing library.

Lines of Code

Support and status

Operating System Compiler Status
macOS 10.15 clang Build status
Ubuntu 18.04, 20.04 g++ Build status
VFX Reference Platform 2021 (CentOS) g++, clang Build status

spice-lib, or spice for short, is a set of image processing tools built on top of custom data types.

spice also provides a small wrapper around OpenImageIO reading and writing operations to facilitate input and output. In a future release this wrapper and the dependency on OIIO will be made optional.

Examples

Colour arithmetic

spice allows you to handle colours almost as easily as scalars.

using namespace spice;

color<float, 3> c1{0.2, 0.47, 1};
auto c2 = c1 * 0.5;
c1 += c2;

std::cout << c1 << ", " << c2 << '\n';

Output

color(0.3, 0.705, 1.5), color(0.1, 0.235, 0.5)

Non-owning color_view type

If you want to have the same flexibility without taking ownership of the underlying memory, you can use color_view to construct a wrapper exposing the same operations.

/**
 * Brighten an image contained in a raw buffer. For the sake of this example,
 * we'll assume planar, row-major memory layout.
 */
void brighten(float * data, size_t width, size_t height, size_t nchannels,
    float brightness)
{
    for (size_t y = 0; y < height; ++y) {
        for (size_t x = 0; x < width; ++x) {
            spice::color_view<float> pixel(
                // the offset of the first sample in memory
                data + y * width + x,
                // the stride between samples - in this case one entire plane
                width * height,
                // the number of channels
                nchannels);

            // use color_view's operator*= to adjust brightness
            pixel *= brightness;
        }
    }
}

Reading an image, calculating its histogram and printing it to the terminal

Note: This will only work on terminals that can display full 8bpc colour.

using namespace spice;

// read an image from a file
auto boat = load_image<float, 3>("./data/testing/boat.jpg");

// print the image to stdout
std::cout << "Printing images to the console is fast and easy!\n";
print::image<float, 3>(boat, 10);

// calculate a histogram with 50 "buckets"
auto hist = statistics::histogram(boat, 50);

// print the histogram to stdout - the peaks will be scaled to a height of 100 characters
print::histogram(hist, 100);

This will result in the following output:

print_image_to_stdout print_image_to_stdout

Not glamorous, but for retro-cool and debugging it does the job.

Building, installing and using spice-lib in your CMake build

See INSTALL.md.

History

This is the fourth iteration of a "learning-by-failing-and-starting-over" project of mine. The idea is to build an understanding for image processing by building this library from the ground up.

Credits

The build system has been adapted from cmake init: https://github.com/cginternals/cmake-init

Backing image of spice splash screen and favicon: Crab Nebula by NASA/STScI: https://hubblesite.org/contents/media/images/2005/37/1823-Image.html?news=true

spice-lib's People

Contributors

janhett avatar

Stargazers

 avatar

Watchers

 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.