简体   繁体   中英

How to convert 8 bit IplImage to 24 bit IplImage in OpenCV?

I have an 8 bit IplImage and I want to convert it to a 24 bit IplImage . How can I do this?

Assuming your gray image is in a variable called image -

IplImage *rgbimage = cvCreateImage(/*whatever size*/, 8, 3);
cvCvtColor(image, rgbimage, CV_GRAY2BGR); 

You need cvConvertScale this is an example from this question

    IplImage *im8 = cvLoadImage(argv[1]);
    IplImage *im32 = cvCreateImage(cvSize(im8->width, im8->height), 32, 3);

    cvConvertScale(im8, im32, 1/255.);

Here you go,

Mat input_8Bit;
vector <Mat> Vec_temp_8bit;

Vec_temp_8bit.push_back ( input_8Bit );
Vec_temp_8bit.push_back ( input_8Bit );
Vec_temp_8bit.push_back ( input_8Bit );

Mat Output_24Bit;

merge ( Vec_temp_8bit, Output_24Bit );

Please give a try, I havent checked it. But logically it should work!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM