pythonでのエラー
Pythonで以下のコードを実行すると12行目に対して
「ValueError: cannot reshape array of size 12288 into shape (4096,1)」
と出るのですがどなたか原因わかるでしょうか?
import cv2
import numpy as np
img_in = cv2.imread("Parrots.bmp")
cv2.imshow("input", img_in)
# img_out = cv2.GaussianBlur(img_in, (3,3), 0)
# cv2.imshow("Gaussian", img_out)
height, width = 64, 64
img_out = cv2.resize(img_in, (height, width))
x = np.reshape(img_out, (width*height,1)) # 画像のベクトル化
H = np.zeros((width*height, width*height), np.float32)
for i in range(width*height):
if i-width-1 >= 0 and i+width+1 <width*height:
H[i,i-width-1] = 1/16
H[i,i-width] = 2/16
H[i,i-width+1] = 1/16
H[i,i-1] = 2/16
H[i,i] = 4/16
H[i,i+1] = 2/16
H[i,i+width-1] = 1/16
H[i,i+width] = 2/16
H[i,i+width+1] = 1/16
y = np.matmul(H, x)
y = cv2.GaussianBlur(y, (3,3), 0)
cv2.imshow("Gaussian", y)
noise = np.random.normal(0, 1, y.shape)
y = np.clip(y + noise, 0, 255).astype(np.uint8)
gamma = 1e-3
x_estimate = np.linalg.solve(np.matmul(H.T, H) + gamma*np.identity(height*width), np.matmul(H.T, y))
cv2.imshow("x_estimate",x_estimate)