用MATLAB计算图像SNR
时间: 2023-06-30 16:09:10 浏览: 1075
在MATLAB中计算图像的信噪比(SNR)可以通过以下步骤实现:
1. 读取原始图像和噪声图像,并将它们转换为灰度图像。
```matlab
original = imread('original_image.jpg');
noisy = imread('noisy_image.jpg');
original_gray = rgb2gray(original);
noisy_gray = rgb2gray(noisy);
```
2. 计算信号的平均值和标准差。
```matlab
signal_mean = mean(original_gray(:));
signal_std = std(double(original_gray(:)));
```
3. 计算噪声的平均值和标准差。
```matlab
noise_mean = mean(double(noisy_gray(:)));
noise_std = std(double(noisy_gray(:)));
```
4. 计算信噪比。
```matlab
snr = 20 * log10(signal_std / noise_std);
```
完整的代码如下:
```matlab
original = imread('original_image.jpg');
noisy = imread('noisy_image.jpg');
original_gray = rgb2gray(original);
noisy_gray = rgb2gray(noisy);
signal_mean = mean(original_gray(:));
signal_std = std(double(original_gray(:)));
noise_mean = mean(double(noisy_gray(:)));
noise_std = std(double(noisy_gray(:)));
snr = 20 * log10(signal_std / noise_std);
disp(['SNR = ' num2str(snr) ' dB']);
```
其中,原始图像和噪声图像需要替换为实际使用的图像。
阅读全文