Search code examples
pythonpytorchlibrosatorchvision

Librosa specshow, what data processing is done under the hood compared to plt.imshow


I am trying to understand, why a plot produced by plt.imshow() is way less detailed and more blurry, than a plot produced by librosa.display.specshow.

As the plots, or better to say, the data behind the plots is my basis of further analysis, I would like to go for as much detail as possible. Thus I wonder, what kind of black magic / enchancement / processing is done by librosa behind the curtains.

enter image description here As you can see in the screenshot, I use the same array as well as the same figure size and resolution.


Solution

  • This blurry effect is likely to be a consequence of interpolation done by plt.imshow. Default value for interpolation parameter in this function is antialiased, you can turn it off by using interpolation="none" in plt.imshow. You can also change the default behavior of plt.imshow according to Matplotlib doc.

    To conclude, it is not that librosa does black magic but more matplotlib that blurs the image, which could be an interesting feature for real-world images, but degrades the quality when trying to look at data such as spectrograms.