Trying to translate a blend mode formula

I use opencv C ++ to create a blend mode, for example, in photoshop , I want to make a blend mode in it, I look for its alternative in opencv, in which I found this blend method , but this is not an overlay, since I want to use it in it overlay method.

overlay formula from this documentation

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

Can someone explain this formula for implementation in opencv C ++, how can I easily understand it for implementation, or is there any function already to create it or any other simple way out: P

What actually overlay blending was Multiplies the light colors and screens the dark colors

+1
c ++ image image-processing opencv computer-vision
source share
1 answer

First, the author of the link you provided suggested that the color of the pixel as a value is from 0 to 1.

Imagine you want to mix 2 images of img1 and img2 . The formula says that if the pixel in img1 as a Target > 0.5 value Target > 0.5 , then the resulting value (1 - (1-2*(Target-0.5)) * (1-Blend)) for the mixed image, where Blend is the img2 pixel img2 .

On the other hand, if Target <= 0.5 resulting color value will be ((2*Target) * Blend) .

You need to do this for each pixel.

This link provides an overlap function with OpenCV.

Here is a halftone example. For an RGB image, you need to do this for each channel. Of course, img1 and img2 should be the same size. There may be a faster way to do this with OpenCV.

 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); } } } 
+2
source share

All Articles