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); } } }
Elie gnrd
source share