OTB  9.0.0
Orfeo Toolbox
otbLmvmPanSharpeningFusionImageFilter.hxx
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1999-2011 Insight Software Consortium
3  * Copyright (C) 2005-2022 Centre National d'Etudes Spatiales (CNES)
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 #ifndef otbLmvmPanSharpeningFusionImageFilter_hxx
23 #define otbLmvmPanSharpeningFusionImageFilter_hxx
24 
26 
27 namespace otb
28 {
29 template <class TPanImageType, class TXsImageType, class TOutputImageType, class TInternalPrecision>
31 {
32  // Fix number of required inputs
33  this->SetNumberOfRequiredInputs(2);
34 
35  // Instantiate convolution filters
36  m_PanConvolutionFilter = PanConvolutionFilterType::New();
37  m_PanConvolutionFilter->NormalizeFilterOn();
38  m_XsConvolutionFilter = XsConvolutionFilterType::New();
39  m_XsConvolutionFilter->NormalizeFilterOn();
40  m_PanNoiseFilter = PanNoiseFilterType::New();
41  m_XsNoiseFilter = XsNoiseFilterType::New();
42  m_XsVectorConvolutionFilter = XsVectorConvolutionFilterType::New();
43  m_XsVectorNoiseFilter = XsVectorNoiseFilterType::New();
44 
45 
46  // Set-up default parameters
47  m_Radius.Fill(3);
48  m_Filter.SetSize(7 * 7);
49  m_Filter.Fill(1);
50 
51  // Instantiate fusion filter
52  m_FusionStep1Filter = FusionStep1FilterType::New();
53  m_FusionStep2Filter = FusionStep2FilterType::New();
54 
55  // Set-up progress reporting
56  m_ProgressAccumulator = itk::ProgressAccumulator::New();
57  m_ProgressAccumulator->SetMiniPipelineFilter(this);
58  m_ProgressAccumulator->RegisterInternalFilter(m_PanConvolutionFilter, 0.2);
59  m_ProgressAccumulator->RegisterInternalFilter(m_PanNoiseFilter, 0.2);
60  m_ProgressAccumulator->RegisterInternalFilter(m_XsVectorConvolutionFilter, 0.2);
61  m_ProgressAccumulator->RegisterInternalFilter(m_XsVectorNoiseFilter, 0.2);
62  m_ProgressAccumulator->RegisterInternalFilter(m_FusionStep1Filter, 0.1);
63  m_ProgressAccumulator->RegisterInternalFilter(m_FusionStep2Filter, 0.1);
64 }
65 
66 template <class TPanImageType, class TXsImageType, class TOutputImageType, class TInternalPrecision>
68 {
69  // We have 2 inputs: an image and a vector image
70 
71  // Process object is not const-correct so the const_cast is required here
72  this->itk::ProcessObject::SetNthInput(1, const_cast<TPanImageType*>(image));
73  this->Modified();
74 }
75 
76 template <class TPanImageType, class TXsImageType, class TOutputImageType, class TInternalPrecision>
78 {
79  if (this->GetNumberOfInputs() < 2)
80  {
81  return nullptr;
82  }
83 
84  return static_cast<const TPanImageType*>(this->itk::ProcessObject::GetInput(1));
85 }
86 
87 template <class TPanImageType, class TXsImageType, class TOutputImageType, class TInternalPrecision>
89 {
90  // We have 2 inputs: an image and a vector image
91 
92  // Process object is not const-correct so the const_cast is required here
93  this->itk::ProcessObject::SetNthInput(0, const_cast<TXsImageType*>(image));
94  this->Modified();
95 }
96 
97 template <class TPanImageType, class TXsImageType, class TOutputImageType, class TInternalPrecision>
99 {
100  if (this->GetNumberOfInputs() < 1)
101  {
102  return nullptr;
103  }
104 
105  return static_cast<const TXsImageType*>(this->itk::ProcessObject::GetInput(0));
106 }
107 
108 template <class TPanImageType, class TXsImageType, class TOutputImageType, class TInternalPrecision>
110 {
111  // Check if size is correct
112  typename TPanImageType::SizeType sizePan;
113  typename TXsImageType::SizeType sizeXs;
114  sizePan = this->GetPanInput()->GetLargestPossibleRegion().GetSize();
115  sizeXs = this->GetXsInput()->GetLargestPossibleRegion().GetSize();
116  if ((sizePan[0] != sizeXs[0]) || (sizePan[1] != sizeXs[1]))
117  {
118  itkExceptionMacro(<< "LmvmPanSharpeningFusionImageFilter: Wrong Pan/Xs size");
119  }
120 
121  // Process the fusion
122  m_PanConvolutionFilter->SetInput(this->GetPanInput());
123  m_PanConvolutionFilter->SetRadius(this->m_Radius);
124  m_PanConvolutionFilter->SetFilter(this->m_Filter);
125  m_PanNoiseFilter->SetRadius(this->m_Radius);
126  m_PanNoiseFilter->SetInput(this->GetPanInput());
127  m_XsConvolutionFilter->SetRadius(this->m_Radius);
128  m_XsConvolutionFilter->SetFilter(this->m_Filter);
129  m_XsVectorConvolutionFilter->SetInput(this->GetXsInput());
130  m_XsVectorConvolutionFilter->SetFilter(m_XsConvolutionFilter);
131  m_XsNoiseFilter->SetRadius(this->m_Radius);
132  m_XsVectorNoiseFilter->SetInput(this->GetXsInput());
133  m_XsVectorNoiseFilter->SetFilter(m_XsNoiseFilter);
134 
135 
136  m_FusionStep1Filter->SetInput1(m_XsVectorNoiseFilter->GetOutput());
137  m_FusionStep1Filter->SetInput2(m_PanConvolutionFilter->GetOutput());
138  m_FusionStep1Filter->SetInput3(this->GetPanInput());
139 
140  m_FusionStep2Filter->SetInput1(m_FusionStep1Filter->GetOutput());
141  m_FusionStep2Filter->SetInput3(m_PanNoiseFilter->GetOutput());
142  m_FusionStep2Filter->SetInput2(m_XsVectorConvolutionFilter->GetOutput());
143 
144  m_FusionStep2Filter->UpdateOutputInformation();
145 
146  // Wire composite filter
147  m_FusionStep2Filter->GraftOutput(this->GetOutput());
148  m_FusionStep2Filter->Update();
149  this->GraftOutput(m_FusionStep2Filter->GetOutput());
150 }
151 
152 template <class TPanImageType, class TXsImageType, class TOutputImageType, class TInternalPrecision>
154  itk::Indent indent) const
155 {
156  Superclass::PrintSelf(os, indent);
157  os << indent << "Radius:" << this->m_Radius << std::endl;
158 }
159 
160 } // end namespace otb
161 
162 #endif
otb::LmvmPanSharpeningFusionImageFilter::SetXsInput
virtual void SetXsInput(const TXsImageType *path)
Definition: otbLmvmPanSharpeningFusionImageFilter.hxx:88
otb::LmvmPanSharpeningFusionImageFilter::SetPanInput
virtual void SetPanInput(const TPanImageType *image)
Definition: otbLmvmPanSharpeningFusionImageFilter.hxx:67
otbLmvmPanSharpeningFusionImageFilter.h
otb::LmvmPanSharpeningFusionImageFilter::GenerateData
void GenerateData() override
Definition: otbLmvmPanSharpeningFusionImageFilter.hxx:109
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::LmvmPanSharpeningFusionImageFilter::LmvmPanSharpeningFusionImageFilter
LmvmPanSharpeningFusionImageFilter()
Definition: otbLmvmPanSharpeningFusionImageFilter.hxx:30
otb::LmvmPanSharpeningFusionImageFilter::GetXsInput
const TXsImageType * GetXsInput(void) const
Definition: otbLmvmPanSharpeningFusionImageFilter.hxx:98
otb::LmvmPanSharpeningFusionImageFilter::GetPanInput
const TPanImageType * GetPanInput(void) const
Definition: otbLmvmPanSharpeningFusionImageFilter.hxx:77
otb::LmvmPanSharpeningFusionImageFilter::PrintSelf
void PrintSelf(std::ostream &os, itk::Indent indent) const override
Definition: otbLmvmPanSharpeningFusionImageFilter.hxx:153