Help - Smoothing surf plot, reduce surf detail and speed up performance

조회 수: 97 (최근 30일)
Hi everyone
I've got a large 3000x2000 matrix (Z) that represents the depth values for a topogrpahical surface plot. Because of the blurring between colour depth I get a very pixelated, sharp ridge line (see image 1 below). I've applied a medfilt2 and then interp2 to try and smooth out the ridges on the plot. This seems to work, but it's a lot of data points and it's running very slow. Is there a way to reduce the points and smooth the plot?
Z_med = medfilt2(Z, [5 5]);
Z_int = interp2(Z_med);
s = surf(Z_int);
% This gets the best results, but is slow and hard to work with
I've tried plotting less points (every 10th point), but this just resulting in really jagged edges (see image 2), and I'm not sure if the way I did this is right (it doesn't look right)? I've also tried plotting a courser grid, but the way I am doing it is wrong?
% Method 1 - Jagged ridges - Failure
step_plot = filt_plot(1:10:end,1:10:end);
Z_int = interp2(step_plot);
s = surf(Z_int);
% Method 2 - Trying to interp2 for a coarser grid - Doing something wrong here - Fails
X = size(Z_med,1);
Y = size(Z_med,2);
[Xq,Yq] = meshgrid(1:2:X,1:2:Y);
Vq = interp2(X,Y,Z_med,Xq,Yq,'cubic');
I was hoping to get a smooth plot between depth layers, and plot less points, but not getting the jaggered spikes like below...
Any help would be greatly appreciated!

채택된 답변

Mustafa Abu-Mallouh
Mustafa Abu-Mallouh 2020년 1월 2일
Have you tried taking a look at the shading function?
Specifically, it sounds like you are looking for the interpolation feature which is set by
shading interp
  댓글 수: 1
mackhina 2020년 1월 3일
Awesome! Thanks a lot for your help!
That definitely smoothed the steps and removed the edge pixilation.. The surface plot looks beautiful! Loading is pretty terrible though.
The reduced sampling image has removed the pixels and loads lots faster. Does the job for this purpose! Thanks!
% Original image
figure('Name', 'Surf plot')
s = surface(Z);
% Reduced sampling image
figure('Name', 'Surf step plot')
t = surface(Z(1:5:end,1:5:end));

댓글을 달려면 로그인하십시오.

추가 답변 (1개)

Deniz Diktas
Deniz Diktas 2020년 11월 18일
I am answering your question late in the same year. The rendering of topographical data (in other words, terrain data) is not trivial. Downsampling is the way to go but there are issues with how you do it: you should not leave out arbitrarily selected sample points when downsampling. By arbitrary I even mean regular downsampling. Such sampling may mislead you visually. The correct way to go about this is to render the data depending on the view-point (both camera location and view direction), which is a non-trivial issue. In 2014 I worked on a project for real-time terrain rendering and I can easily say that this is an intermediate or even an advanced topic in real time computer graphics. The main idea is to divide the data into smaller tiles and produce multi-resolution versions of these tiles (downsampling according to certain criteria comes at this stage) and then sending these tiles at appropriate resolutions depending on view-parameters in real-time to the GPU. I wonder if such a rendering is supported in Matlab's mapping toolkit.
Let me know if you want to learn more..
  댓글 수: 1
mackhina 2020년 11월 22일
Thanks for the feedback. I went with shading interp combined with downsizing the sample for plotting. e.g. taking every 10th data point.

댓글을 달려면 로그인하십시오.


Help CenterFile Exchange에서 Surface and Mesh Plots에 대해 자세히 알아보기




Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by