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?
Advertisement
Answer
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.