Reading a ten ITK dcm image is then displayed by vtk

First, the function

  ITK by reading a picture (dcm format), and then displayed by vtk.

  Version: VS2019

      itk5.0.1

     vtk 8.2.0

Second, the main idea of ​​the program

  1- read dcm format images

  2- converted to data types that can be read vtk

  3- setting display parameters, and then displayed

Third, the code

  Engineered see previous blog, the code section as follows:

//保证VTK正常运行
#include "vtkAutoInit.h" 
VTK_MODULE_INIT(vtkRenderingOpenGL2); // VTK was built with vtkRenderingOpenGL2
VTK_MODULE_INIT(vtkInteractionStyle);

#include "itkImage.h"
#include "itkImageFileReader.h"
#include "itkGDCMImageIO.h"
#include "itkImageToVTKImageFilter.h"

#include <vtkSmartPointer.h>
#include <vtkImageActor.h>
#include <vtkRenderer.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h> 
#include <vtkInteractorStyleImage.h> int main ( int argc, char * the argv []) 
{ // Set the image type to read the using PixelType Signed = Short ;
     const unsigned int   the Dimension = 2 ; 
    typedef :: Image ITK <PixelType, the Dimension> ImageType; 
    typedef ImageFileReader ITK :: <ImageType> ReaderType;
     // read pointer 
    ReaderType the pointer Reader :: = ReaderType :: New ();
     // set the read file 
    reader-> SetFileName (


    
    
    "D:\\Files\\Data\\3219032438350584179-8\\DICOM\\S258070\\S20\\I10");
    //创建读取DCM的GDCMIOImage类
    using ImageIOType =itk::GDCMImageIO;
    ImageIOType::Pointer gdcmImageIO = ImageIOType::New();
    reader->SetImageIO(gdcmImageIO);
    try
    {
        reader->Update();
    }
    catch (itk::ExceptionObject& e)
    {
        std::cerr << "exception in file reader" << std::endl;
        std::cerr << e << std::endl;
        return EXIT_FAILURE;
    }

    //链接滤波器,转换为VTK类型
    typedef itk::ImageToVTKImageFilter<ImageType> ConnectorType;
    ConnectorType::Pointer connector = ConnectorType::New();
    connector->SetInput(reader->GetOutput());
    try
    {
        connector->Update();
    }
    catch (itk::ExceptionObject& e)
    {
        std::cerr << "exception in file reader" << std::endl;
        std::cerr << e <<:: endl STD;
         return EXIT_FAILURE; 
    } 

    / * vtkImageActor rendered image in a 3D scene * / 
    vtkSmartPointer <vtkImageActor> the Actor = vtkImageActor :: New (); 
    the Actor -> SetInputData (connector-> GetOutput ()); 
    the Actor -> InterpolateOff (); 
    the Actor -> the Update (); 
    

    vtkSmartPointer <vtkRenderer> = the render vtkRenderer :: New (); 
    the render -> addActor (the Actor); 
    the render -> SetBackground ( 255 , . 1 , . 1 ); // set the window background color 

    vtkSmartPointer<vtkRenderWindow> window = vtkRenderWindow::New();
    window->SetSize(600, 600);       //设置窗口大小
    window->AddRenderer(render);
    window->SetWindowName("the CT picture ");//设置窗口名称

    vtkSmartPointer<vtkRenderWindowInteractor> interactor = vtkRenderWindowInteractor::New();
    interactor->SetRenderWindow(window);

    interactor->Initialize();
    interactor->Start();
    return 0;
}

Fourth, the results show

  Here note, I found a different interpretation If the read type, show the effect will be different:

  For example, if the image format is:

// Set the image type to read 
    the using PixelType = unsigned char ;
     const unsigned int   the Dimension = 2 ; 
    typedef Image ITK :: <PixelType, the Dimension> ImageType;

  Picture effect is as follows:

  

   If the picture format is set as follows:

    // Set the image type to read 
    the using PixelType Signed = Short ;
     const unsigned int   the Dimension = 2 ; 
    typedef Image ITK :: <PixelType, the Dimension> ImageType;    

  Pictures show as follows:

  

   The feeling is not very clear.

V. References

  How realistic pictures of VTK: https://blog.csdn.net/shenziheng1/article/details/54565337

  The main source of the code: https://blog.csdn.net/cuihaolong/article/details/53943981

Guess you like

Origin www.cnblogs.com/fantianliang/p/12045201.html