Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenCV Split and Merge [duplicate]

I have an image of type Mat that I am trying to separate into its individual bands so I can then adjust the pixel values in each band separately. When I write the code this error pops up "No matching function for call to 'cvSplit'".

Mat image = imread(file,1);
Mat rBand, gBand,bBand;
cvSplit(image, bBand, gBand, rBand, NULL);
imshow("red", rBand);
imshow("blue", bBand);
imshow("green",gBand);
like image 470
C.Radford Avatar asked Jun 17 '26 07:06

C.Radford


2 Answers

A mat does not allow a subscript operator if not stated when created. Therefore most create a Mat denoting number of bands within so it can then be split. this means that Bands[0],Bands[1],Bands[2] are each of a single channel and are grayscale. Not get original image must then merge the channels using merge function.

Mat image = imread(file,1);
Mat Bands[3],merged;
split(image, Bands);
vector<Mat> channels = {Bands[0],Bands[1],Bands[2]};
merge(channels,merged);
imshow("red", Bands[2]);
imshow("blue", Bands[0]);
imshow("green",Bands[1]);
imshow("merged",merged);
like image 106
C.Radford Avatar answered Jun 18 '26 21:06

C.Radford


Try this function instead if cvSplit:

cv::split
like image 39
Harald Nordgren Avatar answered Jun 18 '26 22:06

Harald Nordgren



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!