Reputation: 217
I have a problem. I have this program that makes the black color transparent.
src=imread("0.jpg", 1);
cvtColor(src,tmp,CV_BGR2GRAY);
threshold(tmp,alpha,100,255,THRESH_BINARY);
Mat rgb[3];
split(src,rgb);
Mat rgba[4]={rgb[0],rgb[1],rgb[2],alpha};
merge(rgba,4,dst);
imwrite("1.png",dst);
And his input and output is:
But I don't want black color transparent, I want that white is transparent. But I can not figure it out. Could you help me please? Thank you.
Upvotes: 1
Views: 281
Reputation: 217
src=imread("0.jpg", 1);
cvtColor(src,tmp,CV_BGR2GRAY);
threshold(tmp,alpha,100,255,THRESH_BINARY_INV);
Mat rgb[3];
split(src,rgb);
Mat rgba[4]={rgb[0],rgb[1],rgb[2],alpha};
merge(rgba,4,dst);
imwrite("1.png",dst);
If we choose THRESH_BINARY_INV instead of THRESH_BINARY. Output is: Black background with some transparent places. This was the whole problem and now is solved.
Upvotes: 2