First time here? Check out the FAQ!

Ask Your Question
1

Combining multiple cv::Mat images into single cv::Mat

asked Mar 29 '13

I am working with the new C++ - style interface. I thought I could use the following trick to create an image based on 3 existing images, but the window stays clear of information. Anyone has an idea what I am doing wrong?

split(input_color,color_channels);
blue_channel = color_channels[0];
green_channel = color_channels[1];
red_channel = color_channels[2];

Above code show splitting into color channels which I want to represent next to eachother.

int rows = input_color.rows;
int cols = input_color.cols;

Mat result_channel(rows, cols * 3, CV_8UC1);
result_channel( Rect(0, 0, cols, rows) ) = blue_channel;
result_channel( Rect(cols, 0, cols, rows) ) = green_channel;
result_channel( Rect(cols*2, 0, cols, rows) ) = red_channel;

imshow("color channels", result_channel); cvWaitKey(10);

By using the roi parameter I wanted to assign the color channels to a region in the larger image. Result however is a blank window. Anyone has an idea what is happening?

Preview: (hide)

Comments

Why it show CV_8UC1 cannot be resolved to a variable when I write imageroiB.create(block,block,CV_8UC1);

maizi gravatar imagemaizi (May 19 '14)edit

I do not understand your problem... This has quite nothing to do with this question. I think you simply need

  Mat imageroiB(block, block, CV_8UC1);
StevenPuttemans gravatar imageStevenPuttemans (May 19 '14)edit

Can I have your e-mail.I send the screenshots to you.

maizi gravatar imagemaizi (May 19 '14)edit

No, just open your own question and add them there with some explanation ...

StevenPuttemans gravatar imageStevenPuttemans (May 19 '14)edit

OK ,thank you all the same! I write like this :Mat imageroiB(block,block,CV_8UC1) .it will appear a red break line under the word "Mat".And it can't run. I could not find the "CV_8UC1" in the options when I use the "Alt+/".

maizi gravatar imagemaizi (May 19 '14)edit

Like I said, own question, add your code and then I might be able to tell the problem!

StevenPuttemans gravatar imageStevenPuttemans (May 19 '14)edit

Sorry for my poor English expression abilities. This is my question:
http://answers.opencv.org/question/33639/could-not-find-opencv-library-248apk/

maizi gravatar imagemaizi (May 19 '14)edit

2 answers

Sort by » oldest newest most voted
2

answered Mar 29 '13

AlexanderShishkov gravatar image

You also can use mixChannels() function:

Mat result_channel(rows, cols, CV_8UC3);
Mat in[] = { blue_channel, green_channel, red_channel };
int from_to[] = { 0,0, 1,1, 2,2 };
mixChannels( in, 3, &result_channel, 1, from_to, 3 );
Preview: (hide)
1

answered Mar 29 '13

Vladislav Vinogradov gravatar image

The Mat assignment operator doesn't copy data, it just copy pointers. To copy data use copyTo method:

blue_channel.copyTo( result_channel( Rect(0, 0, cols, rows) ) );
green_channel.copyTo( result_channel( Rect(cols, 0, cols, rows) ) );
red_channel.copyTo( result_channel( Rect(cols*2, 0, cols, rows) ) );
Preview: (hide)

Comments

Thx for the answer :) I was already experimenting with the copyTo operator, but switched the order of what to copy to what exactly. The above did the trick!

StevenPuttemans gravatar imageStevenPuttemans (Mar 29 '13)edit

Question Tools

1 follower

Stats

Asked: Mar 29 '13

Seen: 17,581 times

Last updated: Mar 29 '13