-1

I have seen many tutorials that people blend two images that are placed on top of each other very nicely in Photoshop. For example here are two images that are placed on top of each other:

enter image description here

Then in Photoshop after some work, the edges (around the smaller image) will be erased and two images are nicely mixed. For example, this is a possible end result:

enter image description here

As it can be seen there is no edge and two images are very nicely blended, without blurring.

Can someone point me to any article or post that shows the math behind it? If there is a MATLAB code that can do it, that would be even better. Or at least if someone can tell me what is the correct term for this so I can do Google search on the topic.

TJ1
  • 7,578
  • 19
  • 76
  • 119
  • For that example above that's a custom alpha mask. look at the way the guy's should disappears compared to the way their hair at the top of the image is blended - it differs on the left hand side of the image compared to the right. – Ghoul Fool Jul 27 '17 at 19:10

2 Answers2

1

Straight alpha blending alone is not sufficient, as it will perform a uniform mixing of the two images.

To achieve nice-looking results, you will need to define an alpha map, i.e. an image of the same size where you adjust the degree of transparency depending on the image that should dominate.

To obtain the mask, you can draw it by hand, for example as a filled outline, as a path or a polygon. Then you have to strongly blur this mask to get a smooth blend.

It looks very difficult (if not impossible) to automate this, as no software can guess what you want to enhance.

  • thanks for the answer. Can you please point me to a website or blog post to explain this in more details? I just need to have a band around the smaller photo and blend the two photos. – TJ1 Jul 25 '17 at 13:04
0

The term you are looking for is alpha blending. https://en.wikipedia.org/wiki/Alpha_compositing#Alpha_blending

The maths behind it boils down to some alpha weighted sums.

Matlab provides the function imfuse to achieve this: https://de.mathworks.com/help/images/ref/imfuse.html

Edit: (as it still seems to be unclear)

Let's say you have 2 images A and B wich you want to blend.

You put one image over the other so for each coordinate you have 2 RGB touples. Now you need to define the weight of both images. Will you only see the colour of image A or B or which ratio will you choose to mix them? This is done by alpha values.

So all you need is a 2d function that defines the mixing ratio for each pixel. Usually you have values between 0 and 1 where 0 shows one image, 1 shows the other image, 0.5 will mix them both equally and so on...

Just read the article I have linked. It gives you a clear mathematical definition. I can't provide more detail than that.

If you have problems understanding that I urge you to read a book on image processing fundamentals.

Piglet
  • 27,501
  • 3
  • 20
  • 43
  • Thanks for the answer, let me look into it to make sure this is exactly what I am looking for. – TJ1 Jul 25 '17 at 06:20
  • I am looking for a way to apply it to a band of let's say X pixels around the inner (smaller) image when two images are overlayed. Is there any known algorithm for doing that? – TJ1 Jul 25 '17 at 06:29
  • @TJ1 it's the same thing. you just need to set your alphas properly – Piglet Jul 25 '17 at 06:53
  • can you please point me to a resource that explains how exactly to do this in 2-D? – TJ1 Jul 25 '17 at 13:05