Skip to content
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

Merged
merged 2 commits into from
Oct 26, 2019

Conversation

imsodin
Copy link
Contributor

@imsodin imsodin commented Oct 25, 2019

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/...

Copy link
Contributor

@GuillaumeFavelier GuillaumeFavelier left a 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()

image

But I can take care of it in a follow-up PR if you want.

Name of scalars to process. Defaults to currently active scalars.

preference : str, optional
When scalars is specified, this is the perfered scalar type to
Copy link
Contributor

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

Copy link
Contributor Author

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.

@imsodin
Copy link
Contributor Author

imsodin commented Oct 25, 2019

Given you have already done it, I'd prefer if you could take care of the example - thanks.

@banesullivan
Copy link
Member

banesullivan commented Oct 25, 2019

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

Screen Shot 2019-10-25 at 10 52 43 AM

@banesullivan banesullivan added enhancement Changes that enhance the library example There's a great example/demo in this thread! labels Oct 25, 2019
Copy link
Member

@banesullivan banesullivan left a 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

@banesullivan banesullivan changed the title add gaussian smoothing filter to uniform grid Gaussian smoothing filter for UniformGrid Oct 26, 2019
@banesullivan banesullivan merged commit 037ce81 into pyvista:master Oct 26, 2019
banesullivan added a commit that referenced this pull request Oct 26, 2019
@banesullivan banesullivan added this to the 0.23.0 milestone Nov 1, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Changes that enhance the library example There's a great example/demo in this thread!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants