在Matlab中平滑3D表面

时间:2015-07-21 19:25:23

标签: matlab

我正在努力优化显示的3D对象。我想要实现的是制作音频文件的3D频谱图。还有什么我想让它黑白,漂亮。好看的意思是什么 - 像这样: enter image description here

这只是示例图像 - 我知道谱图看起来不像

这是用于生成面数减少的表面的代码:

[y,fs,nbits]=wavread('audio.wav');
[s f t]= spectrogram(y(:,1),256,100,256,fs);
clear y
[X,Y]=meshgrid(t,f);
Z=log10(abs(s));

rskip = round(linspace(1,size(Z,1),80));
cskip = round(linspace(1,size(Z,2),64));
surf(X,Y,Z,'FaceColor','white','EdgeColor','none');
hold on
surf(X(rskip,:),Y(rskip,:),Z(rskip,:),'FaceColor','none','MeshStyle','row');
surf(X(:,cskip),Y(:,cskip),Z(:,cskip),'FaceColor','none','MeshStyle','column');
hold off
view(-65.5, 28);

这个音频文件的主要问题以及我使用减少的面数的原因是X,Y,Z阵列的大小 - 全部是129到269065.我​​的PC有8GB的RAM和大约1GB被其他人使用应用程序(包括操作系统)为Matlab留下大约6-7 GB。

这是代码运行后创建的图像: enter image description here

有人可以建议我如何让它看起来更顺畅吗?像样本图像一样。

1 个答案:

答案 0 :(得分:0)

如果纯粹出于审美原因,快速肮脏的方式来获得更平滑的图像是将高斯滤波器应用于从频谱图函数返回的功率矩阵。

clear;

[file,path] = uigetfile('*.wav');  % use GUI to select file
[y,fs,~] = wavread([path file]);

[p,f,t] = spectrogram(y(:,1),256,100,256,fs);
% Create the gaussian filter with hsize = [5 5] and sigma = 2
G = fspecial('gaussian',[5 5],2);
% Apply gaussian filter to the dB values
pBlur = imfilter(real(10*log10(p)),G,'same');

%# Show resulting spectograms (Filtered on top, origional on bottom)
figure(2);
imagesc([pBlur; real(10*log10(p))]);
colormap jet;

您可以更改hsizesigma以调整模糊属性。

enter image description here