ImageData
Introduction
vtkImageData is a data object that is a concrete implementation of vtkDataSet. vtkImageData represents a geometric structure that is a topological and geometrical regular array of points. Examples include volumes (voxel data) and pixmaps. All vtkDataSet functions are inherited.
Methods
computeHistogram
Returns an object with { minimum, maximum, average, variance, sigma, count } of the imageData points found within the provided worldBounds.
voxelFunc(index, bounds) is an optional function that is called with the [i,j,k] index and index bounds, expected to return truthy if the data point should be counted in the histogram, and falsey if not.
| Argument | Type | Required | Description |
|---|---|---|---|
voxelFunc | No |
computeIncrements
Returns an array[3] of values to multiply an [i,j,k] index to convert into the actual data array index, from the provided extent. numberOfComponents should match the Scalar components.
| Argument | Type | Required | Description |
|---|---|---|---|
extent | Extent | Yes | |
numberOfComponents | Number | No |
computeOffsetIndex
Converts an [i,j,k] index to the flat data array index. Returns NaN if any of the i,j,k bounds are outside the data Extent.
| Argument | Type | Required | Description |
|---|---|---|---|
ijk | Vector3 | Yes | The localized [i,j,k] pixel array position. Float values will be rounded. |
computeTransforms
Calculates the indexToWorld and worldToIndex conversion matrices from the origin, direction, and spacing. Shouldn't need to call this as it is handled internally, and updated whenever the vtkImageData is modified.
extend
Method used to decorate a given object (publicAPI+model) with vtkImageData characteristics.
| Argument | Type | Required | Description |
|---|---|---|---|
publicAPI | Yes | object on which methods will be bounds (public) | |
model | Yes | object on which data structure will be bounds (protected) | |
initialValues | IImageDataInitialValues | No | (default: {}) |
extentToBounds
Returns a bounds array from a given Extent, useful if you need to calculate the world bounds of a subset of the imageData's data.
| Argument | Type | Required | Description |
|---|---|---|---|
ex | Extent | Yes |
getBounds
Returns the axis-aligned bounds of vtkImageData in world coordinates. The axis-aligned Bounds of a vtkImage are returned as pairs of world coordinates [x_min, x_max, y_min, y_max, z_min, z_max] these are calculated from the Extent, Origin, and Spacing, defined through
[
(i_min - 0.5)*Spacing[0] + Origin[0], (i_max + 0.5)*Spacing[0] + Origin[0],
(j_min - 0.5)*Spacing[1] + Origin[1], (j_max + 0.5)*Spacing[1] + Origin[1],
(k_min - 0.5)*Spacing[2] + Origin[2], (k_max + 0.5)*Spacing[2] + Origin[2]
];Note that this includes a padding of 0.5 voxel spacing in each principal direction, as well as any orientation of the image. You can't directly set the bounds. First you need to decide how many pixels across your image will be (i.e. what the extent should be), and then you must find the origin and spacing that will produce the bounds that you need from the extent that you have. This is simple algebra. In general, always set the extent to start at zero, e.g. [0, 9, 0, 9, 0, 9] for a 10x10x10 image. Calling setDimensions(10,10,10) does exactly the same thing as setExtent(0,9,0,9,0,9) but you should always do the latter to be explicit about where your extent starts. Such an image of dimensions [10, 10, 10], origin [0, 0, 0] and voxel-spacing of 1.0, will result in bounds equal to [-0.5, 9.5, -0.5, 9.5, -0.5, 9.5].
getCenter
Get the [x,y,z] location of the center of the imageData.
getDimensions
Get dimensions of this structured points dataset. It is the number of points on each axis. Dimensions are computed from Extents during this call.
getDirection
Direction is a mat3 matrix corresponding to the axes directions in world coordinates for the I, J, K axes of the image. Direction must form an orthonormal basis.
getExtent
The maximal extent of the projection.
getExtentByReference
getIndexToWorld
Returns the mat4 matrices used to convert between world and index. worldToIndex is the inverse matrix of indexToWorld. Both are made with Float64Array.
getNumberOfCells
getNumberOfPoints
Get the number of points composing the dataset.
getOffsetIndexFromWorld
Returns the data array index for the point at the provided world position.
| Argument | Type | Required | Description |
|---|---|---|---|
xyz | Vector3 | Yes | The [x,y,z] array in world coordinates. |
getOrigin
Get the origin of the dataset. The origin is the position in world coordinates of the point of extent (0,0,0). This point does not have to be part of the dataset, in other words, the dataset extent does not have to start at (0,0,0) and the origin can be outside of the dataset bounding box. The origin plus spacing determine the position in space of the points.
getOriginByReference
Get the origin of the dataset. The origin is the position in world
getPoint
Get the world position of a data point. Index is the point's index in the 1D data array.
| Argument | Type | Required | Description |
|---|---|---|---|
index | Number | Yes |
getScalarValueFromWorld
Returns the scalar value for the point at the provided world position, or NaN if the world bounds are outside the volumeData bounds. comp is the scalar component index, for multi-component scalar data.
| Argument | Type | Required | Description |
|---|---|---|---|
xyz | Vector3 | Yes | The [x,y,z] array in world coordinates. |
comp | Number | No | The scalar component index for multi-component scalars. |
getSpacing
Set the spacing [width, height, length] of the cubical cells that compose the data set.
getSpacingByReference
getSpatialExtent
Get image extents without translation (i.e. with origin set to [0,0,0]) and under unit spacing (i.e. spacing = [1, 1, 1]). This includes a padding of 0.5 pixel/voxel in each principal direction. The padding is necessary for conventional images (textures, png, bmp) as well as medical images and volumes, since each pixel/voxel has a pre-defined width (based on specified spacing) including the ones on the boundary of the image.
getWorldToIndex
Returns the mat4 matrices used to convert between world and index. worldToIndex is the inverse matrix of indexToWorld. Both are made with Float64Array.
indexToWorld
Converts the input index vector [i,j,k] to world values [x,y,z]. If an out vector is not provided, a new one is created. If provided, it modifies the out vector array in place, but also returns it.
| Argument | Type | Required | Description |
|---|---|---|---|
ain | ReadonlyVec3 | Yes | |
aout | vec3 | No |
indexToWorldBounds
Calculate the corresponding world bounds for the given index bounds [i_min, i_max, j_min, j_max, k_min, k_max]. Modifies out in place if provided, or returns a new array. Returned bounds are NOT padded based on voxel spacing (see getBounds). The output is merely a bounding box calculated considering voxels as grid points.
| Argument | Type | Required | Description |
|---|---|---|---|
bin | Bounds | Yes | |
bout | Bounds | No |
indexToWorldVec3
this is the fast version, requires vec3 arguments
| Argument | Type | Required | Description |
|---|---|---|---|
vin | ReadonlyVec3 | Yes | |
vout | vec3 | No |
initialize
Reinitialize the state (direction, spacing, origin, extent, etc.) and the data set.
newInstance
Method used to create a new instance of vtkImageData.
| Argument | Type | Required | Description |
|---|---|---|---|
initialValues | IImageDataInitialValues | No | for pre-setting some of its content |
setDimensions
Set the values of the extent, from 0 to (i-1), etc.
| Argument | Type | Required | Description |
|---|---|---|---|
i | Number | Yes | |
j | Number | Yes | |
k | Number | Yes |
setDimensions
Set the values of the extent, from 0 to (i-1), etc.
| Argument | Type | Required | Description |
|---|---|---|---|
dims | Yes |
setDirection
The direction matrix is a 3x3 basis for the I, J, K axes of the image. The rows of the matrix correspond to the axes directions in world coordinates. Direction must form an orthonormal basis, results are undefined if it is not.
| Argument | Type | Required | Description |
|---|---|---|---|
e00 | Yes | ||
e01 | Yes | ||
e02 | Yes | ||
e10 | Yes | ||
e11 | Yes | ||
e12 | Yes | ||
e20 | Yes | ||
e21 | Yes | ||
e22 | Yes |
setDirection
The direction matrix is a 3x3 basis for the I, J, K axes of the image. The rows of the matrix correspond to the axes directions in world coordinates. Direction must form an orthonormal basis, results are undefined if it is not.
| Argument | Type | Required | Description |
|---|---|---|---|
direction | mat3 | Yes |
setExtent
| Argument | Type | Required | Description |
|---|---|---|---|
x1 | Number | Yes | The x coordinate of the first point. |
x2 | Number | Yes | The x coordinate of the second point. |
y1 | Number | Yes | The y coordinate of the first point. |
y2 | Number | Yes | The y coordinate of the second point. |
z1 | Number | Yes | The z coordinate of the first point. |
z2 | Number | Yes | The z coordinate of the second point. |
setExtent
Set the extent.
| Argument | Type | Required | Description |
|---|---|---|---|
extent | Extent | Yes |
setOrigin
Set the origin of the image.
| Argument | Type | Required | Description |
|---|---|---|---|
origin | Vector3 | Yes | The coordinate of the origin point. |
setOriginFrom
Set the origin of the image.
| Argument | Type | Required | Description |
|---|---|---|---|
origin | Vector3 | Yes | The coordinate of the origin point. |
setSpacing
| Argument | Type | Required | Description |
|---|---|---|---|
spacing | Yes |
setSpacingFrom
| Argument | Type | Required | Description |
|---|---|---|---|
spacing | Yes |
worldToIndex
Converts the input world vector [x,y,z] to approximate index values [i,j,k]. Should be rounded to integers before attempting to access the index. If an out vector is not provided, a new one is created. If provided, it modifies the out vector array in place, but also returns it.
| Argument | Type | Required | Description |
|---|---|---|---|
ain | Yes | ||
aout | No |
worldToIndexBounds
Calculate the corresponding index bounds for the given world bounds [x_min, x_max, y_min, y_max, z_min, z_max]. Modifies out in place if provided, or returns a new array.
| Argument | Type | Required | Description |
|---|---|---|---|
bin | Bounds | Yes | |
bout | Bounds | No |
worldToIndexVec3
this is the fast version, requires vec3 arguments
| Argument | Type | Required | Description |
|---|---|---|---|
vin | Yes | ||
vout | No |