我将图像更改为Numpy数组格式。我以为是黑白图像(288,432),但我得到了288,432,4。为什么会这样?
import librosa
import librosa.display
import matplotlib.pyplot as plt
import librosa.featur
import numpy as np
import PIL.Image as pilimg
from PIL import Image
from matplotlib.backends.backend_agg import FigureCanvasAgg as FigureCanvas
w1,sr =librosa.load('test1.wav')
s1= librosa.feature.melspectrogram(y=w1, sr=sr, n_mels=128)
librosa.display.specshow(librosa.power_to_db(s1, ref=np.max),
cmap='gray', sr=sr, y_axis='mel', x_axis='time')
[出现图片]
fig = plt.Figure()
canvas = FigureCanvas(fig)
ax = fig.add_subplot(111)
p = librosa.display.specshow(librosa.power_to_db(s1, ref=np.max), ax=ax,
y_axis='mel', x_axis='time',cmap='gray')
fig.savefig('spec1.png')
image = pilimg.open('sepc1.png')
image = np.array(image)
print(image.shape)
(288,432,4)
print(image[250][255])
print(image[250][257])
print(image[251][255])
[236 236 236 255]
[230 230 230 255]
[222 222 222 266]