ImageData#
- class ImageData(*args, **kwargs)[source]#
Models datasets with uniform spacing in the three coordinate directions.
Can be initialized in one of several ways:
Create empty grid
Initialize from a vtkImageData object
Initialize based on dimensions, cell spacing, and origin.
Changed in version 0.33.0: First argument must now be either a path or vtkImageData. Use keyword arguments to specify the dimensions, spacing, and origin of the uniform grid.
Changed in version 0.37.0: The
dimsparameter has been renamed todimensions.- Parameters:
- uinput
str| vtkImageData |ImageData,optional Filename or dataset to initialize the uniform grid from. If set, remainder of arguments are ignored.
- dimensionssequence[
int],optional dimensionsof the uniform grid.- spacingsequence[
float], default: (1.0, 1.0, 1.0) spacingof the uniform grid in each dimension. Must be positive.- originsequence[
float], default: (0.0, 0.0, 0.0) originof the uniform grid.- deepbool, default:
False Whether to deep copy a vtkImageData object. Keyword only.
- direction_matrix
RotationLike,optional The
direction_matrixis a 3x3 matrix which controls the orientation of the image data.Added in version 0.45.
- offset
int|VectorLike[int], default: (0, 0, 0) The offset defines the minimum
extentof the image. Offset values can be positive or negative. In physical space, the offset is relative to the image’sorigin.Added in version 0.45.
- validatebool |
MeshValidationFields| sequence[MeshValidationFields], default:False Validate the mesh using
validate_mesh()after initialization. Set this toTrueto validate all fields, or specify any combination of fields allowed byvalidate_mesh.Added in version 0.47.
- uinput
Examples#
Download Python source code | Download Jupyter notebook
Create an empty ImageData.
>>> import pyvista as pv
>>> grid = pv.ImageData()
Initialize from a vtkImageData object.
>>> import vtk
>>> vtkgrid = vtk.vtkImageData()
>>> grid = pv.ImageData(vtkgrid)
Initialize using just the grid dimensions and default spacing and origin. These must be keyword arguments.
>>> grid = pv.ImageData(dimensions=(10, 10, 10))
Initialize using dimensions and spacing.
>>> grid = pv.ImageData(
... dimensions=(10, 10, 10),
... spacing=(2, 1, 5),
... )
Initialize using dimensions, spacing, and an origin.
>>> grid = pv.ImageData(
... dimensions=(10, 10, 10),
... spacing=(2, 1, 5),
... origin=(10, 35, 50),
... )
Initialize from another ImageData.
>>> grid = pv.ImageData(
... dimensions=(10, 10, 10),
... spacing=(2, 1, 5),
... origin=(10, 35, 50),
... )
>>> grid_from_grid = pv.ImageData(grid)
>>> grid_from_grid == grid
True
Used In#
Guides
- PyVista Data Model (1 use)
- Transitioning From VTK to PyVista (1 use)
Docstring Examples
DataObject.add_field_data(1 use)DataObject.copy_attributes(1 use)DataObject.copy_structure(1 use)DataSet.area(1 use)DataSet.cell(1 use)40 more
DataSet.dimensionality(1 use)DataSet.find_containing_cell(1 use)DataSet.intersect_with_line(1 use)DataSet.plot(1 use)DataSet.volume(1 use)DataSetFilters.contour(1 use)DataSetFilters.partition(1 use)DataSetFilters.remove_nan_cells(1 use)DataSetFilters.voxelize_binary_mask(1 use)Grid.dimensions(1 use)Grid.to_hexahedra(1 use)Grid.to_quads(1 use)ImageData.extent(1 use)ImageData.offset(1 use)ImageData.origin(1 use)ImageData.points(1 use)ImageData.spacing(1 use)ImageData.x(1 use)ImageData.y(1 use)ImageData.z(1 use)ImageDataFilters.dilate(1 use)ImageDataFilters.erode(1 use)ImageDataFilters.label_connectivity(1 use)ImageDataFilters.resample(1 use)ImageDataFilters.slice_index(1 use)MultiBlock.flatten(1 use)MultiBlock.get(1 use)MultiBlock.get_block(1 use)MultiBlock.plot(1 use)PartitionedDataSet.plot(1 use)Plotter.add_volume(1 use)Plotter.enable_ssao(1 use)PointSet.plot(1 use)RectilinearGrid.dimensions(1 use)Renderer.enable_ssao(1 use)Volume.mapper(1 use)Volume.prop(1 use)VolumeProperty.interpolation_type(1 use)cartesian_to_spherical(1 use)plot(1 use)
Gallery Examples
Inheritance#
Inherited members are documented on Grid, DataSet, _BoundsSizeMixin, ImageDataFilters, DataSetFilters, DataObjectFilters, DataObject.
See them all under Inherited Attributes, Inherited Methods and Filters.
Wraps vtkImageData.
Attributes#
Set or get the direction matrix. |
|
Return or set the extent of the ImageData. |
|
Return or set 4x4 matrix to transform index space ( |
|
Return or set the index offset of the ImageData. |
|
Return the origin of the grid (bottom southwest corner). |
|
Return or set the 4x4 matrix from physical ( |
|
Build a copy of the implicitly defined points as a NumPy array. |
|
Return or set the spacing for each axial direction. |
|
Return all the X points. |
|
Return all the Y points. |
|
Return all the Z points. |
Inherited Attributes#
Return the active normals as an array. |
|
Return the active scalars as an array. |
|
Return the active scalar’s association and name. |
|
Return the name of the active scalars. |
|
Return the active tensors array. |
|
Return the active tensor’s field and name: [field, name]. |
|
Return the name of the active tensor array. |
|
Return the active texture coordinates on the points. |
|
Return the active vectors array. |
|
Return the active vector’s association and name. |
|
Return the name of the active vectors array. |
|
Return the actual size of the dataset object. |
|
Return the mesh area if 2D. |
|
Return a list of array names for the dataset. |
|
Return a glyph representation of the active vector data as arrows. |
|
Compute the radius and center of a bounding sphere. |
|
Return the bounding box of this dataset. |
|
Return the size of each axis of the object’s bounding box. |
|
A generator that provides an easy way to loop over all cells. |
|
Return cell data as DataSetAttributes. |
|
Set or return the center of the bounding box. |
|
Return the number of spatial dimensions spanned by this dataset’s points. |
|
Return the grid’s dimensions. |
|
Return the set of distinct cell types in this dataset. |
|
Return FieldData as DataSetAttributes. |
|
Return True if the mesh contains any non-linear cells. |
|
Return |
|
Return the length of the diagonal of the bounding box. |
|
Return the maximum spatial dimensionality of all cells in this mesh. |
|
Get address of the underlying VTK C++ object. |
|
Get the minimum spatial dimensionality of all cells in this mesh. |
|
Return the number of arrays present in the dataset. |
|
Return the number of cells in the entire dataset. |
|
Return the number of points in the entire dataset. |
|
Return the number of cells. |
|
Return the number of points. |
|
Return point data as DataSetAttributes. |
|
Set or return a user-specified data dictionary. |
|
Return the mesh volume. |
Methods#
Cast this uniform grid to a rectilinear grid. |
|
Cast this image data to a |
|
|
Create a tetrahedral mesh structured grid. |
Inherited Methods#
Add field data. |
|
Convert this |
|
Extract the points of this dataset and return a |
|
Extract the points of this dataset and return a |
|
Get a new representation of this object as a |
|
Get the cell neighbors of the ind-th cell. |
|
Get consecutive levels of cell neighbors. |
|
Remove all cell arrays. |
|
Remove all arrays from point/cell/field data. |
|
Remove all field data. |
|
Remove all point arrays. |
|
Return a copy of the object. |
|
Copy the data attributes of the input dataset object. |
|
Overwrite this dataset in-place with the new dataset’s geometries and data. |
|
Copy pyvista meta data onto this object from another object. |
|
Copy the structure (geometry and topology) of the input dataset object. |
|
Overwrite this data object with another data object as a deep copy. |
|
Find the index of cells whose bounds intersect a line. |
|
Find the index of cells that intersect a line. |
|
Find the index of cells in this mesh within bounds. |
|
Find index of closest cell in this mesh to the given point. |
|
Find index of closest point in this mesh to the given point. |
|
Find index of a cell that contains the given point. |
|
Search both point, cell, and field data for an array. |
|
Get the association of an array. |
|
Return a |
|
Get the min and max of a named array. |
|
Return the header stats of this dataset. |
|
Locate points and cell ids that intersect a line. |
|
Plot a PyVista, NumPy, or VTK object. |
|
Get the cell IDs that use the ind-th point. |
|
Return whether one or more points are inside a cell. |
|
Get the point neighbors of the ind-th point. |
|
Get consecutive levels of point neighbors. |
|
Change array name by searching for the array then renaming it. |
|
Save this vtk object to file. |
|
Find the scalars by name and appropriately sets it as active. |
|
Find the tensors by name and appropriately sets it as active. |
|
Find the vectors by name and appropriately sets it as active. |
|
Shallow copy the given mesh to this mesh. |
|
Return this dataset’s point or cell arrays as a |
|
Convert voxels to hexahedra. |
|
Return this dataset’s point or cell arrays as a |
|
Convert pixels to quads. |
Filters#
Align a dataset to another. |
|
Align a dataset to the x-y-z axes. |
|
Return a bounding box for this dataset. |
|
Generate points at the center of the cells in this dataset. |
|
Transform cell data into point data. |
|
Compute a function of (geometric) quality for each cell of a mesh. |
|
Check the validity of each cell in this dataset. |
|
Re-mesh image data from a cell-based to a point-based representation. |
|
Clip a dataset by a plane by specifying the origin and normal. |
|
Clip a dataset by a bounding box defined by the bounds. |
|
Clip a dataset by a scalar. |
|
Clip a dataset by a slab of finite thickness around a plane. |
|
Clip any mesh type using a |
|
Perform morphological closing on continuous or binary data. |
|
Add RGB(A) scalars to labeled data. |
|
Compute metrics on the boundary faces of a mesh. |
|
Compute sizes for 0D (vertex count), 1D (length), 2D (area) and 3D (volume) cells. |
|
Compute derivative-based quantities of point/cell scalar field. |
|
Compute the implicit distance from the points to a surface. |
|
Combine multiple images into one. |
|
Find and label connected regions. |
|
Contour an input self by an array. |
|
Generate surface contours from 3D image label maps. |
|
Compute the convex hull from this mesh’s points. |
|
Crop this image to remove points at its boundaries. |
|
Transform cell data into point data. |
|
Return a decimated version of a triangulation of the boundary. |
|
Construct a 3D Delaunay triangulation of the mesh. |
|
Morphologically dilate grayscale or binary data. |
|
Generate scalar values on a dataset. |
|
Morphologically erode grayscale or binary data. |
|
Push each individual cell away from the center of the dataset. |
|
Extract all the internal/external edges of the dataset as PolyData. |
|
Return a subset of the grid. |
|
Extract cells of a specified type. |
|
Extract edges from the surface of the mesh. |
|
Extract the outer surface of a volume or structured grid dataset. |
|
Extract largest connected set in mesh. |
|
Return a subset of the grid (with cells) that contains any of the given point indices. |
|
Select piece (for example, volume of interest). |
|
Extract surface geometry of the mesh as |
|
Return a subset of the mesh based on the values of point or cell data. |
|
Apply a fast Fourier transform (FFT) to the active scalars. |
|
Flip mesh about the normal. |
|
Flip mesh about the x-axis. |
|
Flip mesh about the y-axis. |
|
Flip mesh about the z-axis. |
|
Smooth the data with a Gaussian kernel. |
|
Splat points into a volume using a Gaussian distribution. |
|
Copy a geometric representation (called a glyph) to the input dataset. |
|
Perform a Butterworth high pass filter in the frequency domain. |
|
Dilates one value and erodes another. |
|
Apply a threshold to scalar values in a uniform grid. |
|
Integrate point and cell data. |
|
Interpolate values onto this mesh from a given dataset. |
|
Find and label connected regions in a |
|
Perform a Butterworth low pass filter in the frequency domain. |
|
Smooth data using a median filter. |
|
Join one or many other grids to this grid. |
|
Merge duplicate points in this mesh. |
|
Perform morphological opening on continuous or binary data. |
|
Return an oriented bounding box (OBB) for this dataset. |
|
Produce an outline of the full extent for the input dataset. |
|
Produce an outline of the corners for the input dataset. |
|
Renumber labeled data such that labels are contiguous. |
|
Enlarge an image by padding its boundaries with new points. |
|
Break down input dataset into a requested number of partitions. |
|
Sample a dataset along a circular arc and plot it. |
|
Sample a dataset along a circular arc defined by a normal and polar vector and plot it. |
|
Sample a dataset along a high resolution line and plot. |
|
Transform point data into cell data. |
|
Re-mesh image data from a point-based to a cell-based representation. |
|
Transform point data into cell data. |
|
Reflect a dataset across a plane. |
|
Remove cells whose scalar values are NaN. |
|
Resample the image to modify its dimensions and spacing. |
|
Resize the dataset’s bounds. |
|
Apply a reverse fast Fourier transform (RFFT) to the active scalars. |
|
Rotate mesh about a point with a rotation matrix or |
|
Rotate mesh about a vector. |
|
Rotate mesh about the x-axis. |
|
Rotate mesh about the y-axis. |
|
Rotate mesh about the z-axis. |
|
Resample array data from a passed mesh onto this mesh. |
|
Sample a dataset over a circular arc. |
|
Sample a dataset over a circular arc defined by a normal and polar vector and plot it. |
|
Sample a dataset onto a line. |
|
Sample a dataset onto a multiple lines. |
|
Scale the mesh. |
|
Mark points as to whether they are inside a closed surface. |
|
Mark points from this mesh as inside or outside relative to a closed surface. |
|
Select values of interest and fill the rest with a constant. |
|
Return a copy of the dataset with separated cells with no shared points. |
|
Shrink the individual faces of a mesh. |
|
Slice a dataset by a plane at the specified origin and normal vector orientation. |
|
Create many slices of the input dataset along a specified axis. |
|
Slice a dataset using a polyline/spline as the path. |
|
Slice a dataset by a VTK implicit function. |
|
Extract a subset using IJK indices. |
|
Create three orthogonal slices through the dataset on the three Cartesian planes. |
|
Sort labeled data by number of points or cells. |
|
Find, label, and split connected bodies/volumes. |
|
Split mesh into separate sub-meshes using point or cell data. |
|
Integrate a vector field to generate streamlines. |
|
Generate evenly spaced streamlines on a 2D dataset. |
|
Generate streamlines of vectors from the points of a source mesh. |
|
Return the surface indices of a grid. |
|
Tessellate a mesh. |
|
Texture map this dataset to a user defined plane. |
|
Texture map this dataset to a user defined sphere. |
|
Apply a vtkThreshold filter to the input dataset. |
|
Threshold the dataset by a percentage of its range on the active scalars array. |
|
Transform this mesh with a 4x4 transform. |
|
Translate the mesh. |
|
Return an all triangle mesh. |
|
Validate this mesh’s array data, points, and cells. |
|
Voxelize mesh to UnstructuredGrid. |
|
Voxelize mesh as a binary |
|
Voxelize mesh to create a RectilinearGrid voxel volume. |
|
Warp the dataset’s points by a point data scalars array’s values. |
|
Warp the dataset’s points by a point data vectors array’s values. |