正片叠底

#include
#include
using namespace cv;
using namespace std;
int main() {
	Mat img = imread("774.jpg"); 
	Mat tem = imread("552.jpg");   

	Mat result = tem.clone();
	if (tem.empty())
		return -1;
	if (img.empty() || tem.empty())
		return -1;

	if (img.type() != CV_32F)
		img.convertTo(img, CV_32F, 1/255.0);
	if (tem.type() != CV_32F)
		tem.convertTo(tem, CV_32F);
	if (result.type() != CV_32F)
		tem.convertTo(result, CV_32F);

	resize(tem, tem, img.size());
	resize(result, result, img.size());

	cvtColor(result, result, CV_BGR2YUV);

	vector channel;
	split(result, channel);
	 
	for (int i = 0; i < img.rows; i++) {
		for (int j = 0; j < img.cols; j++) {
			//channel[0].at(i, j) =  tem.at(i, j) * img.at(i, j);
			if(img.at(i,j) < 0.5)
				channel[0].at(i, j) = tem.at(i, j) * img.at(i, j);
			if (img.at(i, j) > 0.5)
				channel[0].at(i, j) = 1 - (1 - tem.at(i, j)) * (1 - img.at(i, j));
		}
	}

	merge(channel, result);

	cvtColor(result, result, CV_YUV2BGR);
	result.convertTo(result, CV_8U);
	GaussianBlur(result, result, Size(3, 3), 0, 0);
	imshow("result", result);

	waitKey(0);
	destroyAllWindows;
	return 0;
}

效果:

正片叠底_第1张图片

运行的两个图:

正片叠底_第2张图片                          正片叠底_第3张图片

你可能感兴趣的:(opencv图像处理)