评价图像模糊度的经典指标的matlab代码
时间: 2024-01-30 21:02:08 浏览: 68
图像模糊度是图像质量的一个重要指标,可以使用多种经典指标进行评价。以下是常用的几种指标及其 MATLAB 代码实现:
1. 均方误差(MSE):
```
function mse_value = mse(image, blur_image)
[m, n] = size(image);
mse_value = sum(sum((double(image) - double(blur_image)).^2)) / (m * n);
end
```
2. 峰值信噪比(PSNR):
```
function psnr_value = psnr(image, blur_image)
mse_value = mse(image, blur_image);
psnr_value = 10 * log10(255^2 / mse_value);
end
```
3. 结构相似性指数(SSIM):
```
function ssim_value = ssim(image, blur_image)
k1 = 0.01;
k2 = 0.03;
L = 255;
[m, n] = size(image);
image = double(image);
blur_image = double(blur_image);
mu1 = filter2(fspecial('gaussian', 11, 1.5), image, 'same');
mu2 = filter2(fspecial('gaussian', 11, 1.5), blur_image, 'same');
mu1_sq = mu1.^2;
mu2_sq = mu2.^2;
mu1_mu2 = mu1 .* mu2;
sigma1_sq = filter2(fspecial('gaussian', 11, 1.5), image.^2, 'same') - mu1_sq;
sigma2_sq = filter2(fspecial('gaussian', 11, 1.5), blur_image.^2, 'same') - mu2_sq;
sigma12 = filter2(fspecial('gaussian', 11, 1.5), image .* blur_image, 'same') - mu1_mu2;
C1 = (k1 * L)^2;
C2 = (k2 * L)^2;
ssim_map = ((2 * mu1_mu2 + C1) .* (2 * sigma12 + C2)) ./ ((mu1_sq + mu2_sq + C1) .* (sigma1_sq + sigma2_sq + C2));
ssim_value = mean2(ssim_map);
end
```
以上三种指标都是越大越好,因此在比较图像模糊度时,数值越大则表示图像越清晰。
阅读全文