OpenCV Python Tutorial
OpenCV Python Resources
Selected Reading
- OpenCV Python - Digit Recognition
- OpenCV Python - Feature Matching
- OpenCV Python - Feature Detection
- OpenCV Python - Meanshift/Camshift
- OpenCV Python - Face Detection
- OpenCV Python - Video from Images
- OpenCV Python - Images From Video
- OpenCV Python - Play Videos
- OpenCV Python - Capture Videos
- OpenCV Python - Fourier Transform
- OpenCV Python - Image Blending
- OpenCV Python - Image Addition
- OpenCV Python - Image Pyramids
- OpenCV Python - Template Matching
- OpenCV Python - Image Contours
- OpenCV Python - Transformations
- OpenCV Python - Color Spaces
- OpenCV Python - Histogram
- OpenCV Python - Edge Detection
- OpenCV Python - Image Filtering
- OpenCV Python - Image Threshold
- OpenCV Python - Resize and Rotate
- OpenCV Python - Add Trackbar
- OpenCV Python - Mouse Events
- OpenCV Python - Shapes and Text
- OpenCV Python - Bitwise Operations
- OpenCV Python - Image Properties
- OpenCV Python - Using Matplotlib
- OpenCV Python - Write Image
- OpenCV Python - Reading Image
- OpenCV Python - Environment
- OpenCV Python - Overview
- OpenCV Python - Home
OpenCV Python Resources
Selected Reading
- Who is Who
- Computer Glossary
- HR Interview Questions
- Effective Resume Writing
- Questions and Answers
- UPSC IAS Exams Notes
OpenCV Python - Image Blending
OpenCV Python - Image Blending with Pyramids
The discontinuity of images can be minimised by the use of image pyramids. This results in a seamless blended image.
Following steps are taken to achieve the final result −
First load the images and find Gaussian pyramids for both. The program for the same is as follows −
import cv2 import numpy as np,sys kalam = cv2.imread( kalam.jpg ) einst = cv2.imread( einstein.jpg ) ### generate Gaussian pyramid for first G = kalam.copy() gpk = [G] for i in range(6): G = cv2.pyrDown(G) gpk.append(G) # generate Gaussian pyramid for second G = einst.copy() gpe = [G] for i in range(6): G = cv2.pyrDown(G) gpe.append(G)
From the Gaussian pyramids, obtain the respective Laplacian Pyramids. The program for the same is as follows −
# generate Laplacian Pyramid for first lpk = [gpk[5]] for i in range(5,0,-1): GE = cv2.pyrUp(gpk[i]) L = cv2.subtract(gpk[i-1],GE) lpk.append(L) # generate Laplacian Pyramid for second lpe = [gpe[5]] for i in range(5,0,-1): GE = cv2.pyrUp(gpe[i]) L = cv2.subtract(gpe[i-1],GE) lpe.append(L)
Then, join the left half of the first image with the right half of second in each level of pyramids. The program for the same is as follows −
# Now add left and right halves of images in each level LS = [] for la,lb in zip(lpk,lpe): rows,cols,dpt = la.shape ls = np.hstack((la[:,0:int(cols/2)], lb[:,int(cols/2):])) LS.append(ls)
Finally, reconstruct the image from this joint pyramid. The program for the same is given below −
ls_ = LS[0] for i in range(1,6): ls_ = cv2.pyrUp(ls_) ls_ = cv2.add(ls_, LS[i]) cv2.imshow( RESULT ,ls_)
Output
The blended result should be as follows −
Advertisements