ITK  5.3.0
Insight Toolkit
itkImageRegistrationMethodImageSource.h
Go to the documentation of this file.
1 /*=========================================================================
2  *
3  * Copyright NumFOCUS
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  * https://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 #ifndef itkImageRegistrationMethodImageSource_h
19 #define itkImageRegistrationMethodImageSource_h
20 #include "itkImage.h"
23 #include "itkOptimizerParameters.h"
24 
34 namespace itk
35 {
36 
37 namespace testhelper
38 {
39 
40 template <typename TFixedPixelType, typename TMovingPixelType, unsigned int VDimension>
42 {
43 public:
45  using Superclass = Object;
49 
51  itkNewMacro(Self);
52 
55 
56 
59 
60  const MovingImageType *
62  {
63  return m_MovingImage.GetPointer();
64  }
65 
66  const FixedImageType *
67  GetFixedImage() const
68  {
69  return m_FixedImage.GetPointer();
70  }
71 
72  const ParametersType &
74  {
75  return m_Parameters;
76  }
77 
78 
79  void
81  {
82  const typename MovingImageType::RegionType region(size);
83 
84  m_MovingImage->SetRegions(region);
85  m_MovingImage->Allocate();
86 
87  m_FixedImage->SetRegions(region);
88  m_FixedImage->Allocate();
89 
90  /* Fill images with a 2D gaussian*/
91  using MovingImageIteratorType = itk::ImageRegionIteratorWithIndex<MovingImageType>;
92 
93  using FixedImageIteratorType = itk::ImageRegionIteratorWithIndex<FixedImageType>;
94 
95 
96  itk::Point<double, 2> center;
97  center[0] = static_cast<double>(region.GetSize()[0]) / 2.0;
98  center[1] = static_cast<double>(region.GetSize()[1]) / 2.0;
99 
100  const double s = static_cast<double>(region.GetSize()[0]) / 2.0;
101 
104 
105  /* Set the displacement */
106  itk::Vector<double, 2> displacement;
107  displacement[0] = m_Parameters[0];
108  displacement[1] = m_Parameters[1];
109 
110 
111  MovingImageIteratorType ri(m_MovingImage, region);
112  FixedImageIteratorType ti(m_FixedImage, region);
113  while (!ri.IsAtEnd())
114  {
115  p[0] = ri.GetIndex()[0];
116  p[1] = ri.GetIndex()[1];
117  d = p - center;
118  d += displacement;
119  const double x = d[0];
120  const double y = d[1];
121  const double value = 200.0 * std::exp(-(x * x + y * y) / (s * s));
122  ri.Set(static_cast<typename MovingImageType::PixelType>(value));
123  ++ri;
124  }
125 
126 
127  while (!ti.IsAtEnd())
128  {
129  p[0] = ti.GetIndex()[0];
130  p[1] = ti.GetIndex()[1];
131  d = p - center;
132  const double x = d[0];
133  const double y = d[1];
134  const double value = 200.0 * std::exp(-(x * x + y * y) / (s * s));
135  ti.Set(static_cast<typename FixedImageType::PixelType>(value));
136  ++ti;
137  }
138  }
139 
140 protected:
142  {
146  m_Parameters[0] = 7.0;
147  m_Parameters[1] = 3.0;
148  }
149 
150 private:
153 
155 };
156 
157 } // end namespace testhelper
158 
159 } // end namespace itk
160 #endif
itk::OptimizerParameters< double >
itk::testhelper::ImageRegistrationMethodImageSource::ParametersType
OptimizerParameters< double > ParametersType
Definition: itkImageRegistrationMethodImageSource.h:48
itk::testhelper::ImageRegistrationMethodImageSource::ImageRegistrationMethodImageSource
ImageRegistrationMethodImageSource()
Definition: itkImageRegistrationMethodImageSource.h:141
itk::Size
Represent a n-dimensional size (bounds) of a n-dimensional image.
Definition: itkSize.h:71
itkCommandIterationUpdate.h
itk::ImageRegion
An image region represents a structured region of data.
Definition: itkImageRegion.h:69
itk::testhelper::ImageRegistrationMethodImageSource::FixedImageType
itk::Image< TFixedPixelType, VDimension > FixedImageType
Definition: itkImageRegistrationMethodImageSource.h:58
itk::Vector
A templated class holding a n-Dimensional vector.
Definition: itkVector.h:62
itkImage.h
itk::ImageRegion::GetSize
const SizeType & GetSize() const
Definition: itkImageRegion.h:181
itk::SmartPointer< Self >
itkImageRegionIteratorWithIndex.h
itk::testhelper::ImageRegistrationMethodImageSource::m_MovingImage
MovingImageType::Pointer m_MovingImage
Definition: itkImageRegistrationMethodImageSource.h:152
itk::LightObject
Light weight base class for most itk classes.
Definition: itkLightObject.h:55
itkOptimizerParameters.h
itk::testhelper::ImageRegistrationMethodImageSource::GenerateImages
void GenerateImages(const typename MovingImageType::SizeType &size)
Definition: itkImageRegistrationMethodImageSource.h:80
itk::SmartPointer::GetPointer
ObjectType * GetPointer() const noexcept
Definition: itkSmartPointer.h:132
itk::testhelper::ImageRegistrationMethodImageSource
Definition: itkImageRegistrationMethodImageSource.h:41
itk::ImageRegionIteratorWithIndex
A multi-dimensional iterator templated over image type that walks pixels within a region and is speci...
Definition: itkImageRegionIteratorWithIndex.h:73
itk::testhelper::ImageRegistrationMethodImageSource::GetActualParameters
const ParametersType & GetActualParameters() const
Definition: itkImageRegistrationMethodImageSource.h:73
itk
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....
Definition: itkAnnulusOperator.h:24
itk::Image::New
static Pointer New()
itk::Object
Base class for most ITK classes.
Definition: itkObject.h:62
itk::testhelper::ImageRegistrationMethodImageSource::GetFixedImage
const FixedImageType * GetFixedImage() const
Definition: itkImageRegistrationMethodImageSource.h:67
itk::Point< double, 2 >
itk::Image
Templated n-dimensional image class.
Definition: itkImage.h:88
itk::testhelper::ImageRegistrationMethodImageSource::m_Parameters
ParametersType m_Parameters
Definition: itkImageRegistrationMethodImageSource.h:154
itk::testhelper::ImageRegistrationMethodImageSource::GetMovingImage
const MovingImageType * GetMovingImage() const
Definition: itkImageRegistrationMethodImageSource.h:61
itk::Object::Object
Object()
itk::testhelper::ImageRegistrationMethodImageSource::m_FixedImage
FixedImageType::Pointer m_FixedImage
Definition: itkImageRegistrationMethodImageSource.h:151