Hey Guys, I am running ITK registration examples V4 (
ImageRegistration4.cpp and the other on a roll), and I have a question:
How can I write the outputs in the
CommandIterationUpdate class at each iteration step into a txt file?
The outputs are:
std::cout << optimizer->GetCurrentIteration() << " ";
std::cout << optimizer->GetValue() << " ";
std::cout << optimizer->GetCurrentPosition() << std::endl;
I tried creating and opening a file inside
int main(), but the class
CommandIterationUpdate does not recognize it.
Can you guys give-me a help?
Adapted from this IJ source code:
class CommandIterationUpdate : public itk::Command
typedef CommandIterationUpdate Self;
typedef itk::Command Superclass;
typedef itk::SmartPointer<Self> Pointer;
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)
const TFilter* filter =
if (typeid(event) != typeid(itk::IterationEvent))
std::cout << " Iteration " << filter->GetElapsedIterations()
<< " (of "
<< "). ";
std::cout << " Current convergence value = "
<< " (threshold = " << filter->GetConvergenceThreshold()
<< ")" << std::endl;
// here you could access outputs like this:
// I haven't tried this so it might not work
typedef itk::N4MRIBiasFieldCorrectionImageFilter<ImageType, MaskImageType,
typedef CommandIterationUpdate<CorrecterType> CommandType;
typename CommandType::Pointer observer = CommandType::New();
I see. But I still did not get how can I write such values into a .txt file.
I got how
class CommandIterationUpdate but I do not know how can I say to that class to write such information at each iteration step.
That is more of a C++ question than ITK one.
Yes it sounds so. I’ll look around to see if I can find it.