Is there a way to convert the imshow object to an image directly in python 2.7 code? I'm trying to obtain the spectrogram of a wav file and use the image to detect edges in it. I have the code to get the spectrogram, I have the code to detect edges. Now, I'm manually saving the spectrogram and then detecting edges in the image. Is there a way to do it directly with the imshow object in python ?
Asked
Active
Viewed 133 times
0
-
Could you please add the code you're using? – unddoch Apr 13 '17 at 22:35
1 Answers
0
Using PIL, you can use:
import PIL
from matplotlib import pyplot as plt
plt.plot(range(5), range(5))
canvas = plt.get_current_fig_manager().canvas
plt.draw()
PIL_image = PIL.Image.frombuffer('RGBA', canvas.get_width_height(), canvas.buffer_rgba())
Tried on jupyter, but how it works may depend on the specific backend, so try it for yourself (for me it also mirrored the image, but that's easy to fix afterward, I think).
Also, you would have to draw only the image without the ticks, see scipy: savefig without frames, axes, only content.