当前位置:   article > 正文

VTK读取DCM保存成png_vtk dcm 保存

vtk dcm 保存

VTK读取DCM保存成png

#include <vtkSmartPointer.h>
#include <vtkImageViewer2.h>
#include <vtkDICOMImageReader.h>
#include <vtkRenderWindow.h>
#include <vtkRenderWindowInteractor.h>
#include <vtkRenderer.h>
#include <vtkPNGWriter.h>
#include <vtkImageCast.h>

#include <vtkAutoInit.h>
VTK_MODULE_INIT(vtkRenderingOpenGL2)

int main(int argc, char* argv[])
{
    // Verify input arguments
    //if (argc != 2)
    //{
    //  std::cout << "Usage: " << argv[0]
    //      << " Filename(.img)" << std::endl;
    //  return EXIT_FAILURE;
    //}

    std::string inputFilename = "/home/tiger/dicom/data/test/004/CT_5fd5cc06429eb17f.dcm";

    // Read all the DICOM files in the specified directory.
    vtkSmartPointer<vtkDICOMImageReader> reader =
        vtkSmartPointer<vtkDICOMImageReader>::New();
    reader->SetFileName(inputFilename.c_str());
    reader->Update();

    // Visualize
    vtkSmartPointer<vtkImageViewer2> imageViewer =
        vtkSmartPointer<vtkImageViewer2>::New();
    imageViewer->SetInputConnection(reader->GetOutputPort());
    vtkSmartPointer<vtkRenderWindowInteractor> renderWindowInteractor =
        vtkSmartPointer<vtkRenderWindowInteractor>::New();
    imageViewer->SetupInteractor(renderWindowInteractor);
    imageViewer->Render();
    imageViewer->GetRenderer()->ResetCamera();
    imageViewer->Render();

    vtkSmartPointer<vtkImageCast> castFilter =
        vtkSmartPointer<vtkImageCast>::New();
    castFilter->SetOutputScalarTypeToUnsignedShort();
    castFilter->SetInputConnection(reader->GetOutputPort());
    castFilter->Update();

    vtkSmartPointer<vtkPNGWriter> writer =
        vtkSmartPointer<vtkPNGWriter>::New();
    writer->SetFileName("out.png");
    writer->SetInputConnection(castFilter->GetOutputPort());
    writer->Write();

    renderWindowInteractor->Start();

    return EXIT_SUCCESS;
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
// CMakeLists.txt
cmake_minimum_required(VERSION 3.3 FATAL_ERROR)

project(AnimateActors)

find_package(Qt5 REQUIRED Widgets)

# opencv
find_package(OpenCV REQUIRED )

find_package(VTK COMPONENTS
  vtkCommonColor
  vtkCommonCore
  vtkCommonDataModel
  vtkFiltersSources
  vtkInteractionStyle
  vtkRenderingContextOpenGL2
  vtkRenderingCore

  vtkIOExport
  vtkInteractionImage

  vtkRenderingFreeType
  vtkRenderingGL2PSOpenGL2
  vtkRenderingOpenGL2
  QUIET
)

if (NOT VTK_FOUND)
  message("Skipping AnimateActors: ${VTK_NOT_FOUND_MESSAGE}")
  return ()
endif()
message (STATUS "VTK_VERSION: ${VTK_VERSION}")
if (VTK_VERSION VERSION_LESS "8.90.0")
  # old system
  include(${VTK_USE_FILE})
  add_executable(AnimateActors MACOSX_BUNDLE AnimateActors.cxx )
  target_link_libraries(AnimateActors PRIVATE ${VTK_LIBRARIES} ${OpenCV_LIBS} Qt5::Widgets)
else ()
  # include all components
  add_executable(AnimateActors MACOSX_BUNDLE AnimateActors.cxx )
  target_link_libraries(AnimateActors PRIVATE ${VTK_LIBRARIES} ${OpenCV_LIBS} Qt5::Widgets)
  # vtk_module_autoinit is needed
  vtk_module_autoinit(
    TARGETS AnimateActors
    MODULES ${VTK_LIBRARIES}
    )
endif ()

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/不正经/article/detail/520690
推荐阅读
相关标签
  

闽ICP备14008679号