Why (A - B) .^ 2 is not equal to (B - A) .^ 2 in MATLAB? -


suppose have quantization function quantize 8bit gray scale image :

function mse = uni_quan(i, b)    q = / 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 uniform quantization on image i , convert b bit image, scale in 0-255 range, want calculate mse (mean square error) of process

but 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 please point me out whats problem?
thanks

the problem type of matrixes. combining 2 unsigned matrixes. if q-i<0 result 0 , different i-q.

in order use uint8, can compute mse in 2 steps:

%compute absolute difference, according sign difference = q-i; neg_idx = find(i>q); difference(neg_idx) = i(neg_idx)-q(neg_idx);  %compute mse mse = sum(sum((difference) .^ 2, 1), 2) / numel(i); 

Comments

Popular posts from this blog

c# - How to get the current UAC mode -

postgresql - Lazarus + Postgres: incomplete startup packet -

javascript - Ajax jqXHR.status==0 fix error -