OpenCV is a Computer Vision library that helps you manipulate images and videos in a way of doing different processing techniques over them.
In this post, we are going to show you, how can you blend images, in order to create one image from a few others. Before reading this post about blend images, here we have another one about barcode detection using OpenCV.
Also, here is how to cartoonize a live video footage using Computer Vision.
The Image Blending Problem
In this post, we are going to use two pictures, and we are going to blend them into one picture. We are going to use Gaussian and Laplacian pyramids in order to resize the images.
An image pyramid is a collection of images, which arise from one source i.e. one original image. In order to create a pyramid, we need to downsample the source image until some desired stopping point is reached.
There are two types of image pyramids: Gaussian pyramid (Used to downsample images) and Laplacian pyramid (Used to reconstruct an upsampled image from an image lower in the pyramid (with less resolution)).
In our example, we are going to use both of these types of pyramids. With the Gaussian, we are going to downsample our images so later we can reconstruct them in order to lose some of their resolutions and their colors look more similar to others.
Now we reconstruct the image, in order to get the result.
We can also blend images by just directly connecting the two images, with the code below.
As we can see the result of the direct blending is not nearly precise as the result we get by applying Gaussian and Laplacian pyramid.
If you want to see a video tutorial of this problem, we suggest you check this YouTube video.
This post is an example of how can you manipulate images by creating one image you like from a few others, by using programming code instead of some graphics editors like Photoshop or Gimp.
OpenCV is a very popular and powerful Computer Vision library, and we have other posts where we showcase examples of image processing using this library.
Don’t forget to read other related articles:
- Learn How To Do K-Means Clustering On An Image
- Finance with Python: Convex Optimization
- Finance with Python: Monte Carlo Simulation (The Backbone of DeepMind’s AlphaGo Algorithm)
Like with every post we do, we encourage you to continue learning, trying and creating.