假设我有量化函数来量化8位灰度图像:
function mse = uni_quan(I, b)
   Q = I / 2 ^ (8 - b);
   Q = uint8(Q);
   Q = Q * 2 ^ (8 - b);
   mse = sum(sum((I - Q) .^ 2, 1), 2) / numel(I);
end
此功能对图像执行均匀量化I并将其转换为b位图像,然后在0-255范围内缩放,现在我想计算此过程的    MSE(均方误差)
但结果是
mse = sum(sum((I - Q) .^ 2, 1), 2) / numel(I);
和
mse = sum(sum((Q - I) .^ 2, 1), 2) / numel(I);
是不同的.任何人都可以请指出我的问题是什么?
谢谢
问题是矩阵的类型.您正在组合两个无符号矩阵.那么如果Q-I<0那时结果是0并且它与IQ不同.
要使用uint8,您可以分两步计算MSE:
%Compute the absolute difference, according to the sign
difference = Q-I;
neg_idx = find(I>Q);
difference(neg_idx) = I(neg_idx)-Q(neg_idx);
%Compute the MSE
mse = sum(sum((difference) .^ 2, 1), 2) / numel(I);