Ask Your Question

Non linear blending - How to?

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

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


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

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

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;


edit flag offensive delete link more
Login/Signup to Answer

Question Tools


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

Seen: 377 times

Last updated: Dec 20 '13