Example of reading and displaying DICOM file by Python VTK

Time:2021-1-10

Because of the project, I came into contact with DICOM file of medical image. VTK just started to see, here is just its simplest read display function. The VTK library is used here. You can install it by yourself.

The code is attached below:


from vtk import *

# reader the dicom file
reader = vtkDICOMImageReader()
reader.SetDataByteOrderToLittleEndian()
reader.SetFileName("00efb2fedf64b867a36031a394e5855a.dcm")
reader.Update()

# show the dicom flie
imageViewer = vtkImageViewer2()
imageViewer.SetInputConnection(reader.GetOutputPort())
renderWindowInteractor = vtkRenderWindowInteractor()
imageViewer.SetupInteractor(renderWindowInteractor)
imageViewer.Render()
imageViewer.GetRenderer().ResetCamera()
imageViewer.Render()
renderWindowInteractor.Start()

Run the program to get the display

DICOM image display can be set window width, window level, is still learning to try, if the effect is good, then update.

The above Python VTK read and display DICOM file example is the whole content shared by Xiaobian. I hope it can give you a reference, and I hope you can support developer more.

Recommended Today

Summary of recent use of gin

Recently, a new project is developed by using gin. Some problems are encountered in the process. To sum up, as a note, I hope it can help you. Cross domain problems Middleware: func Cors() gin.HandlerFunc { return func(c *gin.Context) { //Here you can use * or the domain name you specify c.Header(“Access-Control-Allow-Origin”, “*”) //Allow header […]