Question

I am trying to display this image as i have this image in my directory

enter image description here

but i displaying it with this code

Mat img=imread("D:\\vig.png");
imshow("image",img);
waitKey();
imwrite("D:\\img.jpg",img);

The same image displayed as follows

enter image description here

Whats wrong with it

Was it helpful?

Solution

your vignette is only in the alpha [4th] channel, and also it looks inverted (opacity values here).

(your 1st picture seems to show a proper alpha composite with a white image(or background), that's probably from photoshop or the like. )

Mat img=imread("vig.png",-1); // load 'as is', don't convert to bgr !!
Mat ch[4]; 
split(img,ch);

Mat im2 = ch[3];              // here's the vignette

// im2 = 255 - im2;           // eventually cure the inversion

imshow("image",im2);
waitKey();
imwrite("img.jpg",im2);

enter image description here

again, note, that opencv won't do any alpha-compositing, you'll have to roll your own formulas for that.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top