~ubuntu-branches/debian/sid/simpleitk/sid

« back to all changes in this revision

Viewing changes to Examples/DemonsRegistration1/DemonsRegistration1.cxx

  • Committer: Package Import Robot
  • Author(s): Ghislain Antony Vaillant
  • Date: 2017-11-02 08:49:18 UTC
  • Revision ID: package-import@ubuntu.com-20171102084918-7hs09ih668xq87ej
Tags: upstream-1.0.1
ImportĀ upstreamĀ versionĀ 1.0.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*=========================================================================
 
2
*
 
3
*  Copyright Insight Software Consortium
 
4
*
 
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
 
8
*
 
9
*         http://www.apache.org/licenses/LICENSE-2.0.txt
 
10
*
 
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.
 
16
*
 
17
*=========================================================================*/
 
18
 
 
19
// This example is based on ITK's DeformableRegistration2.cxx example
 
20
 
 
21
 
 
22
#include <SimpleITK.h>
 
23
#include <iostream>
 
24
#include <stdlib.h>
 
25
#include <iomanip>
 
26
 
 
27
namespace sitk = itk::simple;
 
28
 
 
29
 
 
30
class IterationUpdate
 
31
  : public sitk::Command
 
32
{
 
33
public:
 
34
  IterationUpdate( const sitk::DemonsRegistrationFilter &m)
 
35
    : m_Filter(m)
 
36
    {}
 
37
 
 
38
  virtual void Execute( )
 
39
    {
 
40
      // use sitk's output operator for std::vector etc..
 
41
      using sitk::operator<<;
 
42
 
 
43
      // stash the stream state
 
44
      std::ios  state(NULL);
 
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;
 
50
 
 
51
      std::cout.copyfmt(state);
 
52
    }
 
53
 
 
54
private:
 
55
  const sitk::DemonsRegistrationFilter &m_Filter;
 
56
 
 
57
};
 
58
 
 
59
 
 
60
 
 
61
int main(int argc, char *argv[])
 
62
{
 
63
 
 
64
  if ( argc < 4 )
 
65
    {
 
66
    std::cerr << "Usage: " << argv[0] << " <fixedImageFilter> <movingImageFile> <outputTransformFile>" << std::endl;
 
67
    return 1;
 
68
    }
 
69
 
 
70
  sitk::Image fixed = sitk::ReadImage( argv[1], sitk::sitkFloat32 );
 
71
 
 
72
  sitk::Image moving = sitk::ReadImage( argv[2], sitk::sitkFloat32 );
 
73
 
 
74
  sitk::HistogramMatchingImageFilter matcher;
 
75
  matcher.SetNumberOfHistogramLevels( 1024 );
 
76
  matcher.SetNumberOfMatchPoints( 7 );
 
77
  matcher.ThresholdAtMeanIntensityOn();
 
78
  moving = matcher.Execute(moving, fixed);
 
79
 
 
80
  sitk::DemonsRegistrationFilter filter;
 
81
 
 
82
  IterationUpdate cmd(filter);
 
83
  filter.AddCommand( sitk::sitkIterationEvent, cmd );
 
84
 
 
85
  filter.SetNumberOfIterations( 50 );
 
86
  filter.SetStandardDeviations( 1.0 );
 
87
 
 
88
  sitk::Image displacementField = filter.Execute( fixed, moving );
 
89
 
 
90
  std::cout << "-------" << std::endl;
 
91
  std::cout << "Number Of Iterations: " << filter.GetElapsedIterations() << std::endl;
 
92
  std::cout << " RMS: " << filter.GetRMSChange() << std::endl;
 
93
 
 
94
  sitk::DisplacementFieldTransform outTx( displacementField );
 
95
 
 
96
  sitk::WriteTransform(outTx, argv[3]);
 
97
 
 
98
  return 0;
 
99
}