# Blending Images

## Introduction

The discussion of color maps in the previous tutorial is useful to work on the changing of images into various color formats. In this tutorial, we shall look into the blending images that is placing one image on another image.

## Blending two different Images

Let us work on our Jupyter notebook, to blend two different images.

Initially, import the OpenCV library and Matplotlib library to work on this operation of blending images.

Let us read into different images and store them accordingly by converting them into a suitable colour format.

Now, we can obtain the image shape and the orientation of the blending images.

As the shape of the two images are quite different and are irregular. To blend the images in the proper manner, we need to transform them into a reliable size. This method of blending images might cause the change in the image sizes that may lead to the improper aspect ratio of the image. For the better aspect ratio, we shall transform the images into the size ratio of (1200,1200) pixels.

The blending of one image on another can be done by adjusting the brightness level of the images that is by adding the weight to each particular image.

Here we can blend the images with the same weights and the image looks as displayed below.

The other method to blend the images, without changing the size is by overlaying the small image on top of the large image without blending completely using the NumPy array operations.

We shall store the offset value of a small image for both the x and y coordinates and add them accordingly to the larger image. Then the Numpy slicing has to be done for the Numpy array of the larger image, to replace some part of the larger image with the smaller image array values.

Finally, after slicing you can display the blended image.

Now, we shall look into the masking of the two images. That is to blend only the specific pixels of one image on to another image. For that let us take two images of similar shape.

Then you need to convert the image into the grayscale format.

Now, you need to invert the colors black and white to ensure the masking to be done.

Now, you need to highlight the white area values in the NumPy array and need to highlight the area which is present in the white color and that is to be masked on to another image.

The part of the image with the white color values has been highlighted with the red color highlighting the region of interest that is to be masked on to the new image. Now finally, you need to blend the highlighted part of the image on to another image.

Finally, we have successfully overlaid the part of the image on to another image successfully.

This is all about the end of this tutorial. Although the concepts in this tutorial are quite complex and can be performed using other applications also. The blending of the images and the masking of the images are very much important operations on the images. For any sort of doubts or the questions in this tutorial, you can reach out through the comment box.

Related Tutorials

Color Maps

Draw Geometric Shapes using OpenCV

### 2 thoughts on “Blending Images”

1. In image blending, try to elaborate on the function,