Ask Your Question
1

overlay image with offset

asked 2014-08-21 05:34:11 -0500

borjaevo gravatar image

Hi,

I'm trying to get a function that do this. I attached and image to explain you. Have two images of same type and size, that are blue and green. I want to overlay the green image over the blue with an offset, in this case x and y are negative and only overlay the part of the image that is in common coordinates (red area). Are there an easy way to do this?

image description

edit retag flag offensive close merge delete

Comments

You can create mask for red region and use this mask for overlay. For creating mask, threshold both green and blue and perform bitwise_and on results.

Haris gravatar imageHaris ( 2014-08-21 07:18:15 -0500 )edit

maybe i have not explained well, sorry for my english. Colors are an example, blue and green are source images, and dst is blue with a part of green image overlayed (red area) in this case (negative offset).

borjaevo gravatar imageborjaevo ( 2014-08-21 10:47:02 -0500 )edit

So how will you decide the portion green overplayed on blue, do you have co-ordinates for it?

Haris gravatar imageHaris ( 2014-08-21 11:12:57 -0500 )edit

Yes, coordinates are obtained from another device. If the with of both images is 640pixels my x offsets values can be from -640 to 640. With other values images are not overlayed. In the example, x offset can be about -400pixels. if offset is 0, images are completely width overlayed Thank you.

borjaevo gravatar imageborjaevo ( 2014-08-21 12:05:55 -0500 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2014-08-23 09:21:43 -0500

Haris gravatar image

You can use ROI to overly the source on destination.

Assume you got the co-ordinates like

int x= //overlay x
int y= //overlay y
int width = //overlay width
int height = //overlay height

Mat green; // source image.
Mat blue; //destination image.
Mat ROI1=green(Rect(x,y,width,height));//Apply RIO on source image from which overlay portion taken.
Mat ROI2 = blue(0,0,width,height);// assume you have to apply overlay from (0,0).
ROI1.copyTo(ROI2)// copy overlay to destination
edit flag offensive delete link more
Login/Signup to Answer

Question Tools

Stats

Asked: 2014-08-21 05:34:11 -0500

Seen: 1,766 times

Last updated: Aug 23 '14