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
A == B returns a logical array with elements set to logical 1 ( true ) where arrays A and B are equal; otherwise, the element is logical 0 ( false ). The test compares both real and imaginary parts of numeric arrays. eq returns logical 0 ( false ) where A or B have NaN or undefined categorical elements.
The ~ operator means logical negation, and the ~= operator means not equals.
tf = isequal( A,B ) returns logical 1 ( true ) if A and B are equivalent; otherwise, it returns logical 0 ( false ).
Description. double is the default numeric data type (class) in MATLAB®, providing sufficient precision for most computational tasks. Numeric variables are automatically stored as 64-bit (8-byte) double-precision floating-point values. For example: x = 10; whos x.
The problem is the type of the matrixes. You are combining two unsigned matrixes. So if Q-I<0
then the result is 0 and it is different from I-Q.
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With