Ask Your Question
1

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

asked 2013-03-29 04:24:33 -0500

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?

edit retag flag offensive close merge delete

Comments

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

maizi gravatar imagemaizi ( 2014-05-19 03:16:02 -0500 )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 ( 2014-05-19 04:50:03 -0500 )edit

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

maizi gravatar imagemaizi ( 2014-05-19 06:59:21 -0500 )edit

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

StevenPuttemans gravatar imageStevenPuttemans ( 2014-05-19 07:01:01 -0500 )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 ( 2014-05-19 07:11:41 -0500 )edit

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

StevenPuttemans gravatar imageStevenPuttemans ( 2014-05-19 07:51:19 -0500 )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 ( 2014-05-19 09:11:53 -0500 )edit

2 answers

Sort by ยป oldest newest most voted
2

answered 2013-03-29 04:45:41 -0500

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 );
edit flag offensive delete link more
1

answered 2013-03-29 04:31:47 -0500

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) ) );
edit flag offensive delete link more

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 ( 2013-03-29 04:37:31 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower

Stats

Asked: 2013-03-29 04:24:33 -0500

Seen: 13,203 times

Last updated: Mar 29 '13