Orfeo Toolbox  4.0
otbKullbackLeiblerSupervizedDistanceImageFilter.txx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: ORFEO Toolbox
4  Language: C++
5  Date: $Date$
6  Version: $Revision$
7 
8 
9  Copyright (c) Centre National d'Etudes Spatiales. All rights reserved.
10  See OTBCopyright.txt for details.
11 
12  Copyright (c) Institut Telecom / Telecom Bretagne. All rights reserved.
13  See GETCopyright.txt for details.
14 
15  This software is distributed WITHOUT ANY WARRANTY; without even
16  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
17  PURPOSE. See the above copyright notices for more information.
18 
19 =========================================================================*/
20 
21 #ifndef __otbKullbackLeiblerSupervizedDistanceImageFilter_txx
22 #define __otbKullbackLeiblerSupervizedDistanceImageFilter_txx
23 
25 
26 namespace otb
27 {
28 
29 namespace Functor
30 {
31 
32 template <class TInput1, class TInput2, class TInputROIImage, class TOutput>
35 {
36  m_CumROI1 = NULL;
37  m_CumROI2 = NULL;
38 }
39 
40 template <class TInput1, class TInput2, class TInputROIImage, class TOutput>
43 {
44  delete m_CumROI1;
45  m_CumROI1 = NULL;
46 
47  delete m_CumROI2;
48  m_CumROI2 = NULL;
49 }
50 
51 template <class TInput1, class TInput2, class TInputROIImage, class TOutput>
52 void
54 ::Evaluate(const typename TInput1::ImageType * img1,
55  const typename TInput2::ImageType * img2,
56  const TInputROIImage * imgROI)
57 {
60 
63 
64  typename ROIConversionType1::Pointer convertion1 = ROIConversionType1::New();
65  convertion1->SetInputImage(img1);
66  convertion1->SetROIImage(imgROI);
67  convertion1->Update();
68 
69  if (m_CumROI1 != NULL) delete m_CumROI1;
70 
71  m_CumROI1 = new CumulantsForEdgeworth<ROIInputType1> (convertion1->GetOutput());
72 
73  if (!m_CumROI1->IsDataAvailable())
74  {
75  throw itk::ExceptionObject(__FILE__,
76  __LINE__,
77  "Cumulants estimated from ROI in image 1 are not usable",
78  ITK_LOCATION);
79  }
80 
83 
86 
87  typename ROIConversionType2::Pointer convertion2 = ROIConversionType2::New();
88  convertion2->SetInputImage(img2);
89  convertion2->SetROIImage(imgROI);
90  convertion2->Update();
91 
92  if (m_CumROI2 != NULL) delete m_CumROI2;
93 
94  m_CumROI2 = new CumulantsForEdgeworth<ROIInputType2> (convertion2->GetOutput());
95 
96  if (!m_CumROI2->IsDataAvailable())
97  {
98  throw itk::ExceptionObject(__FILE__,
99  __LINE__,
100  "Cumulants estimated from ROI in image 2 are not usable",
101  ITK_LOCATION);
102  }
103 }
104 
105 template <class TInput1, class TInput2, class TInputROIImage, class TOutput>
106 TOutput
108 ::operator() (const TInput1 &it1, const TInput2 &it2)
109  {
111 
112  if (!cum1.IsDataAvailable())
113  {
114  return static_cast<TOutput> (0.);
115  }
116 
118 
119  if (!cum2.IsDataAvailable())
120  {
121  return static_cast<TOutput> (0.);
122  }
123 
124  return static_cast<TOutput> (m_CumROI1->Divergence(cum1)
125  + m_CumROI2->Divergence(cum2));
126  }
127 
128 } // end of namespace Functor
129 
137 template <class TInputImage1, class TInputImage2, class TInputROIImage, class TOutputImage>
138 void
140 ::SetTrainingArea(const TInputROIImage * trainingImage)
141 {
142  this->itk::ProcessObject::SetNthInput(2, const_cast<TInputROIImage *>(trainingImage));
143 }
144 
145 template <class TInputImage1, class TInputImage2, class TInputROIImage, class TOutputImage>
146 void
149 {
150  typename TInputImage1::ConstPointer inputPtr1
151  = dynamic_cast<const TInputImage1*>(this->GetInput(0));
152  typename TInputImage2::ConstPointer inputPtr2
153  = dynamic_cast<const TInputImage2*>(this->GetInput(1));
154  typename TInputROIImage::ConstPointer trainingImage
155  = static_cast<const TInputROIImage *>(this->itk::ProcessObject::GetInput(2));
156 
157  this->GetFunctor().Evaluate(inputPtr1, inputPtr2, trainingImage);
158 }
159 
160 } // end of namespace otb
161 
162 #endif

Generated at Sat Mar 8 2014 16:03:07 for Orfeo Toolbox with doxygen 1.8.3.1