Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the Signal-to-Noise-Ratio from an image in Python?

I am filtering an image and I would like to know the SNR. I tried with the scipy function scipy.stats.signaltonoise() but I get an array of numbers and I don't really know what I am getting.

Is there any other way to get te SNR of my image?

like image 462
Jalo Avatar asked Aug 27 '14 10:08

Jalo


1 Answers

UPDATE: (for those who don't read linked material in the comments) The scipy.stats.signaltonoise function has been deprecated and removed. In the linked github thread, you can find the original recipe to implement it yourself:

def signaltonoise(a, axis=0, ddof=0):
    a = np.asanyarray(a)
    m = a.mean(axis)
    sd = a.std(axis=axis, ddof=ddof)
    return np.where(sd == 0, 0, m/sd)

Original answer:

The reason you are getting an array back rather than a single number, is because you haven't specified axis=None in your call to scipy.stats.signaltonoise.

Thus, you probably needed this:

snr = scipy.stats.signaltonoise(img, axis=None)

Without that option, you will get the SNR for every column in the image. This makes a lot of sense when the data is not actually an image, but a sequence of time signals for example.

like image 127
Oliver W. Avatar answered Oct 22 '22 00:10

Oliver W.