21 #ifndef otbProfileDerivativeToMultiScaleCharacteristicsFilter_hxx
22 #define otbProfileDerivativeToMultiScaleCharacteristicsFilter_hxx
25 #include "itkImageRegionIterator.h"
31 template <
class TInputImage,
class TOutputImage,
class TLabeledImage>
34 this->SetNumberOfRequiredOutputs(2);
35 this->SetNthOutput(0, OutputImageType::New());
36 this->SetNthOutput(1, LabeledImageType::New());
41 template <
class TInputImage,
class TOutputImage,
class TLabeledImage>
44 if (this->GetNumberOfOutputs() < 2)
48 return static_cast<LabeledImageType*
>(this->itk::ProcessObject::GetOutput(1));
53 template <
class TInputImage,
class TOutputImage,
class TLabeledImage>
56 InputImageListPointerType inputPtr = this->GetInput();
57 OutputImagePointerType outputPtr = this->GetOutput();
58 LabeledImagePointerType outputLabeledPtr = this->GetOutputCharacteristics();
59 if (inputPtr->Size() > 0)
61 typename InputImageListType::ConstIterator inputListIt = inputPtr->Begin();
62 outputPtr->CopyInformation(inputListIt.Get());
63 outputLabeledPtr->CopyInformation(inputListIt.Get());
70 template <
class TInputImage,
class TOutputImage,
class TLabeledImage>
73 InputImageListPointerType inputPtr = this->GetInput();
74 typename InputImageListType::ConstIterator inputListIt = inputPtr->Begin();
77 RegionType region1 = this->GetOutput()->GetRequestedRegion();
78 RegionType region2 = this->GetOutputCharacteristics()->GetRequestedRegion();
84 if (region1 == this->GetOutput()->GetLargestPossibleRegion() && region2 != this->GetOutputCharacteristics()->GetLargestPossibleRegion())
88 else if (region1 != this->GetOutput()->GetLargestPossibleRegion() && region2 == this->GetOutputCharacteristics()->GetLargestPossibleRegion())
94 int xul1 = region1.GetIndex()[0];
95 int xul2 = region2.GetIndex()[0];
96 int yul1 = region1.GetIndex()[1];
97 int yul2 = region2.GetIndex()[1];
98 int xlr1 = region1.GetIndex()[0] + region1.GetSize()[0];
99 int xlr2 = region2.GetIndex()[0] + region2.GetSize()[0];
100 int ylr1 = region1.GetIndex()[1] + region1.GetSize()[1];
101 int ylr2 = region2.GetIndex()[1] + region2.GetSize()[1];
104 int xul = std::min(xul1, xul2);
105 int yul = std::min(yul1, yul2);
106 int xlr = std::max(xlr1, xlr2);
107 int ylr = std::max(ylr1, ylr2);
109 typename RegionType::IndexType index;
113 typename RegionType::SizeType size;
114 size[0] =
static_cast<unsigned int>(xlr - xul);
115 size[1] =
static_cast<unsigned int>(ylr - yul);
117 region.SetIndex(index);
118 region.SetSize(size);
121 while (inputListIt != inputPtr->End())
123 inputListIt.Get()->SetRequestedRegion(region);
130 template <
class TInputImage,
class TOutputImage,
class TLabeledImage>
133 OutputImagePointerType outputPtr = this->GetOutput();
134 LabeledImagePointerType outputLabeledPtr = this->GetOutputCharacteristics();
135 InputImageListPointerType inputPtr = this->GetInput();
139 outputPtr->SetBufferedRegion(outputPtr->GetRequestedRegion());
140 outputPtr->Allocate();
141 outputPtr->FillBuffer(0);
143 outputLabeledPtr->SetBufferedRegion(outputLabeledPtr->GetRequestedRegion());
144 outputLabeledPtr->Allocate();
145 outputLabeledPtr->FillBuffer(0);
148 typedef itk::ImageRegionConstIterator<InputImageType> InputIteratorType;
149 typedef itk::ImageRegionIterator<OutputImageType> OutputIteratorType;
150 typedef itk::ImageRegionIterator<LabeledImageType> LabeledIteratorType;
152 typename InputImageListType::ConstIterator inputListIt = inputPtr->Begin();
155 typedef std::vector<InputIteratorType> InputIteratorListType;
156 InputIteratorListType inputIteratorList;
159 for (; inputListIt != inputPtr->End(); ++inputListIt)
161 inputIteratorList.push_back(InputIteratorType(inputListIt.Get(), inputListIt.Get()->GetRequestedRegion()));
162 inputIteratorList.back().GoToBegin();
166 OutputIteratorType outputIt(outputPtr, outputPtr->GetRequestedRegion());
167 outputIt.GoToBegin();
168 LabeledIteratorType labeledIt(outputLabeledPtr, outputLabeledPtr->GetRequestedRegion());
169 labeledIt.GoToBegin();
171 bool inputIteratorsAtEnd =
false;
172 for (
typename InputIteratorListType::iterator it = inputIteratorList.begin(); it != inputIteratorList.end(); ++it)
174 inputIteratorsAtEnd = inputIteratorsAtEnd || it->IsAtEnd();
177 while (!outputIt.IsAtEnd() && !labeledIt.IsAtEnd() && !inputIteratorsAtEnd)
179 unsigned int index = 0;
180 OutputPixelType outputPixel = 0;
181 LabeledPixelType outputChar = 0;
184 for (
typename InputIteratorListType::iterator it = inputIteratorList.begin(); it != inputIteratorList.end(); ++it)
186 if (it->Get() > outputPixel)
188 outputPixel = it->Get();
189 outputChar = m_InitialValue + m_Step * (
static_cast<LabeledPixelType
>(index));
193 outputIt.Set(outputPixel);
194 labeledIt.Set(outputChar);
197 for (
typename InputIteratorListType::iterator it = inputIteratorList.begin(); it != inputIteratorList.end(); ++it)
200 inputIteratorsAtEnd = inputIteratorsAtEnd || it->IsAtEnd();