Skip to main content

Opencv Image Blending: How to blend two images?

Opencv Image Blending

This process is very similar to image addition, but in this process images are given different weights. Thus, a transparent mixture is obtained. Images are added according to the following equation:

𝑔(π‘₯) = (1 − 𝛼)𝑓0(π‘₯) + 𝛼𝑓1(π‘₯)

By changing the value of a between 0 and 1, transparency can be adjusted. In this study, 2 images were used to put them together. The weight was given 0.3 to the first picture and 0.7 to the second picture. cv2.addWeighted () applies the following equation to the image.

𝑑𝑠𝑑 = 𝛼 · π‘–π‘šπ‘”1 + 𝛽 · π‘–π‘šπ‘”2 + y

Open images:

image1 = cv2.imread('flower.jpg')
image2 = cv2.imread('bird.jpg')

rs = cv2.addWeighted(image1, 0.3, image2, 0.7, 0.0);


All Code:

import cv2

image1 = cv2.imread('flower.jpg')
image2 = cv2.imread('bird.jpg')

image1 = cv2.resize(image1, (300, 300))
image2 = cv2.resize(image2, (300, 300))

rs = cv2.addWeighted(image1, 0.3, image2, 0.7, 0.0);

cv2.imshow('blend', rs)
cv2.imshow('img1', image1)
cv2.imshow('img2', image2)



Popular posts from this blog

OpenCV Capture Image From Camera

Capture Image From Camera Using OpenCV, you can capture video from your computer's webcam and use these videos for many purposes. OpenCV provides a very simple interface for video capture process. It takes preparation to capture video. To capture a video, you must create a VideoCapture object. Its argument may be the device index. capture = cv2.VideoCapture( 0 )   The device index is just the number that determines which camera to use. Normally 0 is selected if a camera will be connected. You can select the second camera by giving a value of 1. After that, you can shoot frame by frame. ret , frame = () returns a bool value. If the frame reads correctly, the value will be True. With the Cap.isOpened () method, you can check whether the video capture process is started. If it's true, it's okay. If not, you need to open it using (). The codes are all as follows: import cv2 capture = cv2.VideoCapture( 0 ) while ( True ):   # C

Show OpenCV Image With Matplotlib

Show Image With Matplotlib Matplotlib is a drawing library that offers a wide variety of drawing methods for Python. Matplotlib; The basic python library we use in data visualization. It allows us to make 2 and 3 dimensional drawings. In order to use Matplotlib, we need to add it to our project as follows: from matplotlib import pyplot as plt The image is read as follows: img = cv2.imread( 'bird.jpg' )   Finally, the captured image is displayed on the screen with the following code: plt.imshow(img) plt.xticks([]) , plt.yticks([]) Code and output are as follows: import cv2 from matplotlib import pyplot as plt img = cv2.imread( 'bird.jpg' ) plt.imshow(img) plt.xticks([]) , plt.yticks([]) Output:  

Opencv Image Properties - rows, columns and channels, type of image data, number of pixels

Opencv Image Properties  OpenCV allows access to image properties. These properties are rows, columns and channels, type of image data, number of pixels. The img.shape command is used to access the shape of the image. Returns rows, columns and channels. import  cv2 img = cv2.imread( 'flower.jpg' ) print (img.shape) Result: (400, 400, 3) The data type of the image is obtained with img.dtype import cv2 img = cv2.imread( 'flower.jpg' ) print (img.dtype) Result: uint8