Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How to do Mul blending in opencv

I want to blend two images like multiply blending in photoshop , i want to do the same in OpenCv using C++ for my app , I visit this many time and try to understand every time but i didn't get it , i search it alot but didn't get what i want other then this but this is little bit strange as conversion is alot from IplImages to ibl etc , Any help , guide, idea and example related opencv is needed . I go through Addweight but i think its quite different from Multiply Blending

Formula which i saw here

Target * Blend

and below is what i tried

Mat img1 = imread("E:\\img.jpg");
Mat img2 = Mat (img1.size(),img1.type());
vector<Mat> colors_1;
split(img2, colors_1);
colors_1[0] = 113;
colors_1[1] = 221;
colors_1[2] = 216;
merge(colors_1,img2);
Mat result(img1.size(), CV_32F);
for(int i = 0; i < img1.size().height; ++i){
    for(int j = 0; j < img1.size().width; ++j){
        for (int rgb=0 ; rgb<=img1.channels();rgb++){
            float target = float(img1.at<uchar>(i, j)) / 255;
            float blend = float(img2.at<uchar>(i, j)) / 255;
            result.at<float>(i, j) = target*blend;
        }

    }
}

Thank you

How to do Mul blending in opencvGetting Blackscreen when i run my program

I want to blend two images like multiply blending in photoshop , i want to do am running the same in OpenCv using C++ for my app , I visit this many time and try to understand every time code but i didn't get whenever i run it , i search it alot but didn't get what i want other then this but this is little bit strange give me the black screen as conversion is alot from IplImages to ibl etc , Any help , guide, idea and example related opencv is needed . I go through Addweight but i think its quite different from Multiply Blending

Formula output rather than some good results which i saw here

Target * Blend

and below is what i triedwant

Mat cv::Mat img1 = imread("E:\\img.jpg");
Mat cv::imread("E:\\raw_3.jpg");
cv::Mat img2 = Mat cv::Mat (img1.size(),img1.type());
vector<Mat> std::vector<cv::Mat> colors_1;
split(img2, cv::split(img2, colors_1);
colors_1[0] = 113;
173;
colors_1[1] = 221;
colors_1[2] = 216;
merge(colors_1,img2);
246;
cv::merge(colors_1,img2);
Mat result(img1.size(), CV_32F);
CV_8UC3);

for(int i = 0; i < img1.size().height; ++i){
    for(int j = 0; j < img1.size().width; ++j){
        for (int rgb=0 c=0 ; rgb<=img1.channels();rgb++){
            float c<img1.channels();c++){
            uchar target = float(img1.at<uchar>(i, j)) / 255;
            float img1.at<uchar>(i, 3*j+c)/255. ;
            uchar blend = float(img2.at<uchar>(i, j)) / 255;
            result.at<float>(i, j) = target*blend;
        }

    }
img2.at<uchar>(i, 3*j+c)/255. ;
            if(target > 0.5){
                result.at<uchar>(i, 3*j+c) = cv::saturate_cast<uchar>((1 - (1-target) * (1-2*(blend-0.5))))/255.;
                }
            else{
                result.at<uchar>(i, 3*j+c) = cv::saturate_cast<uchar>(target * (2*blend))/255.;
                }
        }
    }

Thank you