开发者

Logical Error when calculating mean square error

开发者 https://www.devze.com 2023-02-17 21:48 出处:网络
a=imread(\'pic1.jpg\'); b=0.25*a; c=4.0*b; f开发者_JAVA技巧igure; imshow(c); MSE = reshape(mean(mean(((a) - (c)).^2,2),1),[1,3])
a=imread('pic1.jpg');
b=0.25*a;
c=4.0*b;
f开发者_JAVA技巧igure;
imshow(c);
MSE = reshape(mean(mean(((a) - (c)).^2,2),1),[1,3])

Code works fine without any errors. Size of a is 256*256*3 RGB type. However, There are 2 issues :

  1. Now logically, the MSE should have been zero for RGB bands since multiplying the result c with 4.0 should reverse the operation. But MSE is coming out to be 1.1361 1.2780 1.2902 The same is observed when testing with b=0.27.*a; then c=3.703703704.*b;
  2. In MSE formula, on removing double data type , the error minimises to 0.5346 0.6132 0.6275

Can anyone explain it lucidly why this is happening and what is the remedy?


Have a look at the data type of your variable a. It is probably a uint8, which means b also becomes uint8 containing rounded values - in other words you loose two bits of information per pixel.

You mention "double data type", but I don't see where you use it in your code.

If you started with a=double(imread('pix1.jpg')); then your MSE should nearly zero (I'd expect it to be on the order of 256*256*3*eps (i.e. rounding error)).

0

精彩评论

暂无评论...
验证码 换一张
取 消