I am Charmie

メモとログ

CImg: convert an RGB image to a grayscale image

This code loads a image lena.bmp and converts the image to grayscale one. [code lang="c"] 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 switch(color) { case 1: img2 = img1; break; case 3: // get 0-th color slice (Y color component) of YCbCr image format img2 = img1.get_RGBtoYCbCr().get_channel(0); break; } [/code]