PSNR和SSIM和MSEmatlab实现
时间: 2024-01-29 13:04:39 浏览: 98
PSNR和SSIM是图像质量评价指标,MSE是PSNR的计算基础。下面是Matlab代码实现:
1. MSE计算:
```matlab
function mse_value = mse(image1,image2)
% image1和image2分别为待比较的两幅图像
% mse_value为两幅图像的均方误差MSE
image1 = double(image1);
image2 = double(image2);
[m,n] = size(image1);
mse_value = sum(sum((image1-image2).^2))/(m*n);
end
```
2. PSNR计算:
```matlab
function psnr_value = psnr(image1,image2)
% image1和image2分别为待比较的两幅图像
% psnr_value为两幅图像的峰值信噪比PSNR
mse_value = mse(image1,image2);
psnr_value = 10*log10(255^2/mse_value);
end
```
3. SSIM计算:
```matlab
function ssim_value = ssim(image1,image2)
% image1和image2分别为待比较的两幅图像
% ssim_value为两幅图像的结构相似性SSIM
K1 = 0.01;
K2 = 0.03;
L = 255;
C1 = (K1*L)^2;
C2 = (K2*L)^2;
image1 = double(image1);
image2 = double(image2);
[m,n] = size(image1);
mu1 = filter2(fspecial('gaussian', 11, 1.5), image1, 'valid');
mu2 = filter2(fspecial('gaussian', 11, 1.5), image2, 'valid');
mu1_sq = mu1.*mu1;
mu2_sq = mu2.*mu2;
mu1_mu2 = mu1.*mu2;
sigma1_sq = filter2(fspecial('gaussian', 11, 1.5), image1.*image1, 'valid') - mu1_sq;
sigma2_sq = filter2(fspecial('gaussian', 11, 1.5), image2.*image2, 'valid') - mu2_sq;
sigma12 = filter2(fspecial('gaussian', 11, 1.5), image1.*image2, 'valid') - mu1_mu2;
numerator = (2*mu1_mu2+C1).*(2*sigma12+C2);
denominator = (mu1_sq+mu2_sq+C1).*(sigma1_sq+sigma2_sq+C2);
ssim_value = mean(mean(numerator./denominator));
end
```
上述代码中,使用了高斯滤波和加权系数等方法进行图像评价,具体细节可以参考SSIM的论文。
阅读全文