20 #ifndef otbImageDimensionalityReductionFilter_hxx
21 #define otbImageDimensionalityReductionFilter_hxx
24 #include "itkImageRegionIterator.h"
25 #include "itkProgressReporter.h"
32 template <
class TInputImage,
class TOutputImage,
class TMaskImage>
35 this->DynamicMultiThreadingOff();
36 this->SetNumberOfIndexedInputs(2);
37 this->SetNumberOfRequiredInputs(1);
40 this->SetNumberOfRequiredOutputs(2);
41 this->SetNthOutput(0, TOutputImage::New());
42 this->SetNthOutput(1, ConfidenceImageType::New());
43 m_UseConfidenceMap =
false;
47 template <
class TInputImage,
class TOutputImage,
class TMaskImage>
50 this->itk::ProcessObject::SetNthInput(1,
const_cast<MaskImageType*
>(mask));
53 template <
class TInputImage,
class TOutputImage,
class TMaskImage>
57 if (this->GetNumberOfInputs() < 2)
61 return static_cast<const MaskImageType*
>(this->itk::ProcessObject::GetInput(1));
64 template <
class TInputImage,
class TOutputImage,
class TMaskImage>
68 if (this->GetNumberOfOutputs() < 2)
75 template <
class TInputImage,
class TOutputImage,
class TMaskImage>
82 this->SetNumberOfWorkUnits(1);
87 template <
class TInputImage,
class TOutputImage,
class TMaskImage>
89 itk::ThreadIdType threadId)
98 itk::ProgressReporter progress(
this, threadId, outputRegionForThread.GetNumberOfPixels());
101 typedef itk::ImageRegionConstIterator<InputImageType> InputIteratorType;
102 typedef itk::ImageRegionIterator<OutputImageType> OutputIteratorType;
104 InputIteratorType inIt(inputPtr, outputRegionForThread);
105 OutputIteratorType outIt(outputPtr, outputRegionForThread);
108 for (inIt.GoToBegin(), outIt.GoToBegin(); !inIt.IsAtEnd() && !outIt.IsAtEnd(); ++inIt, ++outIt)
111 outIt.Set(m_Model->Predict(inIt.Get()));
112 progress.CompletedPixel();
116 template <
class TInputImage,
class TOutputImage,
class TMaskImage>
119 Superclass::GenerateOutputInformation();
122 itkGenericExceptionMacro(<<
"No model for dimensionality reduction");
124 this->GetOutput()->SetNumberOfComponentsPerPixel(m_Model->GetDimension());
127 template <
class TInputImage,
class TOutputImage,
class TMaskImage>
129 itk::ThreadIdType threadId)
138 itk::ProgressReporter progress(
this, threadId, outputRegionForThread.GetNumberOfPixels());
141 typedef itk::ImageRegionConstIterator<InputImageType> InputIteratorType;
142 typedef itk::ImageRegionIterator<OutputImageType> OutputIteratorType;
144 InputIteratorType inIt(inputPtr, outputRegionForThread);
145 OutputIteratorType outIt(outputPtr, outputRegionForThread);
152 typename InputListSampleType::Pointer samples = InputListSampleType::New();
153 unsigned int num_features = inputPtr->GetNumberOfComponentsPerPixel();
154 samples->SetMeasurementVectorSize(num_features);
155 InputSampleType sample(num_features);
158 for (inIt.GoToBegin(); !inIt.IsAtEnd(); ++inIt)
160 typename InputImageType::PixelType pix = inIt.Get();
161 for (
size_t feat = 0; feat < num_features; ++feat)
163 sample[feat] = pix[feat];
165 samples->PushBack(sample);
168 typename TargetListSampleType::Pointer labels;
171 labels = m_Model->PredictBatch(samples);
174 typename TargetListSampleType::ConstIterator labIt = labels->Begin();
175 for (outIt.GoToBegin(); !outIt.IsAtEnd(); ++outIt)
177 itk::VariableLengthVector<TargetValueType> labelValue;
178 labelValue = labIt.GetMeasurementVector();
180 outIt.Set(labelValue);
181 progress.CompletedPixel();
185 template <
class TInputImage,
class TOutputImage,
class TMaskImage>
187 itk::ThreadIdType threadId)
191 this->BatchThreadedGenerateData(outputRegionForThread, threadId);
195 this->ClassicThreadedGenerateData(outputRegionForThread, threadId);
202 template <
class TInputImage,
class TOutputImage,
class TMaskImage>
205 Superclass::PrintSelf(os, indent);
void PrintSelf(std::ostream &os, itk::Indent indent) const override
void BatchThreadedGenerateData(const OutputImageRegionType &outputRegionForThread, itk::ThreadIdType threadId)
ConfidenceImageType::Pointer ConfidenceImagePointerType
const MaskImageType * GetInputMask(void)
ImageDimensionalityReductionFilter()
void ClassicThreadedGenerateData(const OutputImageRegionType &outputRegionForThread, itk::ThreadIdType threadId)
ConfidenceImageType * GetOutputConfidence(void)
void BeforeThreadedGenerateData() override
InputImageType::ConstPointer InputImageConstPointerType
OutputImageType::Pointer OutputImagePointerType
void SetInputMask(const MaskImageType *mask)
MaskImageType::ConstPointer MaskImageConstPointerType
void ThreadedGenerateData(const OutputImageRegionType &outputRegionForThread, itk::ThreadIdType threadId) override
virtual void GenerateOutputInformation() override
OutputImageType::RegionType OutputImageRegionType
Creation of an "otb" image which contains metadata.
itk::Statistics::ListSample< TargetSampleType > TargetListSampleType
MLMTargetTraits< TTargetValue >::ValueType TargetValueType
itk::Statistics::ListSample< InputSampleType > InputListSampleType
MLMSampleTraits< TInputValue >::SampleType InputSampleType
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.