void RunRigid() { _initialTransform = InitialTransform::New(); _initialTransform->SetFixedParameters(_centerOfRotation); OptiReporter::Pointer optiReporter = OptiReporter::New(); Metric::Pointer metric = Metric::New(); metric->SetFixedImage(_dst); metric->SetMovingImage(_src); metric->SetInterpolator(Interpolator::New()); metric->SetTransform(_initialTransform); //metric->SetFixedImageRegion(_dst->GetBufferedRegion()); metric->SetFixedImageIndexes(_labelIndexes); // metric->SetUseAllPixels(true); metric->Initialize(); Optimizer::Pointer opti = Optimizer::New(); opti->SetCostFunction(metric); Optimizer::ScalesType scales; scales.SetSize(InitialTransform::ParametersDimension); scales.Fill(1); //scales[0] = scales[1] = scales[2] = .1; opti->SetUseUnitLengthGradient(true); opti->SetScales(scales); opti->SetInitialPosition(_initialTransform->GetParameters()); opti->AddObserver(itk::StartEvent(), optiReporter); opti->AddObserver(itk::IterationEvent(), optiReporter); opti->StartOptimization(); cout << "Current Cost: " << opti->GetCurrentCost() << endl; _initialResult = opti->GetCurrentPosition(); _initialTransform->SetParameters(opti->GetCurrentPosition()); }
void RunNine() { _finalTransform = NineTransform::New(); // NineTransform::OutputVectorType initialTranslation; // initialTranslation[0] = _initialResult[0]; // initialTranslation[1] = _initialResult[1]; // initialTranslation[2] = _initialResult[2]; // _finalTransform->SetTranslation(initialTranslation); _finalTransform->SetFixedParameters(_centerOfRotation); OptiReporter::Pointer optiReporter = OptiReporter::New(); Metric::Pointer metric = Metric::New(); metric->SetFixedImage(_dst); metric->SetMovingImage(_src); metric->SetInterpolator(InterpolatorNN::New()); metric->SetTransform(_finalTransform); metric->SetFixedImageIndexes(_labelIndexes); // metric->SetUseAllPixels(true); metric->Initialize(); Optimizer::Pointer opti = Optimizer::New(); opti->SetCostFunction(metric); Optimizer::ScalesType scales; scales.SetSize(NineTransform::ParametersDimension); scales.Fill(1); scales[0] = scales[1] = scales[2] = 10; scales[6] = scales[7] = scales[8] = 100; opti->SetMaximumIteration(500); opti->SetUseUnitLengthGradient(true); opti->SetStepLength(0.5); opti->SetScales(scales); opti->SetInitialPosition(_finalTransform->GetParameters()); opti->AddObserver(itk::StartEvent(), optiReporter); opti->AddObserver(itk::IterationEvent(), optiReporter); opti->StartOptimization(); cout << "Current Cost: " << opti->GetCurrentCost() << endl; _finalResult = opti->GetCurrentPosition(); _finalTransform->SetParameters(opti->GetCurrentPosition()); }