Is it possible to apply a median filter to a mesh? #5947
Replies: 1 comment 1 reply
-
Marching Cubes is a fairly dated method for generating a surface mesh from image data. If your application permits, you can try using a more modern surface generation method such as Surface Nets instead. PyVista has an implementation here: https://docs.pyvista.org/version/stable/api/core/_autosummary/pyvista.ImageDataFilters.contour_labeled.html#pyvista.ImageDataFilters.contour_labeled The nice thing about that method is it has smoothing built-in. So, depending on the kinds of edits you're making, this may work for you to both generate the surface and do the smoothing.
The median filter, both in PyVista and in 3DSlicer, is fundamentally an image filter. The reason you can use it to smooth a surface mesh with 3DSlicer is because 3DSlicer implements a synchronisation method that keeps all representations of your data in sync. If you edit the image data, the surface gets updated accordingly to reflect the changes. So in that way, you can use a median filter on the image data in 3DSlicer, and in the background 3DSlicer will filter the image, but then also generate a new surface for you automatically based on the new filtered image (it uses vtkFlyingEdges to generate the surface and applies smoothing by default). Unfortunately PyVista does not have any such mechanism to keep image data and surface data synchronized like this. |
Beta Was this translation helpful? Give feedback.
-
First check
Commit to Help
Sample Code What is the problem, question, or error?
Write a short description telling me what you are doing, what you expect to happen, and what is currently happening.
Description
I'm creating a PolyData based on vertices and faces that I get from the Marching Cubes algorithm. I then extract the largest connected parts from it and plot it. I then use some callback function to edit parts of the mesh, that's why I have to cast it to an unstructured grid. After editing, I generate a new mesh using
extract_surface()
. I have been using Slicer3D in the past and you can smooth the mesh using a median filter. I have found that pyvista also has this functionality: (https://docs.pyvista.org/version/stable/api/core/_autosummary/pyvista.imagedatafilters.median_smooth#pyvista.ImageDataFilters.median_smooth) but it's made forImageData
and not for PolyData or an Unstructured Grid. How could I implement this for my situation?System Information
Screenshots
Mesh that I would like to get (Made in 3DSlicer)Unsmoothed mesh that I get.
Beta Was this translation helpful? Give feedback.
All reactions