Suppose I have a quantization function which quantize a 8bit gray scale image :
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
This function perform a uniform quantization on image I
and convert it into a b
bit image, then scale it in 0-255 range, Now I want to calculate MSE (Mean Square Error) of this process
But the result for
mse = sum(sum((I - Q) .^ 2, 1), 2) / numel(I);
and
mse = sum(sum((Q - I) .^ 2, 1), 2) / numel(I);
is different. Can anyone please point me out whats the problem?
Thanks
The problem is the type of the matrixes. You are combining two unsigned matrixes. So if QI<0
then the result is 0 and it is different from IQ.
In order to use uint8
, you can compute MSE in two steps:
%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);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.