Ask Your Question
0

Non linear blending - How to?

asked Dec 20 '13

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!

Preview: (hide)

1 answer

Sort by » oldest newest most voted
2

answered Dec 20 '13

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:

Preview: (hide)

Question Tools

Stats

Asked: Dec 20 '13

Seen: 625 times

Last updated: Dec 20 '13