示例代码
#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 << "Similarity: " << optimizer->GetValue() << std::endl;
std::cout << "Position: " << optimizer->GetCurrentPosition() << std::endl;
}
};
void exe_usage()
{
std::cerr << "\n";
std::cerr << "Usage: TwoProjection2D3DRegistration <options> Image2D1 ProjAngle1 Image2D2 ProjAngle2 Volume3D\n";
std::cerr << " Registers two 2D images to a 3D volume. \n\n";
std::cerr << " where <options> 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 << " eewujian@hotmail.com\n";
std::cerr << " (Univeristy of Florida)\n\n";
exit(EXIT_FAILURE);
}
#include "itkTIFFImageIOFactory.h"
#include "itkMetaImageIO.h"
int main(int argc, char *argv[])
{
itk::TIFFImageIOFactory::RegisterOneFactory();
char* fileImage2D1 = nullptr;
double projAngle1 = -1;
char* fileImage2D2 = nullptr;
double projAngle2 = -1;
char* fileVolume3D = nullptr;
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;
bool customized_2DRES = false;
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.;
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;
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