Pergunta

I am using opencv c++ for making the blending mode like in photoshop , i want to make overlay mode in it , i search its alternate in opencv in which i found this blending way , but its not the overlay as i want to use the overlay method in it.

overlay method formula from this documentation

(Target > 0.5) * (1 - (1-2*(Target-0.5)) * (1-Blend)) +
(Target <= 0.5) * ((2*Target) * Blend)

Can any one please explain this formula for implementation in opencv c++ , how i can easy understand it for implementation or is there any already build in function for it or any other easy way out :P

Foi útil?

Solução

Here is Overlay blending mode for Photoshop implementation , above formula work as follows for Grayscale image

Mat img1;
Mat img2;
img1 = imread("img1.jpg", CV_LOAD_IMAGE_GRAYSCALE);
img2 = imread("img2.jpg", CV_LOAD_IMAGE_GRAYSCALE);
Mat result(img1.size(), CV_32F);

for(int i = 0; i < img1.size().height; ++i){
    for(int j = 0; j < img1.size().width; ++j){
        float target = float(img1.at<uchar>(i, j)) / 255;
        float blend = float(img2.at<uchar>(i, j)) / 255;
        if(target > 0.5){
            result.at<float>(i, j) = (1 - (1-2*(target-0.5)) * (1-blend));
        }
        else{
            result.at<float>(i, j) = ((2*target) * blend);
        }
    }
}

and for color image you only need to use loop for color channels

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top