I am working on a python script to embed a watermark in an image using Singular Value Decomposition and Discrete Wavelet Transform. However, when running the script, I get the Error "shapes (504,504) and (378,378) not aligned: 504 (dim 1) != 378 (dim 0)". What did i wrong and how can i solve this problem?
import cv2
import numpy as np
from matplotlib import pyplot as plt
import pywt
alpha = 0.75
picture_path=r'....'
I = cv2.imread(picture_path, cv2.IMREAD_GRAYSCALE)
plt.figure(1)
plt.imshow(I, cmap='gray')
plt.title('The image in which we insert watermark')
plt.show()
LL1, (HL1, LH1, HH1) = pywt.dwt2(I, 'haar')
LL2, (HL2, LH2, HH2) = pywt.dwt2(LL1, 'haar')
p = LL2.shape
Uy, Sy, Vy = np.linalg.svd(LL2)
q = Sy.shape
watermark_path = r'....'
I_w = cv2.imread(watermark_path, cv2.IMREAD_GRAYSCALE)
I1_w = cv2.resize(I_w, (p[1], p[0]))
plt.figure(2)
plt.imshow(I1_w, cmap='gray')
plt.show()
Uw, Sw, Vw = np.linalg.svd(I1_w.astype(float))
Smark = Sy + alpha * Sw
LL2_1 = Uy.dot(np.diag(Smark)).dot(Vy) #here i got the error
#...