skimage的mean_squared_error和numpy计算不一致,相差很大
image1 = cv2.imread(“images/secret.png”)
image2 = cv2.imread(“images/mirage_tank_unstego.png”)
原来的代码:
mse = mean_squared_error(image_true, image_test)
#或者
mse = np.mean((image_true - image_test) ** 2)
修改之后的代码:
mse = mean_squared_error(image_true, image_test)
#或者
mse = np.mean((image_true.astype(float) - image_test.astype(float)) ** 2)
错因:
默认情况下,OpenCV 读取的图像数组的数据类型是 uint8,即无符号8位整数。这意味着每个像素的值范围在 0 到 255 之间。
所以相减值之后的值限定在0-255,所以用astype(float)转成float就好了
参考链接:
https://stackoverflow.com/questions/52799031/skimage-measure-produce-strangely-high-mean-square-error