How to install and use FreeImage

FreeImage is a simple library that can be used for reading and writing image files. If you have to read and write BMP, JPG or PNG files, then this is one of the easiest ways to do that. It has APIs available in C, C++ and .Net.


Installing FreeImage on Ubuntu is easy:

$ sudo apt-get install libfreeimage3 libfreeimage-dev


For C++ code, you can use the FreeImagePlus API, which is a C++ wrapper around the C API. Here is a simple example that reads a PNG image using the fipImage class:

#include <iostream>
#include <FreeImagePlus.h>

int main()
    fipImage img;

    std::cout << img.getWidth() << " " << img.getHeight() << std::endl;
    std::cout << img.isGrayscale() << std::endl;
    std::cout << img.getBitsPerPixel() << std::endl;

    return 0;

To compile code that uses the FreeImagePlus API, link it with using the directive -lfreeimageplus.

Tried with: FreeImage 3.15.1-1 and Ubuntu 12.04 LTS

How to build FastHOG

FastHOG is a Histogram of Oriented Gradients (HOG) library that uses CUDA to compute on the GPU. The original source code can be obtained here. However, this code cannot be compiled with recent CUDA SDKs. I’ve made the changes needed to compile it and shared the code here.

To build and install this FastHOG in a few steps:

  • Install 5.5 or a more recent version of CUDA. Instructions can be found here.

  • Install Xinerama and FreeImage libraries:

$ sudo apt install libxinerama-dev libfreeimage-dev
  • Build and install the 2.0 branch of FLTK. This is an abandoned branch of the library and instructions to build it can be found here. Note that FastHOG will not compile with the current 1.x branch of FLTK.

  • Clone the fixed source code of FastHOG, build it and test whether it works:

$ git clone
$ cd fasthog/source/fastHOG
$ make
$ bin/release/fastHOG

The test program displays an image of pedestrians. Click anywhere on it and the detected people will be drawn in red boxes.

Tried with: CUDA 5.5 and Ubuntu 12.04