Nejc Galof
Nejc Galof

Reputation: 2606

Averaging of two images with mask

I have two image like this:

left image right image

I create two mask, which show me position of each image on scene.

left mask right mask

I create mask which show me intersection of two images.

bitwise and mask

I create intersection mask with cv::bitwise_and(mask_left, mask_right, mask_intersection);

I want adding two images together. Where pixels of mask_intersection is white, I want use average value of pixels on both images. Here is result, where I just add one image on another. The problem is sharp border, which I want to solve with averaging of both images only on mask_intersection.

panorama

I don't know how to solve this problem the easiest way.

Upvotes: 1

Views: 337

Answers (2)

Sunreef
Sunreef

Reputation: 4542

For averaging the two images where the mask intersect, you could use copyTo.

Supposing you have maskIntersection, image1, image2 and finalImage, the code would look something like:

((image1 + image2) * 0.5).copyTo(finalImage, maskIntersection)

Even though this answers your question of averaging the two images, I don't think it will provide very good results. Blending two images together is usually a more involved process. Take a look at this class to have a quick overview of what is required.

Upvotes: 2

Rama
Rama

Reputation: 3305

Te process you are loocking for is called blending, and you can achieve it using cv::addWeighted(), then just multiply the result by the mask to cut off zones of the image that you don´t want to blend.

Upvotes: 0

Related Questions