OTB  9.0.0
Orfeo Toolbox
otbKullbackLeiblerSupervizedDistanceImageFilter.hxx
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2022 Centre National d'Etudes Spatiales (CNES)
3  * Copyright (C) 2007-2012 Institut Mines Telecom / Telecom Bretagne
4  *
5  * This file is part of Orfeo Toolbox
6  *
7  * https://www.orfeo-toolbox.org/
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  *
13  * http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  */
21 
22 
23 #ifndef otbKullbackLeiblerSupervizedDistanceImageFilter_hxx
24 #define otbKullbackLeiblerSupervizedDistanceImageFilter_hxx
25 
27 
28 namespace otb
29 {
30 
31 namespace Functor
32 {
33 
34 template <class TInput1, class TInput2, class TInputROIImage, class TOutput>
36 {
37  m_CumROI1 = nullptr;
38  m_CumROI2 = nullptr;
39 }
40 
41 template <class TInput1, class TInput2, class TInputROIImage, class TOutput>
43 {
44  delete m_CumROI1;
45  m_CumROI1 = nullptr;
46 
47  delete m_CumROI2;
48  m_CumROI2 = nullptr;
49 }
50 
51 template <class TInput1, class TInput2, class TInputROIImage, class TOutput>
53  const typename TInput2::ImageType* img2,
54  const TInputROIImage* imgROI)
55 {
56  typename ROIConversionType1::Pointer conversion1 = ROIConversionType1::New();
57  conversion1->SetInputImage(img1);
58  conversion1->SetROIImage(imgROI);
59  conversion1->Update();
60 
61  if (m_CumROI1 != nullptr)
62  delete m_CumROI1;
63 
64  m_CumROI1 = new CumulantsForEdgeworth<ROIInputType1>(conversion1->GetOutput());
65 
66  if (!m_CumROI1->IsDataAvailable())
67  {
68  throw itk::ExceptionObject(__FILE__, __LINE__, "Cumulants estimated from ROI in image 1 are not usable", ITK_LOCATION);
69  }
70 
71  typename ROIConversionType2::Pointer conversion2 = ROIConversionType2::New();
72  conversion2->SetInputImage(img2);
73  conversion2->SetROIImage(imgROI);
74  conversion2->Update();
75 
76  if (m_CumROI2 != nullptr)
77  delete m_CumROI2;
78 
79  m_CumROI2 = new CumulantsForEdgeworth<ROIInputType2>(conversion2->GetOutput());
80 
81  if (!m_CumROI2->IsDataAvailable())
82  {
83  throw itk::ExceptionObject(__FILE__, __LINE__, "Cumulants estimated from ROI in image 2 are not usable", ITK_LOCATION);
84  }
85 }
86 
87 template <class TInput1, class TInput2, class TInputROIImage, class TOutput>
89 {
91 
92  if (!cum1.IsDataAvailable())
93  {
94  return static_cast<TOutput>(0.);
95  }
96 
98 
99  if (!cum2.IsDataAvailable())
100  {
101  return static_cast<TOutput>(0.);
102  }
103 
104  return static_cast<TOutput>(m_CumROI1->Divergence(cum1) + m_CumROI2->Divergence(cum2));
105 }
106 
107 } // end of namespace Functor
108 
116 template <class TInputImage1, class TInputImage2, class TInputROIImage, class TOutputImage>
118  const TInputROIImage* trainingImage)
119 {
120  this->itk::ProcessObject::SetNthInput(2, const_cast<TInputROIImage*>(trainingImage));
121 }
122 
123 template <class TInputImage1, class TInputImage2, class TInputROIImage, class TOutputImage>
125 {
126  typename TInputImage1::ConstPointer inputPtr1 = dynamic_cast<const TInputImage1*>(this->GetInput(0));
127  typename TInputImage2::ConstPointer inputPtr2 = dynamic_cast<const TInputImage2*>(this->GetInput(1));
128  typename TInputROIImage::ConstPointer trainingImage = static_cast<const TInputROIImage*>(this->itk::ProcessObject::GetInput(2));
129 
130  this->GetFunctor().Evaluate(inputPtr1, inputPtr2, trainingImage);
131 }
132 
133 } // end of namespace otb
134 
135 #endif
otbKullbackLeiblerSupervizedDistanceImageFilter.h
otb::KullbackLeiblerSupervizedDistanceImageFilter::BeforeThreadedGenerateData
void BeforeThreadedGenerateData(void) override
Definition: otbKullbackLeiblerSupervizedDistanceImageFilter.hxx:124
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::Functor::KullbackLeiblerSupervizedDistance::operator()
TOutput operator()(const TInput1 &it1, const TInput2 &it2)
Definition: otbKullbackLeiblerSupervizedDistanceImageFilter.hxx:88
otb::CumulantsForEdgeworth< ROIInputType1 >
otb::Functor::KullbackLeiblerSupervizedDistance::KullbackLeiblerSupervizedDistance
KullbackLeiblerSupervizedDistance()
Definition: otbKullbackLeiblerSupervizedDistanceImageFilter.hxx:35
otb::CumulantsForEdgeworth::IsDataAvailable
bool IsDataAvailable() const
Definition: otbKullbackLeiblerDistanceImageFilter.h:67
otb::KullbackLeiblerSupervizedDistanceImageFilter::SetTrainingArea
void SetTrainingArea(const TInputROIImage *trainingImage)
Definition: otbKullbackLeiblerSupervizedDistanceImageFilter.hxx:117
otb::Functor::KullbackLeiblerSupervizedDistance::Evaluate
void Evaluate(const typename TInput1::ImageType *img1, const typename TInput2::ImageType *img2, const TInputROIImage *imgROI)
Definition: otbKullbackLeiblerSupervizedDistanceImageFilter.hxx:52
otb::ROIdataConversion::Pointer
itk::SmartPointer< Self > Pointer
Definition: otbROIdataConversion.h:46
otb::Functor::KullbackLeiblerSupervizedDistance::~KullbackLeiblerSupervizedDistance
virtual ~KullbackLeiblerSupervizedDistance()
Definition: otbKullbackLeiblerSupervizedDistanceImageFilter.hxx:42