0

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

Cris Luengo
  • 55,762
  • 10
  • 62
  • 120
Pixel
  • 121
  • 2
  • 19

3 Answers3

3

Assuming your gray image is in a variable called image -

IplImage *rgbimage = cvCreateImage(/*whatever size*/, 8, 3);
cvCvtColor(image, rgbimage, CV_GRAY2BGR); 
Roger Rowland
  • 25,885
  • 11
  • 72
  • 113
3

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.);
Rachel Gallen
  • 27,943
  • 21
  • 72
  • 81
2

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!

2vision2
  • 4,933
  • 16
  • 83
  • 164
  • 1
    The cvtColor (http://docs.opencv.org/modules/imgproc/doc/miscellaneous_transformations.html#cvtcolor) function does exactly what you described, in one line. – mpenkov May 23 '13 at 05:43