谱图时间轴不正确或实施智能裁剪?

时间:2017-02-14 11:53:12

标签: python image audio matplotlib plot

我目前正在尝试绘制音频文件的功率谱,但似乎在绘图的时间轴上存在一些问题。

例如

enter image description here

此音频文件的持续时间为1秒,但由于某种原因,该图表显示为无效时间超过1秒。还有更多的方法可以删除情节的灰色部分吗?..我目前正在垂直堆叠这些眼图,并且由于手动操作很乏味,我写了一个程序来做,但这些灰色区域似乎发生在不同地块的不同尺寸因此弄乱了情节的宽度..

以下是我如何制作情节:

Y =  np.array(range(0,length/3)) * (16000.0/(512.0))
X =  np.array(range(0,entries))*(1/98.0)
X,Y = np.meshgrid(X, Y)

plt.pcolormesh(X,Y,output_static_np_reshaped.T,cmap=cm.jet)
plt.xlabel('Time(s)')
plt.ylabel('Frequency(Hz)')
plt.title('Power spectrum of ' + name)
plt.colorbar()
#plt.show()
plt.savefig(spectogram_path_test+"/"+name+"_plot_static_conv.png")
plt.close()

长度始终为771,上图的条目为98.

正在堆叠它们:

 print "Saved"
    print "Saved!"
    print "Hstacked"
    images1 = Image.open(spectogram_path_test+"/"+name+"_plot_static_conv.png")
    images2 = Image.open(spectogram_path_test+"/"+name+"_plot_delta_conv.png")
    images3 = Image.open(spectogram_path_test+"/"+name+"_plot_delta_delta_conv.png")

    box = (100,55,592,496)
    cropped1  = images1.crop(box)
    cropped2  = images2.crop(box)
    cropped3  = images3.crop(box)

    width1, height1 = cropped1.size
    width2, height2 = cropped2.size
    width3, height3 = cropped3.size

    sum_width  = width1 + width2 + width3
    max_height = max(height1,height2,height3)

    new_im = Image.new('RGB',(sum_width,max_height))
    x_offset = 0

    for im in [cropped1,cropped2,cropped3]:
        new_im.paste(im,(x_offset,0))
        x_offset+=im.size[0]

    new_im.save(spectogram_path_test+"/"+name+"_plot_hstacked.png")

我使用Matplotlib绘制光谱图,并使用PIL导入图像来裁剪图像,并使用vstacking它们。

这里有可能的解决方案:

  • 找到一种绘制光谱图的方法,使灰色区域不会出现
  • 然后裁剪图像,使其能够自动检测图像的实际尺寸(没有灰色部分的情节),然后将它们加载..

0 个答案:

没有答案