1

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.

Nejc Galof
  • 2,538
  • 3
  • 31
  • 70
  • have a look at my answers in https://stackoverflow.com/questions/22315904/blending-does-not-remove-seams-in-opencv/22324790#22324790 using linear crossblending – Micka Nov 16 '17 at 18:35

2 Answers2

2

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.

Sunreef
  • 4,452
  • 21
  • 33
  • I see this not give very good results, but thank you for answer on my question and link for what is required. – Nejc Galof Nov 16 '17 at 16:10
  • We cannot just add because of overflow. Here is [link](http://answers.opencv.org/question/42911/solved-how-to-average-n-matrices-into-1/?answer=42917#post-id-42917) how accumulate this two images. Other code is work :) – Nejc Galof Nov 16 '17 at 16:27
  • you should convert the mats to avoid overflow https://stackoverflow.com/questions/26591889/how-to-convert-16-bit-image-to-32-bit-image-in-opencv – Duloren Nov 16 '17 at 16:51
0

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.

Rama
  • 3,222
  • 2
  • 11
  • 26