Ask Your Question

Revision history [back]

try something like this :

Mat img1 = imread("f:/lib/opencv/samples/data/lena.jpg", IMREAD_COLOR);
Mat img2 = imread("f:/lib/opencv/samples/data/orange.jpg", IMREAD_COLOR);
Mat img3;
Mat mask(img1.rows,img1.cols,CV_8UC1,Scalar(0));
circle(mask,Point(200,200),100,Scalar(255),-1);
img2.copyTo(img3,mask);
bitwise_not(mask,mask);
img1.copyTo(img3, mask);
imshow("test",img3);
waitKey();

try something like this :

 Mat img1 = imread("f:/lib/opencv/samples/data/lena.jpg", IMREAD_COLOR);
 Mat img2 = imread("f:/lib/opencv/samples/data/orange.jpg", IMREAD_COLOR);
 Mat img3;
img3,img4;
    Mat mask(img1.rows,img1.cols,CV_8UC1,Scalar(0));
circle(mask,Point(200,200),100,Scalar(255),-1);
img2.copyTo(img3,mask);
bitwise_not(mask,mask);
img1.copyTo(img3, mask);
imshow("test",img3);
mask1(img1.rows, img1.cols, CV_8UC1, Scalar(0));
    circle(mask1, Point(200, 200), 100, Scalar(92), -1);
    Mat mask2=255-mask1;
    Mat mask2c,mask1c;
    vector<Mat> pMask = { mask1,mask1,mask1 };
    merge(pMask, mask1c);
    pMask.clear();pMask.push_back(mask2); pMask.push_back(mask2);pMask.push_back(mask2);
    merge(pMask, mask2c);
    multiply(img1, mask1c, img3,1.0/255, CV_32F);
    multiply(img2, mask2c, img4, 1.0 / 255, CV_32F);
    img4 =img3+img4;
    img4.convertTo(img3,CV_8U);
    imshow("test", img3);
    waitKey();

try something like this :

  Mat img1 = imread("f:/lib/opencv/samples/data/lena.jpg", IMREAD_COLOR);
  Mat img2 = imread("f:/lib/opencv/samples/data/orange.jpg", IMREAD_COLOR);
 Mat mask2c, mask1c;
Mat img3,img4;
    Mat mask1(img1.rows, img1.cols, CV_8UC1, Scalar(0));
    circle(mask1, Point(200, 200), 100, Scalar(92), -1);
    Mat mask2=255-mask1;
    Mat mask2c,mask1c;
    vector<Mat> pMask = { mask1,mask1,mask1 };
 merge(pMask, mask1c);
    pMask.clear();pMask.push_back(mask2); pMask.push_back(mask2);pMask.push_back(mask2);
    merge(pMask, mask2c);
    mask2c=Vec3b(255,255,255)-mask1c;
multiply(img1, mask1c, img3,1.0/255, CV_32F);
    img3,1, CV_32S);
multiply(img2, mask2c, img4, 1.0 / 255, CV_32F);
    img4,1, CV_32S);
img4 =img3+img4;
    img4.convertTo(img3,CV_8U);
    imshow("test", = img3 + img4;
img4.convertTo(img3, CV_8U,1./255);
t1.stop();
cout<< t1.getTimeMilli()<<"\n";
imshow("test2", img3);
 waitKey();

@berak I lost the race because multiply don't use parallelloopbody. Pointer are better here

try something like this :

 ocl::setUseOpenCL(false);
 Mat img1 = imread("f:/lib/opencv/samples/data/lena.jpg", IMREAD_COLOR);
 Mat img2 = imread("f:/lib/opencv/samples/data/orange.jpg", IMREAD_COLOR);
Mat mask2c, mask1c;
Mat img3,img4;
vector<Mat> pMask = { mask1,mask1,mask1 };
merge(pMask, mask1c);
mask2c=Vec3b(255,255,255)-mask1c;
multiply(img1, mask1c, img3,1, CV_32S);
multiply(img2, mask2c, img4,1, CV_32S);
img4 = img3 + img4;
img4.convertTo(img3, CV_8U,1./255);
t1.stop();
cout<< t1.getTimeMilli()<<"\n";
imshow("test2", img3);
waitKey();

@berak I lost the race because multiply don't use parallelloopbody. Pointer are better herehere.Opencl is disable too