6

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?

Jalo
  • 1,131
  • 1
  • 12
  • 28
  • 3
    check the [doc](http://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.signaltonoise.html#scipy.stats.signaltonoise) It will tell you the meaning of the array of numbers – sk11 Aug 27 '14 at 10:09
  • 2
    How do you define the SNR of an image? If it is a camera image, my guess is that you have regions of uniform color, which would represent the signal and the fluctuations over the pixels as the noise. In that case you would limit the region of interest of this image to these uniform regions and then take `mean` values and standard deviations. But without more information of your image, we cannot really help: your question is not so well-defined. – Oliver W. Aug 27 '14 at 10:16
  • I had already read the doc @sk11 and I supose it gives the SNR of every pixel in the selected axis. However, I would like to know the SNR of the hole image, is there any posibility? – Jalo Aug 27 '14 at 10:53
  • I am sorry @OliverW. this is my first post in this web and I am not used to it. It is a greyscale image. I am actually working with medical images, and I would like to calculate the SNR of the filtered image in order to know its effectiveness – Jalo Aug 27 '14 at 10:56
  • The question still stands: *how do you define the SNR of your filtered image?* What kind of filter has been applied? Without any of this, your question probably won't get answered. – Oliver W. Aug 27 '14 at 19:44
  • I define the SNR as it says in (http://en.wikipedia.org/wiki/Signal-to-noise_ratio_%28imaging%29), as the mean to standard deviation ratio. I have used an anisotropic filter with the SimpleITK tools, so I can denoise the image, and keep the borders of the image – Jalo Aug 27 '14 at 21:59
  • 2
    signaltonoise is deprecated! – user153245 Aug 14 '18 at 01:57

1 Answers1

6

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.

Oliver W.
  • 13,169
  • 3
  • 37
  • 50
  • 1
    gone at version 1.3.1... any other suggestions? – Frank Musterman Jan 16 '20 at 15:02
  • 3
    @FrankMusteman the signal to noise ratio that was used in scipy.stats prior to v0.16.0 is simply the mean divided by the stddev. In [this related scipy issue](https://github.com/scipy/scipy/issues/9097) on github, the authors provide both a reasoning on why it was removed, as well as a simple recipe to create it if you need. – Oliver W. Jan 16 '20 at 18:50