Extract single channel image from RGB image with opencV

I work with QT and OpenCV, I have this square that I need to extract, but I need to use the conversion from RGB to one channel (mostly RED). Any advice would be more than welcome, please feel free to advise which features to use. Thanks in advance.

+7
source share
4 answers
0
source

I think cvSplit is what you are looking for ( docs ). You can use it, for example, to split RGB into R, G and B:

 /* assuming src is your source image */ CvSize s = cvSize(src->width, src->height); int d = src->depth; IplImage* R = cvCreateImage(s, d, 1); IplImage* G = cvCreateImage(s, d, 1); IplImage* B = cvCreateImage(s, d, 1); cvSplit(src, R, G, B, null); 

Please note that you need to be careful when ordering; make sure that the original image is actually ordered as R, G, B (there is a decent probability of B, G, R).

+10
source

Since this is tagged qt , I will give an answer in C ++.

  // Create Windows namedWindow("Red",1); namedWindow("Green",1); namedWindow("Blue",1); // Create Matrices (make sure there is an image in input!) Mat input; Mat channel[3]; // The actual splitting. split(input, channel); // Display imshow("Blue", channel[0]); imshow("Green", channel[1]); imshow("Red", channel[2]); 

Tested on OpenCV 2.4.5

+7
source

As far as I know,

 cvtColor(src, bwsrc, CV_RGB2GRAY); 

You can do this, where src is the multi-channel source image, and the third parameter is the number of channels at the destination. This way you can do it in OpenCV and display the image on your Qt interface.

On the other hand, you can split channels into separate single-channel arrays using the appropriate split () method.

http://opencv.willowgarage.com/documentation/cpp/core_operations_on_arrays.html#split

+2
source

All Articles