First time here? Check out the FAQ!

Ask Your Question
2

How to extract red color plane in OpenCV C++

asked May 18 '13

Ali Tillawi gravatar image

How to extract red color plane in OpenCV C++?

Preview: (hide)

3 answers

Sort by » oldest newest most voted
5

answered May 18 '13

berak gravatar image

easy!

Mat src=imread("my.png");
Mat planes[3];
split(src,planes);  // planes[2] is the red channel
Preview: (hide)

Comments

Is it applicable for android programming in Java with openCv? if not then can you please suggest me the alternative for this code, Thank you.

khatri.kelash gravatar imagekhatri.kelash (Jan 18 '17)edit

Thank you Sir for reply, I managed to write the code, and convert the related 3 channels from matrix form to bitmap form but code is not working. The app just show dialog box [Unfortunaly app has stopped].

khatri.kelash gravatar imagekhatri.kelash (Jan 21 '17)edit
2

answered Oct 6 '15

Mizux gravatar image

prefer to use void cv::extractChannel (InputArray src, OutputArray dst, int coi )

cv::Mat out; cv::extractChannel(in, out, 0) // Supposing RGB channel with red first out....

src: http://docs.opencv.org/master/d2/de8/group__core__array.html#gacc6158574aa1f0281878c955bcf35642

Preview: (hide)
0

answered May 21 '13

Ali Tillawi gravatar image

updated May 21 '13

Thank you :)

I have used this one and it worked well:

IplImage* frame_r = cvCreateImage(size, IPL_DEPTH_8U, 1);
IplImage* frame_g = cvCreateImage(size, IPL_DEPTH_8U, 1);
IplImage* frame_b = cvCreateImage(size, IPL_DEPTH_8U, 1);

    cvSplit(frame, frame_b, frame_g, frame_r, NULL);
Preview: (hide)

Comments

2

What you are doing isn't C++ code but using the old C-style API. Keep in mind that the support for the old API will start to get less and less, since people are stimulated to use the newer, more clear C++ interfacing of OpenCV.

StevenPuttemans gravatar imageStevenPuttemans (May 21 '13)edit

Sir how to subtract among three planes example r-g+b

kamachisundaram gravatar imagekamachisundaram (Nov 20 '14)edit

That is just a simple operator. I think you can subtract and add matrices. Have you tried

Mat temp = red - green + blue;

This should work for your needs!

StevenPuttemans gravatar imageStevenPuttemans (Nov 20 '14)edit

Question Tools

Stats

Asked: May 18 '13

Seen: 39,855 times

Last updated: May 21 '13