峰值信噪比matlab
时间: 2023-08-31 19:13:14 浏览: 109
峰值信噪比(PSNR)是一种用来衡量图像质量的指标,在MATLAB中可以通过编写代码来计算。以下是一个计算PSNR的MATLAB函数示例:
```matlab
function [output = PSNR(img1, img2)
if sum(sum(img1 - img2)) == 0
error('Those pictures are the same');
end
MAX = 1; % 图像有多少灰度级(我这里定为1)
% 归一化
if (max(max(img1)) - min(min(img1))) ~= 0
img1 = (img1 - min(min(img1))) ./ (max(max(img1)) - min(min(img1)));
end
if (max(max(img2)) - min(min(img2))) ~= 0
img2 = (img2 - min(min(img2))) ./ (max(max(img2)) - min(min(img2)));
end
MSE = sum(sum((img1 - img2).^2)) / (1024 * 1024); % 图片像素设为1024 x 1024
output = 20 * log10(MAX / sqrt(MSE)); % 峰值信噪比
end
```
你可以将需要计算PSNR的两幅图像作为参数传递给这个函数,函数将返回对应的PSNR值。请注意,这段代码是一个示例,你可能需要根据实际需求进行适当的修改和调整。<span class="em">1</span><span class="em">2</span><span class="em">3</span>
#### 引用[.reference_title]
- *1* [MATLAB下求两幅图像的峰值信噪比(PSNR)](https://download.csdn.net/download/andy817425/12910202)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
- *2* *3* [深入理解PSNR(峰值信噪比)(附matlab代码)](https://blog.csdn.net/weixin_29732003/article/details/122569893)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"]
[ .reference_list ]
阅读全文