1

How might I go about compositing:

image A (8x8 RGB) with top left corner at (0,0).  
image B (4x4 RGB) with top left corner at (6,6).

By simply adding RGB values?

I guess I need to start by creating a (black) RGB canvas of size (10,10), and add each image at its respective location.

But how to accomplish that second step?

Now what if the offset is (6.3, 6.3)? Is there a technique that handles sub-pixel superposition?

EDIT: cvSetImageROI maybe?

P i
  • 29,020
  • 36
  • 159
  • 267
  • 1
    to handle blending there are different techniques, often used are simple constant blending (like addWeighted with factor 0.5) oder linear cross-blending in overlapping parts. Have a look at my answer in https://stackoverflow.com/questions/22315904/blending-does-not-remove-seams-in-opencv/22324790#22324790 on how some kind of linear cross-blending could be used/solved. To "correct" some subpixel offset you can use image warping, which will use interpolation. This could correct some offset in rotation and scale, too. – Micka Jun 09 '17 at 11:14
  • @Micka some excellent answers on that post! – alkasm Jun 09 '17 at 11:16

1 Answers1

3

Why not use addWeighted() to blend the images? You can create an ROI in the larger image the same size as the smaller image, and just add the result there.

You cannot do sub-pixel accuracy with built-in functions that I know of. What would the result at pixel (6,6) be if you added an image that was only partially covering it? Would you want it weighted by the amount of overlap there is? And what about the pixel (7,7)? In this case there would be four pixels crossing over; should each addition be weighted by the amount of overlap?

If you do want those pixels weighted as such, it would not be too difficult to define your own method, but it would be a little tedious as you'd have many cases: the corners, the sides, and the insides would each have different weightings.

alkasm
  • 22,094
  • 5
  • 78
  • 94