1. Products
  2.   Image
  3.   C++
  4.   Boost.GIL

Boost.GIL

 
 

Open Source C++ Generic Image Library

C++ API That Abstracts Image Representations from Algorithms and Supports Working with Simple and Complex Images. Generate a Histogram, Compute Image Gradients, Convolution & Resampling, and So On.

What is Boost.GIL?

Harnessing the power of images is fundamental to modern projects in graphics, digital video, computer vision, and image processing. However, the complexity of varied image representations—such as differences in color space, bit depth, and channel order—makes building a generic yet efficient solution exceptionally challenging. This is where the Boost Generic Image Library (GIL), an open source library, becomes essential. Designed for C++ applications, it empowers software developers to seamlessly work with both simple and complex images, providing a robust foundation for new image-related project development.

The great thing about the Boost.GIL library is that it abstracts image representations from algorithms and allows writing code that can work on a variety of images with performance comparable to hand-writing for a particular image type. So it makes developer's jobs easy by allowing them to write code once and having it work for any image type.

As a cornerstone of the Boost collection, Boost.GIL is expertly designed as a complement to STL and Boost. A core strength is its elegant abstraction, which decouples image representations from algorithms. This design allows developers to write code once and have it work on a variety of images with performance comparable to hand-writing for a specific type, significantly easing the developer's jobs. Speed and flexibility are paramount; the library incurs only a minor performance cost when defining any image parameter at run time, outperforming many alternatives. It delivers advanced support for critical tasks including non-byte-aligned pixels, computing image gradients, deep Boosts integration, assigning a channel to a gray-scale pixel, and operations like convolution & resampling, making it an indispensable tool for high-performance image manipulation.

Previous Next

Getting Started with Boost.GIL

The easiest way to install Boost.GIL is by using GitHub. Please use the following command for a smooth installation

Install Boost.GILvia GitHub.

git clone --https://github.com/boostorg/gil

Reading and writing images

Histogram is the graphical representation of the tonal distribution in a digital image. In the image processing context, the histogram of an image normally refers to a histogram of the pixel intensity values. The Boost.GIL library enables software developers to generate a histogram inside their own application using C++ code. It can be generated by counting the number of pixel values that fall in each bin. You can also compute the luminosity histogram of the image with ease.

How to Write Image via C++ API?

#define png_infopp_NULL (png_infopp)NULL
#define int_p_NULL (int*)NULL
#include 
#include 
using namespace boost::gil;
int main()
{
    rgb8_image_t img(512, 512);
    rgb8_pixel_t red(255, 0, 0);
    fill_pixels(view(img), red);
    png_write_view("redsquare.png", const_view(img));
}

Pixel-Level Image Operations using C++ API

The open source library Boost.GIL has provided complete support for pixel-level image operations inside their own C++ applications. The library has included some useful operations that enable users to handle pixel values, pixel pointers, and pixel references, such as making a pixel colored, accessing a channel, comparing the two channels, constructing const planar pointer, converting gray l-value to RGB, and so on.

How to Convert Color Space to Grayscale via C++?


  template 
void x_luminosity_gradient(SrcView const& src, DstView const& dst)
{
  using gray_pixel_t = pixel::type, gray_layout_t>;
  x_gradient(color_converted_view(src), dst);
}

Image Transformation inside C++ Apps

The open source Boost.GIL library gives software programmers the ability to rotate images with just a couple of lines of code. The Boost.GIL supports a variety of image transformation functions that can perform any axis-aligned rotation, flip image vertically or horizontally, extract a rectangular sub-image, apply color conversion, , special rotations by 90, 180, or 270 degrees & so on.

How to Perform Image Transformation via C++ API?


  template 
  void y_gradient(const SrcView& src, const DstView& dst) {
      x_gradient(rotated90ccw_view(src), rotated90ccw_view(dst));
  }
 English