Witam!
Mam tutaj problem z wyliczeniem współczynnika MSE dla dwóch map głębokości. Kod wygląda w ten sposób:
import numpy as np
import cv2 as cv
from matplotlib import pyplot as plt
def mse(imageA, imageB):
err = np.sum((imageA.astype("float") - imageB.astype("float")) ** 2)
err /= float(imageA.shape[0] * imageA.shape[1])
print(err)
return err
imgL = cv.imread('tsukuba1.ppm',0)
imgR = cv.imread('tsukuba2.ppm',0)
imgD = cv.imread('tsukuba_disp.pgm')
#Tworzenie mapy głębokości
stereo = cv.StereoBM_create(numDisparities=16, blockSize=15)
disparity = stereo.compute(imgL,imgR)
plt.imshow(disparity,'gray')
plt.show()
#Filtr Gaussa
blur = cv.GaussianBlur(disparity,(5,5),0)
plt.imshow(blur,'gray')
#plt.show()
#Filtr medianowy
median = cv.medianBlur(disparity, 5)
plt.imshow(median,'gray')
#plt.show()
#Filtr Weighted Least Squares
wsize=31
max_disp = 16
sigma = 5
lmbda = 8000.0
left_matcher = cv.StereoBM_create(max_disp, wsize)
right_matcher = cv.ximgproc.createRightMatcher(left_matcher)
left_disp = left_matcher.compute(imgL, imgR)
right_disp = right_matcher.compute(imgR,imgL)
wls_filter = cv.ximgproc.createDisparityWLSFilter(left_matcher)
wls_filter.setLambda(lmbda)
wls_filter.setSigmaColor(sigma)
filtered_disp = wls_filter.filter(left_disp, imgL, disparity_map_right=right_disp)
plt.imshow(filtered_disp,'gray')
#plt.show()
mse(imgD, disparity)
Niestety po uruchomieniu programu otrzymuję następujący błąd:
Traceback (most recent call last):
File "E:/Dodatkowe/Depth_map/depth_map.py", line 50, in <module>
mse(imgD, disparity)
File "E:/Dodatkowe/Depth_map/depth_map.py", line 7, in mse
err = np.sum((imageA.astype("float") - imageB.astype("float")) ** 2)
ValueError: operands could not be broadcast together with shapes (288,384,3) (288,384)
Czy ktoś może mi pomóc co mam zrobić aby funkcja nie wyrzucała tego błędu i poprawnie liczyła MSE? Uprzedzając odpowiedzi szukałem już w internecie, czytałem nawet na Stcku o podobnych problemach, ale nic nie rozumiem z tłumaczeń w stylu "If X and beta do not have the same shape as the second term in the rhs of your last line (i.e. nsample), then you will get this type of error. To add an array to a tuple of arrays, they all must be the same shape."
Bardzo proszę o jakąś pomoc!