Tuesday, January 11, 2011

A lightweight Image Processing Library in C++

Ever wondered how to work with/on images with little or no development overhead on your own? Here is the answer, the CImg image processing library. CImg stands for Cool Image; it is an open source, written entirely in C++, image processing toolkit which is very easy to use, handy for image processing tasks.

I first encountered this library when I was working on the dissertation, I had to extract frames from a video which I did easily using mpeg2encode and mpeg2decode, after that I had to read these frames (images) into 2D arrays and process them. I started looking for a way to achieve this and ended up with CImg library.
CImg is designed with following properties in mind:

Usefulness: CImg defines classes and methods to manage images in your own C++ code. You can use it to load/save various file formats, access pixel values, display/transform/filter images, draw primitives (text, faces, curves, 3d objects, ...), compute statistics, manage user interactions on images, and so on...

Genericity: CImg defines a single image class which can represent datasets having up to 4-dimensions (from 1d scalar signals to 3d hyperspectral volumetric images), with template pixel types (bool,char,int,float,...). It also handles image collections and sequences.

Portability: CImg is self-contained and thus highly portable. It fully works on different operating systems (UNIX, Windows, MacOS X, BSD, …) and is compatible with various C++ compilers (VC++, g++, …).

Simplicity: CImg is lightweight. It is made of a single header file “CImg.h” that must be included in your C++ source. It defines only four different classes, encapsulated in a namespace. It can be compiled using a minimal set of standard C++ and system libraries.

Just include a single header file in your application or library and you done and fully equipped with amazing capability of this library.

How to use CImg in your C++ program?
You just need to add these two lines in your C++ source code, in order to be able to work with CImg images:

    #include “CImg.h”
    using namespace cimg_library;

I guess this is enough introduction, believe me; you have to use it to realize its power and usefulness. 


Reference: http://cimg.sourceforge.net

Cheers!
Rajendra

No comments: