itk中生成drr整理

生成drr

    char * input_name = "test.mhd";//三维体数据
    char * output_name = "test.tif";//生成的二维DRR

    float rx = 90.;
    float ry = 0.;
    float rz = 90.;

    float tx = 0.;
    float ty = 0.;
    float tz = 0.;

    float cx = 0.;
    float cy = 0.;
    float cz = 0.;

    float sid = 400.;

    float sx = 0.5;
    float sy = 0.5;

    int dx = 501;
    int dy = 501;

    float o2Dx = 0;
    float o2Dy = 0;

    double threshold = 0;

    //Although we generate a 2D projection of the 3D volume for the
    //purposes of the interpolator both images must be three dimensional.
    //尽管我们为插值器生成了 3D 体积的 2D 投影,但两个图像都必须是 3D 的。

    constexpr unsigned int Dimension = 3;
    using InputPixelType = short;
    using OutputPixelType = unsigned char;

    using InputImageType = itk::Image<InputPixelType, Dimension>;
    using OutputImageType = itk::Image<OutputPixelType, Dimension>;
    using OutputImageType2 = itk::Image<OutputPixelType, Dimension2D>;

    InputImageType::Pointer image;
    if(input_name){
   
        //读取dicom序列
    //    std::vector< std::string > stdvecfiles;
    //    QString tmpPath = "D:/ctdata/spine/renyouquan";
    //    readFileDir(stdvecfiles,tmpPath);
    //    qDebug() << "size:" << stdvecfiles.size();
    //    using ReaderType = itk::ImageSeriesReader< InputImageType >;
    //    ReaderType::Pointer reader = ReaderType::New();
    //    reader->SetFileNames(stdvecfiles);
    //    reader->ReverseOrderOn();
    //    using ImageIOType = itk::GDCMImageIO;
    //    ImageIOType::Pointer gdcmImageIO = ImageIOType::New();
    //    reader->SetImageIO(gdcmImageIO);
    //    try {
   
    //        reader->Update();
    //    }
        //读取mhd文件
        std::string image3dPath = "D:\\ctdata\\spine\\spineL11.mhd";
        using ReaderType = itk::ImageFileReader<InputImageType>;
        ReaderType::Pointer reader = ReaderType::New();
        reader->SetFileName(image3dPath);
        using ImageIOType = itk::MetaImageIO;
        ImageIOType::Pointer imageIO = ImageIOType::New();
        reader->SetImageIO(imageIO);
        reader->Update();
        image = reader->GetOutput();
    }else{
   
      // No input image specified so create a cube
      //未指定输入图像,因此创建一个立方体,创建一个itk::Image
      InputImageType::SpacingType spacing;
      spacing[0] = 3.;
      spacing[1] = 3.;
      spacing[2] = 3.;
      image->SetSpacing(spacing);
      InputImageType::PointType origin;
      origin[0] = 0.;
      origin[1] = 0.;
      origin[2] = 0.;
      image->SetOrigin(origin);
      InputImageType::IndexType start;
      start[0] = 0; // first index on X
      start[1] = 0; // first index on Y
      start[2] = 0; // first index on Z
      InputImageType::SizeType size;
      size[0] = 61; // size along X
      size[1] = 61; // size along Y
      size[2] = 61; // size along Z
      InputImageType::RegionType region;
      region.SetSize(size);
      region.SetIndex(start);

      image = InputImageType::New();
      image->SetRegions(region);
      image->Allocate(true); // initialize to zero.
      image->Update();

      using IteratorType = itk::ImageRegionIteratorWithIndex<InputImageType>;
      IteratorType iterate(image, 

你可能感兴趣的:(ITK,itk,drr)