Preface:
VTK, (visualizationtoolkit) is an open-source, free software system for 3D computer graphics, image processing, and visualization. vtk is designed and implemented on object-oriented principles. its kernel is built in C++ and contains about 250,000 lines of code, more than 2,000 classes, and several conversion interface, so it is also free to use vtk in Java, Tcl/Tk and Python.
Introduction to Main Functions
(): The interface for reading pictures, through which you can set the position, size and dimension of the pictures to be read. It should be noted that if you need to read a column of two-dimensional pictures into a three-dimensional image you need to name some of the pictures into a natural order of 0, 1, 2, 3 ---, so that VTK can read the picture correctly. If you need to read other formats of the picture just need to function in the JPEG replaced by the corresponding format can be, such as PNG.
(): The 3D reconstruction function, MarchingCubes algorithm, is actually a divide-and-conquer approach, as it distributes the extraction of equivalent surfaces to be performed in each voxel (voxel). For each voxel being processed, a triangular face sheet is used to approximate the equivalent faces inside it. Each voxel is a small cube, and the process of constructing the triangular voxels "scans" each voxel as if it were a processor moving over the voxels, hence the name. --In the process of isosurface extraction, a series of two-dimensional sliced data is regarded as a three-dimensional data field, from which substances with a certain threshold are extracted and connected into triangular slices in a certain topological form, so the MC algorithm is also known as "isosurface extraction" (IsosurfaceExtraction). Algorithm. --In medical applications, the MC algorithm can be used to reconstruct the external contours of the human body, internal tissues and organs, enabling doctors to observe the spatial relationship between the organ of interest and the surrounding tissues directly on the 3D image.
import vtk # Define rendering windows, interaction modes aRender = () Renwin = () (aRender) iren = () (Renwin) # Define an image reading interface #Read a PNG image and replace it with PNG_Reader = () Jpg_Reader = () Jpg_Reader.SetNumberOfScalarComponents(1) Jpg_Reader.SetFileDimensionality(3) # Show that the image is three-dimensional # Define the image size, this row indicates that the image size is (512*512*240) Jpg_Reader.SetDataExtent(0, 512, 0, 512, 0, 240) # Setting the storage location of the image Jpg_Reader.SetFilePrefix("E:/outer/label/5/") # Set the image prefix name # indicates that the image is prefixed with a number (e.g.) Jpg_Reader.SetFilePattern("%s%") Jpg_Reader.Update() Jpg_Reader.SetDataByteOrderToLittleEndian() # Methods for calculating contours contour = () (Jpg_Reader.GetOutputPort()) () (0, 255) mapper = () (()) () actor = () (mapper) renderer = () ([0.1, 0.1, 0.5]) (actor) window = () (512, 512) (renderer) interactor = () (window) # Start displaying () () ()
Effective demonstration
to this article on Python-VTK batch read two-dimensional slices and display three-dimensional model of the article is introduced to this, more related Python-VTK read two-dimensional slices of the contents of the search for my previous articles or continue to browse the following related articles I hope that you will support me in the future more!