Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

img = img1*mask + img2*(1-mask) How do that ?

Hello,

I would like merge two color images with an image mask.

img1 and img2 are color image with 3 channels mask is grey image with 1 channel

for merge the two image with the mask I do a loop for each pixel.

float coef1,coef2;
for(int j = 0; j < img1.rows ; j++ ){
    for(int i = 0; i < img1.cols ; i++ ){
        coef1 = (greyGoodScale.at<uchar>(j, i))/255.0;
        coef2 = 1-coef1;
        img.at<Vec3b>(j, i)[0] = coef2*img1.at<Vec3b>(j, i)[0] + coef1*img2.at<Vec3b>(j, i)[0];
        img.at<Vec3b>(j, i)[1] = coef2*img1.at<Vec3b>(j, i)[1] + coef1*img2.at<Vec3b>(j, i)[1];
        img.at<Vec3b>(j, i)[2] = coef2*img1.at<Vec3b>(j, i)[2] + coef1*img2.at<Vec3b>(j, i)[2];
    }
}

OK, it's work but my image is 720x500 and i have 70ms of processing time is TOO LONG, I need to be real time. I can't do process on GPU.

Is a way to reduce processing time ?

thank. christophe openCV 3.x

img = img1*mask + img2*(1-mask) How do that ?

Hello,

I would like merge two color images with an image mask.

img1 and img2 are color image with 3 channels mask is grey image with 1 channel

for merge the two image with the mask I do a loop for each pixel.

float coef1,coef2;
c1,c2;
for(int j = 0; j < img1.rows ; j++ ){
    for(int i = 0; i < img1.cols ; i++ ){
        coef1 c1 = (greyGoodScale.at<uchar>(j, i))/255.0;
        coef2 = 1-coef1;
c2 = 1-c1;
        img.at<Vec3b>(j, i)[0] = coef2*img1.at<Vec3b>(j, c2*img1.at<Vec3b>(j, i)[0] + coef1*img2.at<Vec3b>(j, c1*img2.at<Vec3b>(j, i)[0];
        img.at<Vec3b>(j, i)[1] = coef2*img1.at<Vec3b>(j, c2*img1.at<Vec3b>(j, i)[1] + coef1*img2.at<Vec3b>(j, c1*img2.at<Vec3b>(j, i)[1];
        img.at<Vec3b>(j, i)[2] = coef2*img1.at<Vec3b>(j, c2*img1.at<Vec3b>(j, i)[2] + coef1*img2.at<Vec3b>(j, c1*img2.at<Vec3b>(j, i)[2];
    }
}

OK, it's work but my image is 720x500 and i have 70ms of processing time is TOO LONG, I need to be real time. I can't do process on GPU.

Is a way to reduce processing time ?

thank. christophe openCV 3.x