[英]Why (A - B) .^ 2 is not equal to (B - A) .^ 2 in MATLAB?
假設我有量化函數來量化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);
是不同的。 任何人都可以請指出我的問題是什么?
謝謝
問題是矩陣的類型。 您正在組合兩個無符號矩陣。 因此,如果QI<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);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.