skip to Main Content

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.

2

Answers


  1. 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.

    Login or Signup to reply.
  2. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search