Ravi
Ravi

Reputation: 309

Add alpha channel to opencv Mat

Using the cv::imread I was able to reading the RGB image to cv::Mat (as below)

Mat picture = imread(fileName, -1);

Instead of reading, I tried to create an RGB image using the following code :

Mat arr1 = Mat(9, 9, CV_8UC1, &data1);
Mat arr2 = Mat(9, 9, CV_8UC1, &data2);
Mat arr3 = Mat(9, 9, CV_8UC1, &data3);
Mat pic;
vector<Mat> mk(3);
mk.at(0)=(arr1);
mk.at(1)=(arr2);
mk.at(2)=(arr3);
merge(mk,pic);

Will the Mat picture and Mat pic be equal? As cv::imread has a flag of '-1' which indicates that 'Return the loaded image as is (with alpha channel)'. Which I am not able to understand and how do I match 'pic' to 'picture'?(Not picture to pic)

Upvotes: 1

Views: 2002

Answers (1)

Gaurav Raj
Gaurav Raj

Reputation: 708

-1 Flag in cv::imread indicates that image will be loaded as it is including the alpha channel if present. So, if your image file has alpha channel, your picture(Mat) will be a CV_8UC4 type of image while your pic(Mat) is a 3 channel image. Hence, they won't be same in some cases. But if your picture(Mat) has only 3 channels and its B, G, R channels have same data as data1, data2, data3 respectively then your 'picture' and 'pic' will be same.

Upvotes: 1

Related Questions