applying AddWeighted algorithm to two image

asked 2020-01-10 14:36:34 -0500

dato gravatar image

i have read two image from skimage library, then i have resized these two image so they have same size, there is code for it import matplotlib.pyplot as plt

import cv2
import skimage
from skimage import data
from skimage import io
from  skimage.transform import resize
from google.colab.patches import cv2_imshow
image1 =data.logo()
image1_gray = cv2.cvtColor(image1, cv2.COLOR_BGR2GRAY)
imag2 =data.rocket()
imag2_gray =cv2.cvtColor(imag2,cv2.COLOR_BGR2GRAY)
imag2_gray =resize(imag2_gray,(image1_gray.shape[0],image1_gray.shape[1]))

then i have tried to apply algorithm

alpha = 0.30
beta = 0.70
#Blend images
final_image = cv2.addWeighted(image1_gray, alpha, imag2_gray, beta, 0.0)

but i got following error :

error: OpenCV(4.1.2) /io/opencv/modules/core/src/arithm.cpp:687: error: (-5:Bad argument) When the input arrays in add/subtract/multiply/divide functions have different types, the output array type must be explicitly specified in function 'arithm_op'

please help me how to fix it

edit retag flag offensive close merge delete


it''s complaining about image1_gray and image2_gray having different type. can you check ?

berak gravatar imageberak ( 2020-01-11 02:28:24 -0500 )edit