将频谱图另存为MATLAB中的图像 [英] Save Spectrogram as an Image in MATLAB

查看:701
本文介绍了将频谱图另存为MATLAB中的图像的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 MATLAB 中的spectrogram()功能分析一些声音片段.我想将频谱图另存为图像(jpg,png等).但是,无论我将图形保存为哪种图像格式,生成的图像看上去总是与图中看到的有所不同(斑点").

I'm analyzing some sound clips using the spectrogram() function in MATLAB. I would like to save the spectrogram as an image (jpg, png, etc). But regardless of what image format I save the figure in, the resulting image always looks different ("spotty") from what I see in the figure.

以下是频谱图的示例: Matlab图保存的图片

Here's an example of the spectrograms: Matlab Figure vs. Saved Image

我想要的只是将图中显示的内容保存为图像.我已经尝试过将图形保存为所有可能的图像格式,但是它们都产生相同的斑点"效果.我也尝试过手动保存(单击文件->另存为)以及使用print()saveas()函数以编程方式进行保存.每次都得到相同的结果.

All I want is to save exactly what I see in the figure as an image. I've already tried saving the figure in all the image formats possible but all of them are producing the same "spotting" effect. I've also tried both manual saving (click on file -> save as) and programmatically using the print() and the saveas() functions. Same result every time.

任何帮助将不胜感激!

Any help would be appreciated!

推荐答案

我通过使用pcolor()函数找到了解决此问题的方法,该函数本质上是以网格格式绘制的旋转的surf()函数(文档).在进一步修改了spectrogram()函数之后,我确信这些斑点"工件与数据格式,属性或小数位数无关.问题似乎在于MATLAB绘制和可视化3D绘制的方式.我也尝试使用mesh()函数进行绘图,它产生了另一种斑点"效果. pcolor()之所以有效,是因为它是3D图的2D可视化.

I found a work-around for this problem by using the pcolor() function, which is essentially a rotated surf() function plotted in a grid format (doc). After tinkering with the spectrogram() function more, I'm convinced that these "spotting" artifacts have nothing to do with the data format, property, or scale. The problem seems to lie in the way MATLAB plots and visualizes 3D plots. I tried plotting with the mesh() function as well and it produced a different kind of "spotting" effect. pcolor() works because it's a 2D visualization of a 3D plot.

这是spectrogram()使用surf()绘制图像的方式(改编自 doc ):

This is how spectrogram() plots the image using surf() (adapted from the doc):

[S,T,F,P] = spectrogram(X,256,250,256,2000);
surf(T,F,abs(S),'EdgeColor','none');
axis tight; view(0,90);

...,这就是使用pcolor()绘制易于保存的图像的方法:

... and this is how to use pcolor() to plot a save-friendly image:

[S,T,F,P] = spectrogram(X,256,250,256,2000);
h = pcolor(T,F,abs(S));
set(h,'EdgeColor','none');

这篇关于将频谱图另存为MATLAB中的图像的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆