Reputation: 1175
I would like to replicate the example here https://docs.pyvista.org/version/stable/examples/01-filter/gaussian-smoothing.html using my own data but trying to apply the gaussian_smooth()
method to my ImageData
results in MissingDataError: No data available.
(but works for the example). I'm guessing I need to pass my scalar field to ImageData
but I'm not sure with what attribute I do this.
Some potentially helpful code:
# create a uniform grid to sample the function with
n = 40
x_min, y_min, z_min = [np.min(q) - 0.25*np.absolute(np.min(q)) for q in [tmp[tmp[:,3]==1, 0], tmp[tmp[:,3]==1, 1], tmp[tmp[:,3]==1, 2]]]
x_max, y_max, z_max = [np.max(q) + 0.25*np.absolute(np.max(q)) for q in [tmp[tmp[:,3]==1, 0], tmp[tmp[:,3]==1, 1], tmp[tmp[:,3]==1, 2]]]
grid = pv.ImageData(
dimensions=(n, n, n),
spacing=( (x_max - x_min) / n,
(y_max - y_min) / n,
(z_max - z_min) / n),
origin=(x_min, y_min, z_min),
)
smooth_grid = grid.gaussian_smooth(std_dev=3.0)
My question: How can I successfully perform a gaussian_smooth
on my ImageData
Upvotes: 1
Views: 377
Reputation: 20932
Here's a minimal reproducible example that Gaussian smooths an ImageData
object.
# Import packages
import numpy as np
import pyvista as pv
# Create an empty ImageData instance `grid`
# See here for more info: https://docs.pyvista.org/api/core/_autosummary/pyvista.imagedata#pyvista.ImageData
grid = pv.ImageData(dimensions=(10, 10, 10))
# Create random points to fill `grid`
rng = np.random.default_rng(seed=0)
points = rng.random((1000, 3))
# Fill `grid` with these random points
grid.point_data['mydata'] = points
# Gaussian smooth
grid_smoothed = grid.gaussian_smooth()
Upvotes: 0