How to Use MATLAB for Measuring SNR in Single Image
Date: 2023-03-29 12:15:50
To calculate the Signal-to-Noise Ratio (SNR) in a single image using MATLAB, you can follow these steps:
- Read in the image using the
imread
function:
img = imread('image_file.jpg');
- Convert the image to double precision:
img = im2double(img);
- Calculate the mean signal value in the image using the
mean2
function:
signal_mean = mean2(img);
- Calculate the standard deviation of the signal in the image using the
std2
function:
signal_std = std2(img);
- Calculate the mean noise value in the image by subtracting the mean signal value from the overall mean value:
noise_mean = mean2(img) - signal_mean;
- Calculate the SNR using the formula:
SNR = 20 * log10(signal_mean / noise_mean);
This formula is in units of decibels (dB), which is a logarithmic measure of the ratio of the signal power to the noise power.
Here's the complete code:
img = imread('image_file.jpg');
img = im2double(img);
signal_mean = mean2(img);
signal_std = std2(img);
noise_mean = mean2(img) - signal_mean;
SNR = 20 * log10(signal_mean / noise_mean);
Note that the actual SNR value will depend on the specific image and the imaging conditions used to capture it.