2013-11-28 131 views

回答

1

对于两个画面A,B你把所述的每一个象素和B中的对应像素之间的差的平方,即总和起来,由像素的数量除以它。

伪代码:

sum = 0.0 
for(x = 0; x < width;++x){ 
    for(y = 0; y < height; ++y){ 
     difference = (A[x,y] - B[x,y]) 
     sum = sum + difference*difference 
    } 
} 
mse = sum /(width*height) 
printf("The mean square error is %f\n",mse) 
1

你可以看看下面的文章:http://en.wikipedia.org/wiki/Mean_squared_error#Definition_and_basic_properties。 “Yi”表示真值,“hat_Yi”表示我们想要比较真值的值。

所以,你的情况,你可以考虑一个图像作为参考图像,将其像素值你想用第一个比较形象的第二图像....你通过计算MSE这样做哪些告诉你“第二张图像与第一张图像的差异/相似程度如何”

0

让我们假设你在二维空间A(x1,y1)和B(x2,y2)中有两个点,两点之间的距离是计算为sqrt((x1-x2)^2+(y1-y2)^2)。如果两点在三维空间中,则可以计算为sqrt((x1-x2)^2+(y1-y2)^2+(z1-z2)^2)。对于n维空间中的两点,距离公式可以扩展为sqrt(sumacrossdimensions(valueofAindim-valueofBindim)^2)(因为乳胶是不允许的)。现在

,具有n个像素的图像可以被看作是在n维空间中的点。具有n个像素的两个图像之间的距离可以被认为是n维空间中的2个点之间的距离。这个距离被称为MSE

+0

在均方根误差中没有平方根 – user151496

+0

正如user161496所示。如果你使用平方根,那么你正在计算RMSE(均方根误差) – fmw42

1

检查出MSE维基百科,它的每个像素值之间的差的量度。下面是一个示例实现

def MSE(img1, img2): 
     squared_diff = (img1 -img2) ** 2 
     summed = np.sum(squared_diff) 
     num_pix = img1.shape[0] * img1.shape[1] #img1 and 2 should have same shape 
     err = summed/num_pix 
     return err 
1

概念,那就是:

1) Start with red channel 
2) Compute the difference between each pixel's gray level value in the two image's red channels pixel-by-pixel (redA(0,0)-redB(0,0) etc for all pixel locations. 
3) Square the differences of every one of those pixels (redA(0,0)-redB(0,0)^2 
4) Compute the sum of the squared difference for all pixels in the red channel 
5) Repeat above for the green and blue channels 
6) Add the 3 sums together and divide by 3, i.e, (redsum+greensum+bluesum)/3 
7) Divide by the area of the image (Width*Height) to form the mean or average, i.e., (redsum+greensum+bluesum)/(3*Width*Height) = MSE 


注意,在错误的E是与差的代名词。所以它可以被称为均方差。也意味着与平均水平相同。所以它也可以称为平均平方差。