22 #ifndef otbSimpleRcsPanSharpeningFusionImageFilter_hxx
23 #define otbSimpleRcsPanSharpeningFusionImageFilter_hxx
30 template <
class TPanImageType,
class TXsImageType,
class TOutputImageType,
class TInternalPrecision>
34 this->SetNumberOfRequiredInputs(2);
35 this->m_UseNoData =
false;
38 m_ConvolutionFilter = ConvolutionFilterType::New();
39 m_ConvolutionFilter->NormalizeFilterOn();
43 m_Filter.SetSize((2 * m_Radius[0] + 1) * (2 * m_Radius[1] + 1));
47 template <
class TPanImageType,
class TXsImageType,
class TOutputImageType,
class TInternalPrecision>
53 this->itk::ProcessObject::SetNthInput(1,
const_cast<TPanImageType*
>(image));
57 template <
class TPanImageType,
class TXsImageType,
class TOutputImageType,
class TInternalPrecision>
60 if (this->GetNumberOfInputs() < 2)
65 return static_cast<const TPanImageType*
>(this->itk::ProcessObject::GetInput(1));
68 template <
class TPanImageType,
class TXsImageType,
class TOutputImageType,
class TInternalPrecision>
74 this->itk::ProcessObject::SetNthInput(0,
const_cast<TXsImageType*
>(image));
78 template <
class TPanImageType,
class TXsImageType,
class TOutputImageType,
class TInternalPrecision>
81 if (this->GetNumberOfInputs() < 1)
86 return static_cast<const TXsImageType*
>(this->itk::ProcessObject::GetInput(0));
89 template <
class TPanImageType,
class TXsImageType,
class TOutputImageType,
class TInternalPrecision>
93 typename TPanImageType::SizeType sizePan;
94 typename TXsImageType::SizeType sizeXs;
95 sizePan = this->GetPanInput()->GetLargestPossibleRegion().GetSize();
96 sizeXs = this->GetXsInput()->GetLargestPossibleRegion().GetSize();
97 if ((sizePan[0] != sizeXs[0]) || (sizePan[1] != sizeXs[1]))
99 itkExceptionMacro(<<
"SimpleRcsPanSharpeningFusionImageFilter: Wrong Pan/Xs size");
103 m_ProgressAccumulator = itk::ProgressAccumulator::New();
104 m_ProgressAccumulator->SetMiniPipelineFilter(
this);
105 m_ProgressAccumulator->RegisterInternalFilter(m_ConvolutionFilter, 0.9);
107 m_ConvolutionFilter->SetInput(this->GetPanInput());
108 m_ConvolutionFilter->SetRadius(this->m_Radius);
109 m_ConvolutionFilter->SetFilter(this->m_Filter);
111 typedef typename TPanImageType::InternalPixelType PanPixelType;
112 typedef typename TXsImageType::InternalPixelType XsPixelType;
115 std::vector<bool> tmpNoDataValuePanAvailable;
116 std::vector<double> tmpNoDataValuePan;
117 bool noDataValuePanAvailable =
false;
118 PanPixelType noDataValuePan = 0;
120 bool retPan =
ReadNoDataFlags(this->GetPanInput()->GetImageMetadata(), tmpNoDataValuePanAvailable, tmpNoDataValuePan);
122 if (retPan && tmpNoDataValuePanAvailable.size() > 0 && tmpNoDataValuePan.size() > 0)
124 noDataValuePanAvailable = tmpNoDataValuePanAvailable[0] && retPan;
125 noDataValuePan =
static_cast<PanPixelType
>(tmpNoDataValuePan[0]);
129 std::vector<bool> noDataValuesXsAvailable;
130 std::vector<double> tmpNoDataValuesXs;
131 std::vector<XsPixelType> noDataValuesXs;
133 bool retXs =
ReadNoDataFlags(this->GetXsInput()->GetImageMetadata(), noDataValuesXsAvailable, tmpNoDataValuesXs);
138 m_UseNoData = noDataValuePanAvailable;
139 for (
unsigned int i = 0; i < tmpNoDataValuesXs.size() && i < noDataValuesXsAvailable.size(); ++i)
141 noDataValuesXs.push_back(
static_cast<XsPixelType
>(tmpNoDataValuesXs[i]));
142 m_UseNoData |= (noDataValuesXsAvailable[i] = (noDataValuesXsAvailable[i] && retXs));
149 m_NoDataFusionFilter = NoDataFusionFilterType::New();
150 m_ProgressAccumulator->RegisterInternalFilter(m_NoDataFusionFilter, 0.1);
152 m_NoDataFusionFilter->SetInput2(m_ConvolutionFilter->GetOutput());
153 m_NoDataFusionFilter->GetModifiableFunctor().SetNoDataValuesXsAvailable(noDataValuesXsAvailable);
154 m_NoDataFusionFilter->GetModifiableFunctor().SetNoDataValuePanAvailable(noDataValuePanAvailable);
155 m_NoDataFusionFilter->GetModifiableFunctor().SetNoDataValuePan(noDataValuePan);
156 m_NoDataFusionFilter->GetModifiableFunctor().SetNoDataValuesXs(noDataValuesXs);
158 m_NoDataFusionFilter->SetInput1(this->GetXsInput());
159 m_NoDataFusionFilter->SetInput2(m_ConvolutionFilter->GetOutput());
160 m_NoDataFusionFilter->SetInput3(this->GetPanInput());
163 m_NoDataFusionFilter->GraftOutput(this->GetOutput());
164 m_NoDataFusionFilter->Update();
165 this->GraftOutput(m_NoDataFusionFilter->GetOutput());
169 m_FusionFilter = FusionFilterType::New();
170 m_ProgressAccumulator->RegisterInternalFilter(m_FusionFilter, 0.1);
172 m_FusionFilter->SetInput1(this->GetXsInput());
173 m_FusionFilter->SetInput2(m_ConvolutionFilter->GetOutput());
174 m_FusionFilter->SetInput3(this->GetPanInput());
177 m_FusionFilter->GraftOutput(this->GetOutput());
178 m_FusionFilter->Update();
179 this->GraftOutput(m_FusionFilter->GetOutput());
183 template <
class TPanImageType,
class TXsImageType,
class TOutputImageType,
class TInternalPrecision>
185 itk::Indent indent)
const
187 Superclass::PrintSelf(os, indent);
188 os << indent <<
"Radius:" << this->m_Radius << std::endl;