-
Notifications
You must be signed in to change notification settings - Fork 441
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Gaussian smoothing filter for UniformGrid #420
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Except the typo, this looks good to me, great work! Also, it would be awesome to have an example to illustrate this feature in the gallery. I was thinking about something like:
import pyvista as pv
data = pv.read("lenna.png")
smoothed_data = data.gaussian_smooth(std_dev=4.)
p = pv.Plotter(shape=(1, 2))
p.subplot(0, 0)
p.add_text("Original Image", font_size=24)
p.add_mesh(data)
p.camera_position = 'xy'
p.subplot(0, 1)
p.add_text("Gaussian smoothing", font_size=24)
p.add_mesh(smoothed_data)
p.camera_position = 'xy'
p.show()
But I can take care of it in a follow-up PR if you want.
pyvista/core/filters.py
Outdated
Name of scalars to process. Defaults to currently active scalars. | ||
|
||
preference : str, optional | ||
When scalars is specified, this is the perfered scalar type to |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- When scalars is specified, this is the perfered scalar type to
+ When scalars is specified, this is the preferred scalar type to
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That typo was copy-pasted (while it could have very well been mine :) ). I fixed it everywhere in filters.py.
Given you have already done it, I'd prefer if you could take care of the example - thanks. |
Great work! Here's a 3D example. In general, this might fit well with the volume rendering examples: https://docs.pyvista.org/examples/02-plot/volume.html import pyvista as pv
from pyvista import examples
data = examples.download_brain()
smoothed_data = data.gaussian_smooth(std_dev=3.)
dargs = dict(clim=smoothed_data.get_data_range(),
opacity = [0, 0, 0, 0.1, 0.3, 0.6, 1])
n = [100, 150, 200, 245, 255]
p = pv.Plotter(shape=(1, 2), notebook=0)
p.subplot(0, 0)
p.add_text("Original Image", font_size=24)
# p.add_mesh(data.contour(n), **dargs)
p.add_volume(data, **dargs)
p.subplot(0, 1)
p.add_text("Gaussian smoothing", font_size=24)
# p.add_mesh(smoothed_data.contour(n), **dargs)
p.add_volume(smoothed_data, **dargs)
p.link_views()
p.camera_position = [(-162.0, 704.8, 65.02),
(90.0, 108.0, 90.0),
(0.0068, 0.0447, 0.999)]
p.show() The brain is a little more visible. The opacity mapping could probably be improved |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great to me! We can add an example in the gallery down the road
Not much to say here: Adds the Gaussian smoothing filter to uniform grids.
For testing I just check that the data is changed at all and shape has not changed.
Also the scalars, preferences filter arguments and correspondingly setting the input of the vtk algo is duplicated so many times, and not always consistently - this should definitely happen in a wrapper function/decorator/...