写一个计算PSNR值的MATLAB函数
时间: 2024-05-13 11:18:50 浏览: 84
以下是计算PSNR值的MATLAB函数:
```
function psnr_value = calculate_psnr(original_image, processed_image)
% Calculate PSNR value between two images
% Convert images to double precision
original_image = im2double(original_image);
processed_image = im2double(processed_image);
% Calculate MSE
mse_value = mean(mean((original_image - processed_image).^2));
% Calculate maximum pixel value
max_pixel_value = max(original_image(:));
% Calculate PSNR value
psnr_value = 10*log10(max_pixel_value^2/mse_value);
end
```
使用方法:
将原始图像和处理后的图像作为函数的输入参数,即可计算出PSNR值:
```
original_image = imread('original_image.png');
processed_image = imread('processed_image.png');
psnr_value = calculate_psnr(original_image, processed_image);
disp(['PSNR value is ', num2str(psnr_value)])
```
阅读全文