1
/*=========================================================================
3
* Copyright Insight Software Consortium
5
* Licensed under the Apache License, Version 2.0 (the "License");
6
* you may not use this file except in compliance with the License.
7
* You may obtain a copy of the License at
9
* http://www.apache.org/licenses/LICENSE-2.0.txt
11
* Unless required by applicable law or agreed to in writing, software
12
* distributed under the License is distributed on an "AS IS" BASIS,
13
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
* See the License for the specific language governing permissions and
15
* limitations under the License.
17
*=========================================================================*/
19
// This example is based on ITK's DeformableRegistration2.cxx example
22
#include <SimpleITK.h>
27
namespace sitk = itk::simple;
31
: public sitk::Command
34
IterationUpdate( const sitk::DemonsRegistrationFilter &m)
38
virtual void Execute( )
40
// use sitk's output operator for std::vector etc..
41
using sitk::operator<<;
43
// stash the stream state
45
state.copyfmt(std::cout);
46
std::cout << std::fixed << std::setfill(' ') << std::setprecision( 5 );
47
std::cout << std::setw(3) << m_Filter.GetElapsedIterations();
48
std::cout << " = " << std::setw(10) << m_Filter.GetMetric();
49
std::cout << std::endl;
51
std::cout.copyfmt(state);
55
const sitk::DemonsRegistrationFilter &m_Filter;
61
int main(int argc, char *argv[])
66
std::cerr << "Usage: " << argv[0] << " <fixedImageFilter> <movingImageFile> <outputTransformFile>" << std::endl;
70
sitk::Image fixed = sitk::ReadImage( argv[1], sitk::sitkFloat32 );
72
sitk::Image moving = sitk::ReadImage( argv[2], sitk::sitkFloat32 );
74
sitk::HistogramMatchingImageFilter matcher;
75
matcher.SetNumberOfHistogramLevels( 1024 );
76
matcher.SetNumberOfMatchPoints( 7 );
77
matcher.ThresholdAtMeanIntensityOn();
78
moving = matcher.Execute(moving, fixed);
80
sitk::DemonsRegistrationFilter filter;
82
IterationUpdate cmd(filter);
83
filter.AddCommand( sitk::sitkIterationEvent, cmd );
85
filter.SetNumberOfIterations( 50 );
86
filter.SetStandardDeviations( 1.0 );
88
sitk::Image displacementField = filter.Execute( fixed, moving );
90
std::cout << "-------" << std::endl;
91
std::cout << "Number Of Iterations: " << filter.GetElapsedIterations() << std::endl;
92
std::cout << " RMS: " << filter.GetRMSChange() << std::endl;
94
sitk::DisplacementFieldTransform outTx( displacementField );
96
sitk::WriteTransform(outTx, argv[3]);