Ask Your Question
1

addweighted for mix of two image

asked 2013-12-10 17:05:34 -0600

amin.karimi gravatar image

updated 2013-12-10 17:17:18 -0600

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);

}

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
2

answered 2013-12-10 22:58:59 -0600

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.

edit flag offensive delete link more

Comments

yes martin , thanks alot

amin.karimi gravatar imageamin.karimi ( 2013-12-11 00:21:11 -0600 )edit

Please accept the answer as correct.

Guanta gravatar imageGuanta ( 2013-12-11 08:33:16 -0600 )edit

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

amin.karimi gravatar imageamin.karimi ( 2013-12-11 10:20:55 -0600 )edit
1

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

Guanta gravatar imageGuanta ( 2013-12-11 11:39:23 -0600 )edit
0

answered 2014-05-26 02:48:31 -0600

Farrakh Javed gravatar image

This is not working for different size images.

edit flag offensive delete link more

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 ( 2014-05-26 04:06:04 -0600 )edit

Question Tools

Stats

Asked: 2013-12-10 17:05:34 -0600

Seen: 4,947 times

Last updated: May 26 '14