VTK ImageData 与ITK、SimpleITK

Table of contents

VTK、ITK、SimpleITK

 ITK

VTK image data structure

Image header information

image data

vtkImageData


VTK、ITK、SimpleITK

For medical image processing, it is recommended to use ITK+VTK, ITK is used as the underlying image processing algorithm, VTK is used for visual display, and itkImageToVTKImageFilter is used between ITK and VTK

vtk_image = itk.vtk_image_from_image(image)

image = itk.image_from_vtk_image(vtk_image)

VTK is developed on the basis of the three-dimensional function library OpenGL using an object-oriented design method. It shields the details that we often encounter in the visualization development process and encapsulates some commonly used algorithms.

 ITK

In the Python dictionary interface to image metadata, keys for the spatial metadata, the ‘origin’‘spacing’, and ‘direction’, are reversed in order from image.GetOrigin(), image.GetSpacing(), image.GetDirection() to be consistent with the NumPy array index order resulting from pixel buffer array views on the image.

VTK image data structure

Digital image file content consists of two parts:

Image header information and data.

Image header information

The image header information defines the basic information of the image,

It mainly includes the starting position (Origin), pixel interval (space) and dimension (dimension).

Through these three parameters, the spatial position and scale of the image can be determined.

An image can be regarded as a regular grid in space, and each smallest unit in the grid is called a pixel (two-dimensional) or voxel (three-dimensional)

In this way, the number of pixels or voxels of the grid in each direction is the dimension of the image in this direction .

The pixel index indicates the position of each pixel in the image grid, which is the grid coordinate inside the image .

In medical images, in addition to internal coordinates , each image also has a world coordinate .

  • The origin position (Origin), which is the position of [0,0,0] (first pixel index) in 3D space
  • Pixel interval (space), (the size of voxels in each direction x, y, z)
  • Image dimension (dimension), how many voxel units are there in each direction (as shown in the small ball)

In this way, the world coordinate position of each pixel can be calculated through the starting point position, pixel interval and pixel index .

World coordinate calculation :

RAS conversion to pixel coordinates

Taking a two-dimensional image as an example, the third dimension is 1, the point is 0, and the pixel interval is 1

GetOutput()->GetOrigin(origin) ( CenterImage() meeting SetOutputOrigin() )

Calculate the width and height of the new image according to the dimension and pixel interval of the image to be (512-1)*5, the origin of the initial image is at (0, 0, 0), now the center of the image is translated to the origin, the amount of translation is (-(512-1)*5/2,(512-1)*5/2, 0) = (-1277.5, -1275.5,0).

With the origin and spacing , the corresponding position of each (image coordinate) voxel in anatomical coordinates can be calculated .

The difference between extent (range) and dimension (dimension)

extent=[0,511,0,511,0,49]
dimensions=[512,512,50]

This figure represents a 4x2x3 image, which is the dimension of the image, and each small ball represents a pixel; and

The origin of the image is (5.1,10.0,6.5),

The interval between two pixels represents the pixel interval, and the pixel interval in each direction is 1.5, 1.5, and 1.8.

image data

Image data is the pixel value of an image pixel, which is generally expressed and stored in a one-dimensional array. Knowing the pixel index and image dimension, the pixel value corresponding to each pixel can be calculated. Usually the pixel value of an image is a scalar, such as a general grayscale image.

Most images in medical image processing are grayscale images.

Here you need to pay attention to the data type of the grayscale value of the grayscale image, which does not need to be considered in general grayscale image processing, because its range is 0-255 by default, and it can be represented by an unsigned char type class.

However, in medical image processing, 256 gray levels are far from meeting the requirements, so the gray scale range is often greater than 256 levels.

The pixel data type of common medical images is unsigned short, and the grayscale range is 0-65536.

In addition, sometimes int, float or even double types are used for precision considerations, so special attention is required.

vtkImageData

vtkImageData can be used to read Reader and save Writer of images in different formats

The data of the vtk 3D model mainly includes: point point, line edge, surface surface, attribute scalar of point line surface, color table lookuptable,

 xyz012,zxy201

POINTS 989 float//A total of 989 points, and the coordinates of the points are stored in float type.
-0.300020 -0.500000 0.000000//Three-dimensional x, y, z coordinates of the 0th point

Reference link:

05-Application of VTK in image processing (1)-card core

Quick start guide — ITKPythonPackage documentation

VTK: Notes on the relationship between geometry, topology, cell, cellarray, and polydata

Guess you like

Origin blog.csdn.net/qq_28838891/article/details/127518394