图层混合

 
// mix.cpp : 图像mix
//
 
#include "stdafx.h"
#include <iostream>
#include "opencv2/core/core.hpp"
#include "opencv2/highgui/highgui.hpp"
#include "opencv2/imgproc/imgproc.hpp"
using namespace std;
using namespace cv;
 
// Multiply 正片叠底
void Multiply(Mat& src1, Mat& src2, Mat& dst)
{
    for(int index_row=0; index_row<src1.rows; index_row++)
    {
        for(int index_col=0; index_col<src1.cols; index_col++)
        {
            for(int index_c=0; index_c<3; index_c++)
                dst.at<Vec3f>(index_row, index_col)[index_c]=
                src1.at<Vec3f>(index_row, index_col)[index_c]*
                src2.at<Vec3f>(index_row, index_col)[index_c];
        }
    }
}
 
// Color_Burn 颜色加深
void Color_Burn(Mat& src1, Mat& src2, Mat& dst)
{
    for(int index_row=0; index_row<src1.rows; index_row++)
    {
        for(int index_col=0; index_col<src1.cols; index_col++)
        {
            for(int index_c=0; index_c<3; index_c++)
                dst.at<Vec3f>(index_row, index_col)[index_c]=1-
                (1-src1.at<Vec3f>(index_row, index_col)[index_c])/
                src2.at<Vec3f>(index_row, index_col)[index_c];
        }
    }
}
 
// 线性增强
 
void Linear_Burn(Mat& src1, Mat& src2, Mat& dst)
{
    for(int index_row=0; index_row<src1.rows; index_row++)
    {
        for(int index_col=0; index_col<src1.cols; index_col++)
        {
            for(int index_c=0; index_c<3; index_c++)
                dst.at<Vec3f>(index_row, index_col)[index_c]=max(
                src1.at<Vec3f>(index_row, index_col)[index_c]+
                src2.at<Vec3f>(index_row, index_col)[index_c]-1, (float)0.0);
        }
    }
}
 
int _tmain(int argc, _TCHAR* argv[])
{    
    //首先做灰度的mix
    Mat src = imread("1.jpg");
    Mat mask = imread("mask2.jpg");
    Mat maskF(src.size(),CV_32FC3);
    Mat srcF(src.size(),CV_32FC3);
    Mat dstF(src.size(),CV_32FC3);
    src.convertTo(srcF,CV_32FC3);
    mask.convertTo(maskF,CV_32FC3);
    srcF = srcF /255;
    maskF = maskF/255;
    Mat dst(srcF);
    //正片叠底
    Multiply(srcF,maskF,dstF);
    dstF = dstF *255;
    dstF.convertTo(dst,CV_8UC3);
    imwrite("正片叠底.jpg",dst);
    // Color_Burn 颜色加深
    Color_Burn(srcF,maskF,dstF);
    dstF = dstF *255;
    dstF.convertTo(dst,CV_8UC3);
    imwrite("颜色加深.jpg",dst);
    // 线性增强
    Linear_Burn(srcF,maskF,dstF);
    dstF = dstF *255;
    dstF.convertTo(dst,CV_8UC3);
    imwrite("线性增强.jpg",dst);
    waitKey();
    return 0;
}





posted on   jsxyhelu  阅读(59)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南
· 被坑几百块钱后,我竟然真的恢复了删除的微信聊天记录!

导航

< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

统计

点击右上角即可分享
微信分享提示