MATLAB代码psnr
时间: 2023-11-13 10:08:56 浏览: 82
算法实现?
您好!关于MATLAB代码psnr算法实现,可以使用以下代码:
```matlab
function psnr_value=psnr(original_image,recon_image)
%PSNR Peak Signal-to-Noise Ratio.
% PSNR_VALUE = PSNR(ORIGINAL_IMAGE,RECON_IMAGE) computes the peak
% signal-to-noise ratio between the original image ORIGINAL_IMAGE and
% the reconstructed image RECON_IMAGE. Both images are assumed to
% have values in the range [0, 1]. The output is in decibels (dB),
% which can be calculated by 10*log10(psnr_value).
%
% Example
% -------------
% original_image = imread('cameraman.tif');
% recon_image = imnoise(original_image,'gaussian',0,0.01);
% psnr_value = psnr(original_image,recon_image);
%
% See also IMREAD, IMWRITE.
% Convert the image matrices to double precision
original_image = im2double(original_image);
recon_image = im2double(recon_image);
% Compute the mean square error (MSE) between the two images
mse = mean(mean((original_image - recon_image).^2));
% Compute the maximum possible pixel value
max_pixel_value = 1;
% Compute the PSNR
psnr_value = 10*log10(max_pixel_value^2/mse);
end
```
该算法实现计算给定图像的峰值信噪比(PSNR),并将结果以分贝(dB)表示。
希望回答能对您有所帮助!
阅读全文