Ask Your Question
1

addweighted for mix of two image

asked Dec 10 '13

amin.karimi gravatar image

updated Dec 10 '13

i want to mix a part of any image with original image and i write this program but my program produce only result of mixing of two parts but i want to see may original image with a part that is mixed with a part of another image why?please help me , my original image is "khaste.jpg"

    Mat image;
Mat im;
image=imread("khaste.jpg",CV_LOAD_IMAGE_COLOR);
im=imread("kari o behrooz.jpg",CV_LOAD_IMAGE_COLOR);
Rect roi=Rect(150,200,40,60);
Mat image_roi=image(roi);
Mat im_roi=im(roi);

addWeighted(image_roi,.3,im_roi,.7,0,image);

namedWindow("k",1 );
imshow("k",image);
cvWaitKey(0);
return (0);

}

Preview: (hide)

2 answers

Sort by » oldest newest most voted
2

answered Dec 11 '13

Hi there,

if you take a look at the documentation of addWeighted you will see that the last parameter is the output array that will have the same size as the input arrays. This means that by doing

addWeighted(image_roi,.3,im_roi,.7,0,image);

the method addWeighted will deallocate image (because it is not of the same size as the image_roi) and allocate a new array with the same size as image_roi (40x60) and put there the result. Try instead this:

addWeighted(image_roi,.3,im_roi,.7,0,image_roi);

It should do what you want.

I hope this helps.

Preview: (hide)

Comments

yes martin , thanks alot

amin.karimi gravatar imageamin.karimi (Dec 11 '13)edit

Please accept the answer as correct.

Guanta gravatar imageGuanta (Dec 11 '13)edit

martin said true , i should use image_roi as last argument in addweighted

amin.karimi gravatar imageamin.karimi (Dec 11 '13)edit
1

well, then you can mark his answer as correct (the check below the number)

Guanta gravatar imageGuanta (Dec 11 '13)edit
0

answered May 26 '14

Farrakh Javed gravatar image

This is not working for different size images.

Preview: (hide)

Comments

1

It wont work for different size images, according to Documentationsrc2 should be of the same size and channel number as src1, the solution for different sized image may be use ROI on larger image. Also from next time please use post a comment section instead of answer section.

Haris gravatar imageHaris (May 26 '14)edit

Question Tools

Stats

Asked: Dec 10 '13

Seen: 5,075 times

Last updated: May 26 '14