I am currently looking for at in which i can store a numpy.ndarray
as an image, then save that image, and extract the pixel values of the image into a numpy.ndarray
. The dimension of the numpy.ndarray with the pixel values should be the same as the numpy.ndarray what was used to create the plot.
I tried something like this:
def make_plot_store_data(name, data):
plt.figure()
librosa.display.specshow(data.T,sr=16000,x_axis='frames',y_axis='mel',hop_length=160,cmap=cm.jet)
plt.savefig(name+".png")
plt.close()
convert = plt.get_cmap(cm.jet)
numpy_output_interweawed = convert(data.T)
The first image looks like this: The second image looks like this:
Why is this so messed up?
Here's one approach that takes a 512x512
ndarray
, displays it as an image, stores it as an image object, saves an image file, and generates a normalized pixel array of the same shape as the original.You might consider looking into the
skimage
module, in addition to standardpyplot
methods. There are a bunch of image manipulation methods there, and they're all built to play nice withnumpy
. Hope that helps.