Ask Your Question

Intersection of two images

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

infoclogged gravatar image

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

I have two images of unequal size -

image description


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

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

LBerger gravatar image

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

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

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


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 -0500 )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 -0500 )edit
Login/Signup to Answer

Question Tools

1 follower


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

Seen: 40 times

Last updated: Aug 31 '18