CImg: display image(s)

This code loads an image lena.bmp and shows the original image and its grayscaled one in a window, which shows text “Original image | Grayscale image” on its bar.

std::string strFile = "lena.bmp";
cimg_library::CImg<unsigned char> img1(strFile.c_str());
cimg_library::CImg<unsigned char> img2;
int color = _imgInput.spectrum(); // to check the number of color channels
    case 1:
        img2 = img1;
    case 3: // get 0-th color slice (Y color component) of YCbCr image format
        img2 = img1.get_RGBtoYCbCr().get_channel(0);
std::string strWindow = "Original image | Grayscale image";

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s