How to calculate signal to noise ratio of hyperspectral image refolded in 2D matrix format?

19 views (last 30 days)
Input:
Raw Data (noise affected): 20000x224 (pixel values x wavelengths) (this data has been refolded from 3D array of HSI cube)
Preprocessed data (without noise): 20000x224 (pixel values x wavelengths)
Preferred output:
  1. A single value for SNR
  2. A plot of SNR
About SNR:
Doubt:
How do I use mean(x) and std(x) to calculate SNR? (or is it even recommended). I am also confused with the language used here, "mean of the image pixel value". Does this mean that I should find a single mean value or mean along the row so that I end up with meanvalues with output of size (20000x1). Similarly, "std at the wavelength". Does this mean that I should calculate stdvalues with output of size (1x224)?
I might have gravely misinterpreted what the author says about SNR and I am figuring out how to implement it with my 2D data.

Accepted Answer

Subhadeep Koley
Subhadeep Koley on 9 Mar 2022
As per my understanding, "A single value for SNR" indicates the overall SNR between the noisy and cleaned data. While in order to obatain a "A plot of SNR", you need to calculate one SNR value per channel (wavelength or band) of the noisy and cleaned data.
The code below is an example of how to do this using the psnr(_) function.
% Load an example 3D image and add noise (Replace this with your HS image)
load("mristack.mat");
img = mristack;
noisyImg = imnoise(img,"gaussian",0.0001);
[rw,cl,nChannel] = size(img);
% Refold the images in a 2D matrix format
imgReshaped = reshape(img,[rw*cl,nChannel]);
noisyImgReshaped = reshape(noisyImg,[rw*cl,nChannel]);
% Calculate overall SNR for the entire image
[~,snrVal] = psnr(noisyImgReshaped, imgReshaped);
% Calculate per channel SNR
snrPerChannel = zeros(1,nChannel);
for idx = 1:nChannel
[~,snrPerChannel(1,idx)]=psnr(noisyImgReshaped(:,idx),imgReshaped(:,idx));
end
% Plot the per channel SNR
figure
plot(snrPerChannel,"LineWidth",2)
xlabel("Channels/Bands/Wavelengths")
ylabel("SNR")

More Answers (0)

Products


Release

R2021a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!