openlifu.seg.skinseg.vtk_img_from_array_and_affine¶
- openlifu.seg.skinseg.vtk_img_from_array_and_affine(vol_array: ndarray, affine: ndarray) vtkImageData[source]¶
Convert a numpy (array, affine) pair into a vtkImageData.
- Parameters:
vol_array – a 3D image numpy array with float type data
affine – a numpy array of shape (4,4) representing the affine matrix of the 3D image.
- Returns: vtkImageData with a copy of vol_array as the underlying image data,
and with origin, spacing, and direction matrix set according to the affine matrix.
Since a vtkImageData is intended to represent image data on a structured grid with orthogonal axes, the upper-left 3x3 submatrix of the affine matrix should be an orthogonal matrix. There will be no error if it isn’t, since the “direction matrix” of a vtkImageData can be set to be non-orthogonal – it just isn’t the intended usage of vtkImageData and could be misinterpreted by downstream vtk filters.
Maintain a reference to vol_array, so that it is not garbage collected (which could leave the vtkImageData pointing to invalid memory – see vtk.util.numpy_support.numpy_to_vtk documentation).