Seg3D  2.4
Seg3D is a free volume segmentation and processing tool developed by the NIH Center for Integrative Biomedical Computing at the University of Utah Scientific Computing and Imaging (SCI) Institute.
itkImageMosaicVarianceMetric.h
1 /*
2  For more information, please see: http://software.sci.utah.edu
3 
4  The MIT License
5 
6  Copyright (c) 2016 Scientific Computing and Imaging Institute,
7  University of Utah.
8 
9 
10  Permission is hereby granted, free of charge, to any person obtaining a
11  copy of this software and associated documentation files (the "Software"),
12  to deal in the Software without restriction, including without limitation
13  the rights to use, copy, modify, merge, publish, distribute, sublicense,
14  and/or sell copies of the Software, and to permit persons to whom the
15  Software is furnished to do so, subject to the following conditions:
16 
17  The above copyright notice and this permission notice shall be included
18  in all copies or substantial portions of the Software.
19 
20  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
21  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
22  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
23  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
24  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
25  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
26  DEALINGS IN THE SOFTWARE.
27 */
28 
29 // File : itkImageMosaicVarianceMetric.h
30 // Author : Pavel A. Koshevoy
31 // Created : 2005/06/22 17:19
32 // Copyright : (C) 2004-2008 University of Utah
33 // Description : A metric class measuring mean pixel variance within
34 // the mosaic tile overlap regions. The metric derivative
35 
36 #ifndef __itkImageMosaicVarianceMetric_h
37 #define __itkImageMosaicVarianceMetric_h
38 
39 #include <itkImageBase.h>
40 #include <itkTransform.h>
41 #include <itkInterpolateImageFunction.h>
42 #include <itkSingleValuedCostFunction.h>
43 #include <itkExceptionObject.h>
44 #include <itkGradientRecursiveGaussianImageFilter.h>
45 
60 namespace itk
61 {
62 
68 template <class TImage, class TInterpolator>
69 class ITK_EXPORT ImageMosaicVarianceMetric : public SingleValuedCostFunction
70 {
71 public:
74  typedef SingleValuedCostFunction Superclass;
75  typedef SmartPointer<Self> Pointer;
76  typedef SmartPointer<const Self> ConstPointer;
77 
79  itkNewMacro(Self);
80 
82  itkTypeMacro(ImageMosaicVarianceMetric, SingleValuedCostFunction);
83 
85  typedef TInterpolator interpolator_t;
86  typedef TImage image_t;
87  typedef typename TImage::PixelType pixel_t;
88 
90  itkStaticConstMacro(ImageDimension, unsigned int, TImage::ImageDimension);
91 
92  typedef itk::Image<unsigned char,
93  itkGetStaticConstMacro(ImageDimension)> mask_t;
94 
96  typedef Transform<Superclass::ParametersValueType,
97  itkGetStaticConstMacro(ImageDimension),
98  itkGetStaticConstMacro(ImageDimension)> transform_t;
99 
100  typedef typename transform_t::InputPointType point_t;
101  typedef typename transform_t::ParametersType params_t;
102  typedef typename transform_t::JacobianType jacobian_t;
103 
105  // typedef typename NumericTraits<pixel_t>::RealType
106  typedef float
108 
109  typedef CovariantVector<scalar_t, itkGetStaticConstMacro(ImageDimension)>
110  gradient_pixel_t;
111 
112  typedef Image<gradient_pixel_t, itkGetStaticConstMacro(ImageDimension)>
113  gradient_image_t;
114 
115  typedef GradientRecursiveGaussianImageFilter<image_t, gradient_image_t>
116  gradient_filter_t;
117 
119  typedef Superclass::MeasureType measure_t;
120 
122  typedef Superclass::DerivativeType derivative_t;
123 
125  itkGetConstReferenceMacro( NumberOfPixelsCounted, unsigned long );
126 
128  itkSetMacro( MosaicRegion, typename image_t::RegionType );
129  itkGetConstReferenceMacro( MosaicRegion, typename image_t::RegionType );
130 
150  void setup_param_map(const std::vector<bool> & params_shared,
151  const std::vector<bool> & params_active);
152 
158  params_t GetTransformParameters() const;
159 
165  void SetTransformParameters(const params_t & parameters) const;
166 
172  unsigned int GetNumberOfParameters() const;
173 
177  virtual void Initialize() throw (ExceptionObject);
178 
180  measure_t GetValue(const params_t & parameters) const
181  {
182  measure_t measure;
183  derivative_t derivative;
184  GetValueAndDerivative(parameters, measure, derivative);
185  return measure;
186  }
187 
189  void GetDerivative(const params_t & parameters,
190  derivative_t & derivative) const
191  {
192  measure_t measure;
193  GetValueAndDerivative(parameters, measure, derivative);
194  }
195 
197  void GetValueAndDerivative(const params_t & parameters,
198  measure_t & value,
199  derivative_t & derivative) const;
200 
201  //----------------------------------------------------------------
202  // image_data_t
203  //
204  // This datastructure is used to speed up access to relevant
205  // information when evaluating GetValueAndDerivative:
206  //
208  {
209  public:
210  image_data_t():
211  id_(~0),
212  P_(measure_t(0)),
213  dPdx_(measure_t(0)),
214  dPdy_(measure_t(0))
215  {}
216 
217  // image id:
218  unsigned int id_;
219 
220  // image value:
221  measure_t P_;
222 
223  // partial derivative with respect to x:
224  measure_t dPdx_;
225 
226  // partial derivative with respect to y:
227  measure_t dPdy_;
228 
229  // a pointer to the Jacobian of the transform:
230  const jacobian_t * J_;
231  };
232 
233  // calculate the bounding box for a given set of image bounding boxes:
234  void CalcMosaicBBox(point_t & mosaic_min,
235  point_t & mosaic_max,
236  std::vector<point_t> & image_min,
237  std::vector<point_t> & image_max) const;
238 
239  // calculate the mosaic variance image as well as maximum and mean variance:
240  typename image_t::Pointer variance(measure_t & max_var,
241  measure_t & avg_var) const;
242 
243  typename image_t::Pointer variance(const typename TImage::SpacingType & sp,
244  const pnt2d_t & mosaic_min,
245  const pnt2d_t & mosaic_max,
246  measure_t & max_var,
247  measure_t & avg_var) const;
248 
249  typename image_t::Pointer variance(const typename TImage::SpacingType & sp,
250  const pnt2d_t & mosaic_min,
251  const typename TImage::SizeType & sz,
252  measure_t & max_var,
253  measure_t & avg_var) const;
254 
255  typename image_t::Pointer variance() const
256  {
257  measure_t max_var;
258  measure_t avg_var;
259  return variance(max_var, avg_var);
260  }
261 
262  // mosaic images:
263  std::vector<typename image_t::ConstPointer> image_;
264  std::vector<typename mask_t::ConstPointer> mask_;
265 
266  // image transforms (cascaded):
267  mutable std::vector<typename transform_t::Pointer> transform_;
268 
269  // image interpolators:
270  std::vector<typename interpolator_t::Pointer> interpolator_;
271 
272  // image gradients:
273  std::vector<typename gradient_image_t::ConstPointer> gradient_;
274 
275  // adresses of the individual transform parameter indices within the
276  // concatenated parameter vector:
277  std::vector<std::vector<unsigned int> > address_;
278 
279  // number of shared/unique parameters per transform:
280  unsigned int n_shared_;
281  unsigned int n_unique_;
282 
283  // this mask defines which of the individual transform parameters are
284  // active and will be included into the metric parameter vector:
285  std::vector<bool> param_active_;
286 
287 protected:
289  n_shared_(0),
290  n_unique_(0),
291  param_active_(0),
292  m_NumberOfPixelsCounted(0)
293  {}
294 
295  virtual ~ImageMosaicVarianceMetric()
296  {}
297 
298  // standard ITK debugging helper:
299  void PrintSelf(std::ostream & os, Indent indent) const;
300 
301  // number of pixels in the overlapping regions of the mosaic:
302  mutable unsigned long m_NumberOfPixelsCounted;
303 
304 private:
305  // unimplemented on purpose:
306  ImageMosaicVarianceMetric(const Self &);
307  void operator = (const Self &);
308 
309  typename image_t::RegionType m_MosaicRegion;
310 };
311 
312 } // end namespace itk
313 
314 #ifndef ITK_MANUAL_INSTANTIATION
315 #include <Core/ITKCommon/Optimizers/itkImageMosaicVarianceMetric.txx>
316 #endif // ITK_MANUAL_INSTANTIATION
317 
318 #endif // __itkImageMosaicVarianceMetric_h
Computes mean pixel variance within the overlapping regions of a mosaic.
Definition: itkImageMosaicVarianceMetric.h:69
Definition: itkNormalizeImageFilterWithMask.h:48
ImageMosaicVarianceMetric Self
Definition: itkImageMosaicVarianceMetric.h:73
Superclass::MeasureType measure_t
Definition: itkImageMosaicVarianceMetric.h:119
Transform< Superclass::ParametersValueType, itkGetStaticConstMacro(ImageDimension), itkGetStaticConstMacro(ImageDimension)> transform_t
Definition: itkImageMosaicVarianceMetric.h:98
Superclass::DerivativeType derivative_t
Definition: itkImageMosaicVarianceMetric.h:122
Definition: itkImageMosaicVarianceMetric.h:207
void GetDerivative(const params_t &parameters, derivative_t &derivative) const
Definition: itkImageMosaicVarianceMetric.h:189
float scalar_t
Definition: itkImageMosaicVarianceMetric.h:107
TInterpolator interpolator_t
Definition: itkImageMosaicVarianceMetric.h:85