Ask Your Question
0

Intersection of two images

asked 2018-08-31 04:03:45 -0600

infoclogged gravatar image

updated 2018-08-31 04:04:44 -0600

I have two images of unequal size -

image description

and

image description

Is there any way that I can get the intersection of the two images such that the final image is

image description

The size of the final image is the same as the size of the ellipse..Maybe pictorally the size doesnt look the same here. The center of the images coincide.

edit retag flag offensive close merge delete

1 answer

Sort by ยป oldest newest most voted
3

answered 2018-08-31 04:12:44 -0600

LBerger gravatar image

updated 2018-08-31 05:02:53 -0600

Answer is no. To get intersection a mask must be used. Then you can use (example) copyTo. but it is written :

Operation mask of the same size as *this. Its non-zero elements indicate which matrix elements need to be copied. The mask has to be of type CV_8U and can have 1 or multiple channels.

You must copy mask is an image with a size equal to original image example :

Mat img;
Mat mask(img.size(),CV_8UC1,Scalar(0));
Mat smallerMask;
....
Point p(10,10);
smallerMask.copyTo(mask(rect(p,smallerMask.size()));

You must choose P location and check is rect(p,smallerMask.size()) is not outside of img image

PS code is not tested

edit flag offensive delete link more

Comments

this line is not clear - You must copy mask is an image with a size equal to original image example :

infoclogged gravatar imageinfoclogged ( 2018-08-31 09:02:52 -0600 )edit

it means that if your original image is 500x500 pixels, the mask also has to be 500x500 pixels, instead of for example 250x400 pixels.

StevenPuttemans gravatar imageStevenPuttemans ( 2018-09-03 06:45:49 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2018-08-31 04:03:45 -0600

Seen: 2,288 times

Last updated: Aug 31 '18