I want make a registration function by ITK . And the code of my scripts is the same of Examples/RegistrationITKv4/ImageRegistration7.cxx . I am sure the code grammar is right. But the error (error C3861: “InsertSort”: identifier not found)represented when i run it . The code is bellow:
#include "itkImageRegistrationMethodv4.h"
#include "itkMeanSquaresImageToImageMetricv4.h"
#include "itkRegularStepGradientDescentOptimizerv4.h"
#include "itkCenteredTransformInitializer.h"
#include "itkCenteredSimilarity2DTransform.h"
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"
#include "itkResampleImageFilter.h"
#include "itkCastImageFilter.h"
#include "itkSubtractImageFilter.h"
#include "itkRescaleIntensityImageFilter.h"
#include "itkIdentityTransform.h"
#include "itkShrinkImageFilter.h"
#include "itkCommand.h"
#include<itkPNGImageIOFactory.h>
#include<itkJPEGImageIOFactory.h>
#include<itkBMPImageIOFactory.h>
#include<itkTIFFImageIOFactory.h>
////// Head for get file names in a folder
#include <io.h>
#include <vector>
using namespace std;
///////////
///// string and integer plus
#include <iostream>
#include <string>
#include <sstream>
class CommandIterationUpdate : public itk::Command
{
public:
typedef CommandIterationUpdate Self;
typedef itk::Command Superclass;
typedef itk::SmartPointer<Self> Pointer;
itkNewMacro(Self);
protected:
CommandIterationUpdate() {};
public:
typedef itk::RegularStepGradientDescentOptimizerv4<double> OptimizerType;
typedef const OptimizerType * OptimizerPointer;
void Execute(itk::Object *caller, const itk::EventObject & event)
{
Execute((const itk::Object *)caller, event);
}
void Execute(const itk::Object * object, const itk::EventObject & event)
{
OptimizerPointer optimizer =
dynamic_cast<OptimizerPointer>(object);
if (!itk::IterationEvent().CheckEvent(&event))
{
return;
}
std::cout << optimizer->GetCurrentIteration() << " ";
std::cout << optimizer->GetValue() << " ";
std::cout << optimizer->GetCurrentPosition() << std::endl;
}
};
int main()
{
//string filePath = "D:/Data/Gray_pic/gray"; //主文件夹路径
//vector<string> files; //子文件夹容器
//vector<string> files_update;
//////获取该路径下的所有文件
//getFiles(filePath, files);
//string a = "_.jpg";
//for (int i = 0; i < files.size(); i++)
//{
// if (files[i].find(a) == string::npos)
// {
// string b = files[i].substr(files[i].size() - 7);
// string c = b.substr(0, 3);
// files_update.push_back(c);
// }
//}
itk::PNGImageIOFactory::RegisterOneFactory();
itk::TIFFImageIOFactory::RegisterOneFactory();
itk::BMPImageIOFactory::RegisterOneFactory();
itk::JPEGImageIOFactory::RegisterOneFactory();
string s1 = "E:/ceshi/222/108.png";
string s2 = "E:/ceshi/222/106.png";
string s3 = "E:/ceshi/222/122.png";
//string fixedFilename = "Outputs/199.png";
//string movingFilename = "D:/Data/Gray_pic/gray/198.jpg";
//string outputFilename = "Outputs/198.png";
const unsigned int Dimension = 2;
typedef float PixelType;
typedef itk::Image< PixelType, Dimension > FixedImageType;
typedef itk::Image< PixelType, Dimension > MovingImageType;
using FixedImageReaderType = itk::ImageFileReader<FixedImageType>;
using MovingImagReaderType = itk::ImageFileReader<MovingImageType>;
FixedImageReaderType::Pointer fixedImageReader = FixedImageReaderType::New();
MovingImagReaderType::Pointer movingImageReader = MovingImagReaderType::New();
fixedImageReader->SetFileName(s1);
movingImageReader->SetFileName(s2);
typedef itk::CenteredSimilarity2DTransform< double > TransformType;
typedef itk::RegularStepGradientDescentOptimizerv4<double> OptimizerType;
typedef itk::MeanSquaresImageToImageMetricv4< FixedImageType,
MovingImageType > MetricType;
typedef itk::ImageRegistrationMethodv4< FixedImageType,
MovingImageType,
TransformType > RegistrationType;
MetricType::Pointer metric = MetricType::New();
OptimizerType::Pointer optimizer = OptimizerType::New();
RegistrationType::Pointer registration = RegistrationType::New();
registration->SetMetric(metric);
registration->SetOptimizer(optimizer);
TransformType::Pointer transform = TransformType::New();
typedef itk::CenteredTransformInitializer<TransformType,
FixedImageType,
MovingImageType > TransformInitializerType;
TransformInitializerType::Pointer initializer
= TransformInitializerType::New();
initializer->SetTransform(transform);
initializer->SetFixedImage(fixedImageReader->GetOutput());
initializer->SetMovingImage(movingImageReader->GetOutput());
initializer->MomentsOn();
initializer->InitializeTransform();
double initialScale = 0.5;
double initialAngle = 0.0;
transform->SetScale(initialScale);
transform->SetAngle(initialAngle);
registration->SetInitialTransform(transform);
registration->InPlaceOn();
typedef OptimizerType::ScalesType OptimizerScalesType;
OptimizerScalesType optimizerScales(transform->GetNumberOfParameters());
const double translationScale = 1.0 / 100.0; //1.0
optimizerScales[0] = 0.5; //1.5
optimizerScales[1] = 1.0;
optimizerScales[2] = translationScale;
optimizerScales[3] = translationScale;
optimizerScales[4] = translationScale;
optimizerScales[5] = translationScale;
optimizer->SetScales(optimizerScales);
double steplength = 1.0;
optimizer->SetLearningRate(steplength);
optimizer->SetMinimumStepLength(0.0001);
optimizer->SetNumberOfIterations(10000);
CommandIterationUpdate::Pointer observer = CommandIterationUpdate::New();
optimizer->AddObserver(itk::IterationEvent(), observer);
const unsigned int numberOfLevels = 1;
RegistrationType::ShrinkFactorsArrayType shrinkFactorsPerLevel;
shrinkFactorsPerLevel.SetSize(1);
shrinkFactorsPerLevel[0] = 1;
RegistrationType::SmoothingSigmasArrayType smoothingSigmasPerLevel;
smoothingSigmasPerLevel.SetSize(1);
smoothingSigmasPerLevel[0] = 0;
registration->SetNumberOfLevels(numberOfLevels);
registration->SetSmoothingSigmasPerLevel(smoothingSigmasPerLevel);
registration->SetShrinkFactorsPerLevel(shrinkFactorsPerLevel);
try
{
registration->Update();
std::cout << "Optimizer stop condition: "
<< registration->GetOptimizer()->GetStopConditionDescription()
<< std::endl;
}
catch (itk::ExceptionObject & err)
{
std::cerr << "ExceptionObject caught !" << std::endl;
std::cerr << err << std::endl;
return EXIT_FAILURE;
}
TransformType::ParametersType finalParameters =
transform->GetParameters();
const double finalScale = finalParameters[0];
const double finalAngle = finalParameters[1];
const double finalRotationCenterX = finalParameters[2];
const double finalRotationCenterY = finalParameters[3];
const double finalTranslationX = finalParameters[4];
const double finalTranslationY = finalParameters[5];
const unsigned int numberOfIterations = optimizer->GetCurrentIteration();
const double bestValue = optimizer->GetValue();
const double finalAngleInDegrees = finalAngle * 180.0 / vnl_math::pi;
std::cout << std::endl;
std::cout << "Result = " << std::endl;
std::cout << " Scale = " << finalScale << std::endl;
std::cout << " Angle (radians) " << finalAngle << std::endl;
std::cout << " Angle (degrees) " << finalAngleInDegrees << std::endl;
std::cout << " Center X = " << finalRotationCenterX << std::endl;
std::cout << " Center Y = " << finalRotationCenterY << std::endl;
std::cout << " Translation X = " << finalTranslationX << std::endl;
std::cout << " Translation Y = " << finalTranslationY << std::endl;
std::cout << " Iterations = " << numberOfIterations << std::endl;
std::cout << " Metric value = " << bestValue << std::endl;
TransformType::InputPointType rotationCenter;
rotationCenter[0] = finalParameters[2]; /////////////
rotationCenter[1] = finalParameters[3]; /////////////
TransformType::OutputVectorType finalTranslation;
finalTranslation[0] = finalParameters[4]; /////////////
finalTranslation[1] = finalParameters[5]; /////////////
TransformType::Pointer transform_Final = TransformType::New();
//transform_Final->SetParameters(transform->GetParameters());
transform_Final->SetScale(0.5); //finalParameters[0]
transform_Final->SetAngle(finalParameters[1]);
transform_Final->SetCenter(rotationCenter);
transform_Final->SetTranslation(finalTranslation);
typedef itk::ResampleImageFilter< MovingImageType,
FixedImageType > ResampleFilterType;
ResampleFilterType::Pointer resampler = ResampleFilterType::New();
resampler->SetTransform(transform_Final);
resampler->SetInput(movingImageReader->GetOutput());
FixedImageType::Pointer fixedImage = fixedImageReader->GetOutput();
resampler->SetSize(fixedImage->GetLargestPossibleRegion().GetSize());
resampler->SetOutputOrigin(fixedImage->GetOrigin());
resampler->SetOutputSpacing(fixedImage->GetSpacing());
resampler->SetOutputDirection(fixedImage->GetDirection());
resampler->SetDefaultPixelValue(100);
resampler->Update();
typedef unsigned char OutputPixelType;
typedef itk::Image< OutputPixelType, Dimension > OutputImageType;
typedef itk::CastImageFilter< FixedImageType, OutputImageType >
CastFilterType;
typedef itk::ImageFileWriter< OutputImageType > WriterType;
WriterType::Pointer writer = WriterType::New();
CastFilterType::Pointer caster = CastFilterType::New();
writer->SetFileName(s3); /////////////------->
caster->SetInput(resampler->GetOutput());
writer->SetInput(caster->GetOutput());
writer->Update();
return EXIT_SUCCESS;
}
The ERROR(partily is Chinese, main is English ) is bellow, I google it ,but not found the same question.if you caould solve it, please tell me, ,Thank you!
:\file_programe\itk\bin\include\itk-4.13\itkstatisticsalgorithm.hxx(533): error C3861: “InsertSort”: identifier not found
1>d:\file_programe\itk\bin\include\itk-4.13\itkstatisticsalgorithm.hxx(533): note: “InsertSort”: 函数未在模板定义上下文中声明,只能通过实例化上下文中参数相关的查找找到
1>d:\file_programe\itk\bin\include\itk-4.13\itkkdtreegenerator.hxx(171): note: 参见对正在编译的函数 模板 实例化“float itk::Statistics::Algorithm::NthElement<itk::Statistics::Subsample<TSample>>(TSubsample *,unsigned int,int,int,int)”的引用
1> with
1> [
1> TSample=itk::Statistics::VectorContainerToListSampleAdaptor<itk::VectorContainer<itk::DefaultStaticMeshTraits<float,2,2,float,float,float>::PointIdentifier,itk::Point<float,2>>>,
1> TSubsample=itk::Statistics::Subsample<itk::Statistics::VectorContainerToListSampleAdaptor<itk::VectorContainer<itk::DefaultStaticMeshTraits<float,2,2,float,float,float>::PointIdentifier,itk::Point<float,2>>>>
1> ]
1>d:\file_programe\itk\bin\include\itk-4.13\itkkdtreegenerator.hxx(131): note: 编译 类 模板 成员函数 "itk::Statistics::KdTreeNode<TSample> *itk::Statistics::KdTreeGenerator<TSample>::GenerateNonterminalNode(unsigned int,unsigned int,itk::Point<float,2> &,itk::Point<float,2> &,unsigned int)" 时
1> with
1> [
1> TSample=itk::Statistics::VectorContainerToListSampleAdaptor<itk::VectorContainer<itk::DefaultStaticMeshTraits<float,2,2,float,float,float>::PointIdentifier,itk::Point<float,2>>>
1> ]
1>d:\file_programe\itk\bin\include\itk-4.13\itkpointslocator.h(80): note: 参见对正在编译的 类 模板 实例化 "itk::Statistics::KdTreeGenerator<itk::Statistics::VectorContainerToListSampleAdaptor<itk::VectorContainer<itk::DefaultStaticMeshTraits<TPixelType,2,2,float,float,TPixelType>::PointIdentifier,itk::Point<float,2>>>>" 的引用
1> with
Os:Windows 10
IDE:Visual Studio 2017;
ITK version : 4.13;
Your code compiles fine for me with ITK 4.13.x branch. Can you try that please?
Your code compiles fine for me with ITK 4.13.x branch. Can you try that please?
Thank you for your replay!
I rebuild ITK 4.13.x branch codes by using Cmake,configuringd it with Visual Studio2017,But the the error is still hanppened. And I copy the ITK code rebuilt by Cmake from the Internet,the error is still exits.
Now I am crashed by this bug !
Interesting that the complaint is itkstatisticsalgorithm.hxx(533): error C3861: “InsertSort”: identifier not found, when InsertSort is defined few lines further, on line 539.
Can you configure ITK with ITK_LEGACY_REMOVE set to ON. It is OFF by default.
Interesting that the complaint is
itkstatisticsalgorithm.hxx(533): error C3861: “InsertSort”: identifier not found, whenInsertSortis defined few lines further, on line 539.Can you configure ITK with
ITK_LEGACY_REMOVEset to ON. It is OFF by default.
I configure ITK again by Cmake,and ITK_LEGACY_REMOVE set to ON. But the same error is still exits. It does not work.
This issue has been automatically marked as stale because it has not had recent activity. Thank you for your contributions.
Has this been fixed meanwhile?
Thank you! I have tried this method. I move the the codes from 533-5**(end of InsertSort function) to the front in the
itkstatisticsalgorithm.hxx. And it the error is none temporarily
Can you turn it into a pull request?
This issue has been automatically marked as stale because it has not had recent activity. Thank you for your contributions.