itk中图像2d-3d配准整理

示例代码


#include "itkTwoProjectionImageRegistrationMethod.h"
#include "itkEuler3DTransform.h"
#include "itkNormalizedCorrelationTwoImageToOneImageMetric.h"
#include "itkSiddonJacobsRayCastInterpolateImageFunction.h"
#include "itkPowellOptimizer.h"
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"
#include "itkResampleImageFilter.h"
#include "itkCastImageFilter.h"
#include "itkRescaleIntensityImageFilter.h"
#include "itkFlipImageFilter.h"
#include "itkCommand.h"
#include "itkTimeProbesCollectorBase.h"

class CommandIterationUpdate : public itk::Command
{
   
public:
  using Self = CommandIterationUpdate;
  using Superclass = itk::Command;
  using Pointer = itk::SmartPointer<Self>;
  itkNewMacro(Self);

protected:
  CommandIterationUpdate() = default;

public:
  using OptimizerType = itk::PowellOptimizer;
  using OptimizerPointer = const OptimizerType *;

  void
  Execute(itk::Object * caller, const itk::EventObject & event) override
  {
   
    Execute((const itk::Object *)caller, event);
  }

  void
  Execute(const itk::Object * object, const itk::EventObject & event) override
  {
   
    auto optimizer = dynamic_cast<OptimizerPointer>(object);
    if (typeid(event) != typeid(itk::IterationEvent))
    {
   
      return;
    }
    //    std::cout << "Iteration: " << optimizer->GetCurrentIteration() << std::endl;
    std::cout << "Similarity: " << optimizer->GetValue() << std::endl;
    std::cout << "Position: " << optimizer->GetCurrentPosition() << std::endl;
  }
};

void exe_usage()
{
   
    std::cerr << "\n";
    std::cerr << "Usage: TwoProjection2D3DRegistration  Image2D1 ProjAngle1 Image2D2 ProjAngle2 Volume3D\n";
    std::cerr << "       Registers two 2D images to a 3D volume. \n\n";
    std::cerr << "   where  is one or more of the following:\n\n";
    std::cerr << "       <-h>                     Display (this) usage information\n";
    std::cerr << "       <-v>                     Verbose output [default: no]\n";
    std::cerr << "       <-dbg>                   Debugging output [default: no]\n";
    std::cerr << "       <-scd float>             Source to isocenter distance [default: 1000mm]\n";
    std::cerr << "       <-t float float float>   CT volume translation in x, y, and z direction in mm \n";
    std::cerr << "       <-rx float>              CT volume rotation about x axis in degrees \n";
    std::cerr << "       <-ry float>              CT volume rotation about y axis in degrees \n";
    std::cerr << "       <-rz float>              CT volume rotation about z axis in degrees \n";
    std::cerr
            << "       <-2dcx float float float float>    Central axis positions of the 2D images in continuous indices \n";
    std::cerr << "       <-res float float float float>     Pixel spacing of projection images in the isocenter plane "
                 "[default: 1x1 mm]  \n";
    std::cerr << "       <-iso float float float> Isocenter location in voxel in indices (center of rotation and "
                 "projection center)\n";
    std::cerr << "       <-threshold float>       Intensity threshold below which are ignore [default: 0]\n";
    std::cerr << "       <-o file>                Output image filename\n\n";
    std::cerr << "                                by  Jian Wu\n";
    std::cerr << "                                [email protected]\n";
    std::cerr << "                                (Univeristy of Florida)\n\n";
    exit(EXIT_FAILURE);
}

#include "itkTIFFImageIOFactory.h"
#include "itkMetaImageIO.h"
int main(int argc, char *argv[])
{
   
//    QCoreApplication a(argc, argv);
//    return a.exec();
    itk::TIFFImageIOFactory::RegisterOneFactory();

    char* fileImage2D1 = nullptr;//./data/RDD/metric/part_0.tif
    double projAngle1 = -1;//0
    char* fileImage2D2 = nullptr;//./data/RDD/metric/part_1.tif
    double projAngle2 = -1;//90
    char* fileVolume3D = nullptr;//D:\\ctdata\\spine\\spineL11.mhd
    // Default output file names
    const char * fileOutput1 = "./Image2D1_Registered.tif";
    const char * fileOutput2 = "./Image2D2_Registered.tif";

    bool ok;
    bool verbose = true;
    bool debug = true;
    bool customized_iso = false;
    bool customized_2DCX = false;  // Flag for customized 2D image central axis positions
    bool customized_2DRES = false; // Flag for customized 2D image pixel spacing

    double rx = 0.;
    double ry = 0.;
    double rz = 0.;

    double tx = 0.;
    double ty = 0.;
    double tz = 0.;

    double cx = 0.;
    double cy = 0.;
    double cz = 0.;

    double scd = 1000.; // Source to isocenter distance

    double image1centerX = 0.0;
    double image1centerY = 0.0;
    double image2centerX = 0.0;
    double image2centerY = 0.0;

    double image1resX = 1.0;
    double image1resY = 1.0;
    double image2resX = 1.0;
    double image2resY = 1.0;
    if(argc < 5){
   
        exe_usage();
    }
    double threshold = -600;
    // -scd 1000 -t 1.0 -1.0 1.0 -rx 2 -ry 3 -rz 4
    //D:/ctdata/spine/regis/part_0.tif 0 D:/ctdata/spine/regis/part_1.tif 90 D:/ctdata/spine/spineL11.mhd
    while (argc > 1) {
   
        ok = false;
        if ((ok == false) && (strcmp(argv[1], "-scd") == 0))
        {
   
          argc--;
          argv++;
          ok = true;
          scd = atof(argv[1]);
          argc--;
          argv++;
        }
        if ((ok == false) && (strcmp(argv[1], "-threshold") == 0))
        {
   
          argc--;
          argv++;
          ok = true;
          threshold = atof(argv[1]);
          argc

你可能感兴趣的:(ITK,2d-3d,itk)