Ask Your Question
0

Non linear blending - How to?

asked 2013-12-20 05:26:36 -0600

Viatorus gravatar image

Hey Community,

I want do blend two images non linear. AddWeighted can only blend two images linear. I am looking for something like this:

non linear blending

(http://graphics.cs.cmu.edu/courses/15-463/2008_fall/Lectures/blending.pdf)

The best would be, if I could use my own mask for that. I thought to use a alpha mask (explained here) but I don´t know how to get back to rgb and blend again..

Anyone an idea? Thanks in advance!

edit retag flag offensive close merge delete

1 answer

Sort by » oldest newest most voted
2

answered 2013-12-20 08:48:36 -0600

berak gravatar image

you could just go and interpol single cols:


Mat l(100,200,CV_8UC3,Scalar(255,0,0)); // you probably want to imread your img,
Mat r(100,200,CV_8UC3,Scalar(0,0,255)); // this is just to show the effect nicely
Mat res(l.size(),l.type());
double step = 1.0 / l.cols;
double blend = 0.0;
for ( int i=0; i<l.cols; i++ )
{
    res.col(i) = l.col(i) * blend + r.col(i) * (1.0-blend);
    blend += step;
}
imwrite("blended.png",res);
imshow("lalala",res);
waitKey();

blended:

edit flag offensive delete link more

Question Tools

Stats

Asked: 2013-12-20 05:26:36 -0600

Seen: 608 times

Last updated: Dec 20 '13