SIRF  3.6.0
Resample.h
Go to the documentation of this file.
1 /*
2 SyneRBI Synergistic Image Reconstruction Framework (SIRF)
3 Copyright 2017 - 2020 University College London
4 
5 This is software developed for the Collaborative Computational
6 Project in Synergistic Reconstruction for Biomedical Imaging (formerly CCP PETMR)
7 (http://www.ccpsynerbi.ac.uk/).
8 
9 Licensed under the Apache License, Version 2.0 (the "License");
10 you may not use this file except in compliance with the License.
11 You may obtain a copy of the License at
12 http://www.apache.org/licenses/LICENSE-2.0
13 Unless required by applicable law or agreed to in writing, software
14 distributed under the License is distributed on an "AS IS" BASIS,
15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 See the License for the specific language governing permissions and
17 limitations under the License.
18 
19 */
20 
30 #pragma once
31 
32 #include <vector>
33 #include <memory>
35 #include "sirf/iUtilities/iutilities.h"
36 #include "sirf/common/JacobiCG.h"
37 
38 
39 namespace sirf {
40 
41 // Forward declarations
42 template<class dataType> class Transformation;
43 class ImageData;
44 
56 template<class dataType>
57 class Resampler
58 {
59 public:
60 
63  NOTSET = -1,
64  NEARESTNEIGHBOUR = 0,
65  LINEAR = 1,
66  CUBICSPLINE = 3,
67  SINC = 4
68  };
69 
72 
74  virtual ~Resampler() {}
75 
77  virtual void set_reference_image(const std::shared_ptr<const ImageData> reference_image_sptr);
78 
80  virtual void set_floating_image(const std::shared_ptr<const ImageData> floating_image_sptr);
81 
83  virtual void add_transformation(const std::shared_ptr<const Transformation<dataType> > transformation_sptr);
84 
87 
89  virtual void set_interpolation_type(const enum InterpolationType type);
90 
93 
96 
99 
102 
105 
107  void set_padding_value(const float padding_value) { _padding_value = padding_value; }
108 
110  virtual void process() = 0;
111 
113  const std::shared_ptr<const ImageData> get_output_sptr() const { return _output_image_sptr; }
114 
116  virtual std::shared_ptr<ImageData> forward(const std::shared_ptr<const ImageData> input_sptr) = 0;
117 
119  virtual void forward(std::shared_ptr<ImageData> output_sptr, const std::shared_ptr<const ImageData> input_sptr) = 0;
120 
122  virtual std::shared_ptr<ImageData> adjoint(const std::shared_ptr<const ImageData> input_sptr) = 0;
123 
125  virtual void adjoint(std::shared_ptr<ImageData> output_sptr, const std::shared_ptr<const ImageData> input_sptr) = 0;
126 
128  virtual std::shared_ptr<ImageData> backward(const std::shared_ptr<const ImageData> input_sptr);
129 
131  virtual void backward(std::shared_ptr<ImageData> output_sptr, const std::shared_ptr<const ImageData> input_sptr);
132 
133  std::shared_ptr<const ImageData> reference_image_sptr() const
134  {
135  return _reference_image_sptr;
136  }
137  std::shared_ptr<const ImageData> floating_image_sptr() const
138  {
139  return _floating_image_sptr;
140  }
141  std::vector<std::shared_ptr<const Transformation<dataType> > > transformations_sptr() const
142  {
143  return _transformations;
144  }
145  virtual float norm(int num_iter, int verb) const = 0;
146 
147 protected:
148 
150  virtual void set_up() = 0;
151 
153  virtual void set_up_forward() = 0;
154 
156  virtual void set_up_adjoint() = 0;
157 
159  virtual void check_parameters();
160 
162  std::shared_ptr<const ImageData> _reference_image_sptr;
164  std::shared_ptr<const ImageData> _floating_image_sptr;
165 
167  std::vector<std::shared_ptr<const Transformation<dataType> > > _transformations;
168 
171 
173  std::shared_ptr<ImageData> _output_image_sptr;
174 
176  float _padding_value = 0;
177  bool _need_to_set_up = true;
178  bool _need_to_set_up_forward = true;
179  bool _need_to_set_up_adjoint = true;
180 };
181 
183 template<class dataType>
184 class BFOperator : public Operator<Wrapped_sptr<ImageData, dataType> >{
185 public:
186  BFOperator(std::shared_ptr<Resampler<dataType> > sptr_r) : sptr_r_(sptr_r) {}
187  std::shared_ptr<Wrapped_sptr<ImageData, dataType> > apply(const Wrapped_sptr<ImageData, dataType>& wsptr)
188  {
189  std::shared_ptr<const ImageData> sptr_im = wsptr.sptr();
190  std::shared_ptr<ImageData> sptr_f = sptr_r_->forward(sptr_im);
191  std::shared_ptr<ImageData> sptr_bf = sptr_r_->backward(sptr_f);
192  return std::unique_ptr<Wrapped_sptr<ImageData, dataType> >(new Wrapped_sptr<ImageData, dataType>(sptr_bf));
193  }
194 private:
195  std::shared_ptr<Resampler<dataType> > sptr_r_;
196 };
197 
198 }
Base class for transformations.
Backward projection of the forward projected image.
Definition: Resample.h:184
Definition: Operator.h:7
Definition: Resample.h:58
virtual void set_interpolation_type(const enum InterpolationType type)
Set interpolation type (0=nearest neighbour, 1=linear, 3=cubic, 4=sinc)
Definition: Resample.cpp:64
const InterpolationType get_interpolation_type() const
Get interpolation type.
Definition: Resample.h:104
std::shared_ptr< ImageData > _output_image_sptr
Output image.
Definition: Resample.h:173
void set_interpolation_type_to_linear()
Set interpolation type to linear.
Definition: Resample.h:95
InterpolationType
Interpolation type.
Definition: Resample.h:62
Resampler()
Constructor.
Definition: Resample.h:71
virtual void set_reference_image(const std::shared_ptr< const ImageData > reference_image_sptr)
Set reference image. This is the image that would be the reference if you were doing a forward transf...
Definition: Resample.cpp:36
virtual void check_parameters()
Check parameters.
Definition: Resample.cpp:73
virtual void set_floating_image(const std::shared_ptr< const ImageData > floating_image_sptr)
Set floating image. This is the image that would be the floating if you were doing a forward transfor...
Definition: Resample.cpp:46
virtual std::shared_ptr< ImageData > forward(const std::shared_ptr< const ImageData > input_sptr)=0
Do the forward transformation.
virtual void set_up_forward()=0
Set up forward.
virtual std::shared_ptr< ImageData > backward(const std::shared_ptr< const ImageData > input_sptr)
Backward. Alias for Adjoint.
Definition: Resample.cpp:85
virtual void process()=0
Process. Equivalent of calling forward(floating_image). Use get_output to get resampled image.
std::vector< std::shared_ptr< const Transformation< dataType > > > _transformations
Transformations (could be mixture of affine, displacements, deformations).
Definition: Resample.h:167
void set_interpolation_type_to_cubic_spline()
Set interpolation type to cubic spline.
Definition: Resample.h:98
std::shared_ptr< const ImageData > _reference_image_sptr
Reference image.
Definition: Resample.h:162
virtual void set_up_adjoint()=0
Set up adjoint.
virtual ~Resampler()
Destructor.
Definition: Resample.h:74
const std::shared_ptr< const ImageData > get_output_sptr() const
Get output.
Definition: Resample.h:113
void set_padding_value(const float padding_value)
Set padding value.
Definition: Resample.h:107
virtual void adjoint(std::shared_ptr< ImageData > output_sptr, const std::shared_ptr< const ImageData > input_sptr)=0
Do the adjoint transformation.
virtual void add_transformation(const std::shared_ptr< const Transformation< dataType > > transformation_sptr)
Add transformation.
Definition: Resample.cpp:55
void set_interpolation_type_to_nearest_neighbour()
Set interpolation type to nearest neighbour.
Definition: Resample.h:92
virtual std::shared_ptr< ImageData > adjoint(const std::shared_ptr< const ImageData > input_sptr)=0
Do the adjoint transformation.
void set_interpolation_type_to_sinc()
Set interpolation type to sinc.
Definition: Resample.h:101
float _padding_value
Padding value.
Definition: Resample.h:176
std::shared_ptr< const ImageData > _floating_image_sptr
Floating image.
Definition: Resample.h:164
InterpolationType _interpolation_type
Interpolation type.
Definition: Resample.h:170
virtual void forward(std::shared_ptr< ImageData > output_sptr, const std::shared_ptr< const ImageData > input_sptr)=0
Do the forward transformation.
void clear_transformations()
Clear transformations.
Definition: Resample.h:86
virtual void set_up()=0
Set up.
Forward declarations.
Definition: Transformation.h:52
Definition: JacobiCG.h:166
Abstract data container.
Definition: GeometricalInfo.cpp:141