CImg: convert an RGB image to a grayscale image

This code loads a image lena.bmp and converts the image to grayscale one.

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);

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 )

Google+ photo

You are commenting using your Google+ 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 )


Connecting to %s