Is there any way I can make the attached contour plots more smooth ?
17 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Ankit Bhandari
el 6 de Ag. de 2017
Respondida: jacob faerman
el 15 de En. de 2018
I have attached two contour plots for pressure field outside an ellipse. The contour plots I got are jagged, may be due to the numerical integration I am using to calculate the pressure fields.The two plots are with Gaussian points 15000 and 5000 respectively. It is observable that with more Gaussian points, the contour plots are becoming smooth, but it is also taking time. Is there any other way to get smooth contour lines.
0 comentarios
Respuesta aceptada
John D'Errico
el 6 de Ag. de 2017
Sorry. If you try to resize a matrix (using interpolation) that is not itself sufficiently smooth that the original matrix yields non-smooth contours, you will get more finely interpolated noise! Interp2 is a waste of time here.
If you have a noisy matrix, then BEFORE you compute contours, you MUST smooth it FIRST if you want smooth contours. That smoothing may be done by removing the noise before you create the matrix, thus noise reduction prior to creating the matrix of data. Or you can do smoothing by applying a smoothing tool to your matrix, after creation.
You are doing some form of numerical integration that creates a noisy result. So a higher precision numerical integration is an option. Noise in the integration, as well as your comments, suggests you might be doing a Monte Carlo integration. I can't help if you don't say.
If you must do post smoothing on the matrix, then the classic solution is simply to apply a Gaussian blur to the matrix. You can do that using conv2. Or it should be possible to use methods like Savitsky-Golay, in two dimensions.
4 comentarios
Image Analyst
el 7 de Ag. de 2017
I agree with John. Smoothing array before finding contours is a good solution, otherwise Savitzky-Golay filter to smooth a jaggedy outline on a non-smoothed array. It's easy enough to try them both and see which you like better. For what it's worth, see my attached Savitzky-Golay outline smoothing demo.
Más respuestas (4)
KSSV
el 6 de Ag. de 2017
You should be plotting the contours from a matrix say Z..you can increase the dimensions of this matrix using imresize. If you have spatial data matrices X and Y also, you may go for interpolation using interp2.
0 comentarios
Chad Greene
el 6 de Ag. de 2017
I like KSSV's option of using imresize, because it performs antialiasing before interpolation. To scale by 1/5,
sc = 1/5; % scaling factor
contour(imresize(X,sc),imresize(Y,sc),imresize(Z,sc))
res = ?;
lambda = ?;
Zf = filt2(Z,res,lambda,'lp');
contour(X,Y,Zf)
where you'll have to enter res, which is the pixel size in x,y; and you'll have to enter lambda, the approximate lowpass wavelength.
0 comentarios
Teja Muppirala
el 7 de Ag. de 2017
Editada: Teja Muppirala
el 7 de Ag. de 2017
Maybe a median filter? However ORDFILT2 needs the Image Processing Toolbox.
Z = peaks(501); % Sample data
Z = Z +0.1*randn(size(Z));
Z(abs(Z)<0.5) = 0;
subplot(211);
contourf(Z);
title('original')
subplot(212);
rad = 5; %Filter radius
[x,y] = meshgrid(-rad:rad);
filtArea = x.^2+y.^2 <= rad.^2; % Use a round filter
Zfilt = ordfilt2(Z,ceil(nnz(filtArea)/2),filtArea);
contourf(Zfilt);
title('filtered')
0 comentarios
jacob faerman
el 15 de En. de 2018
The median filter worked nicely for me, and filter2 does not need the image processing toolbox.
0 comentarios
Ver también
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!