Skip to content

ad-si/FlatCV

Repository files navigation

FlatCV

Image processing and computer vision library in pure C.

  • Color images are a flat array of 8-bit per channel RGBA row-major top-to-bottom
  • Grayscale images are a flat array of 8-bit GRAY row-major top-to-bottom
  • All operations are done on the raw sRGB pixel values
  • Minimal usage of macros and preprocessor
  • Available as an amalgamation where all code is combined into one file. (Each release includes a flatcv.h and flatcv.c file.)
  • No fusing of image transformations
  • No multithreading
    You're more likely to process one file per core than one file over multiple cores anyways. Yet, it's still often faster than GraphicsMagick with multiple threads. (Check out the benchmark.)
  • No GPU acceleration
  • Only uses functions from the C standard library.

Usage

FlatCV can either be used as a C library or via its CLI.

CLI

The CLI supports edit pipelines which sequentially apply all transformations.

flatcv <input> <comma-separated-edit-pipeline> <output>

As commas aren't special characters in shells, you can write the edit pipeline without quotes. Both variants yield the same result:

flatcv i.jpg 'grayscale, blur 9' o.jpg
flatcv i.jpg grayscale, blur 9 o.jpg

Examples

Check out the documentation website for more examples and usage instructions.

Command Input Output
flatcv i.jpg grayscale o.jpg Parrot Parrot Grayscale
flatcv i.jpg grayscale, blur 9 o.jpg Parrot Parrot Grayscale and Blur
flatcv i.jpg bw_smooth o.jpg Parrot Smooth Binarization
flatcv i.jpg watershed 0x0 300x200 599x0 o.jpg Parrot Watershed Segmentation

Library

#include "flatcv.h"

// Resize an image to half size
unsigned char const * half_size = resize(
    input_width, input_height,
    0.5, 0.5,
    &out_width, &out_height,
    input_data
);

// Do something with the resized image

// Free the allocated memory
free(half_size);