18 #ifndef __otbBinaryFunctorNeighborhoodJoinHistogramImageFilter_txx
19 #define __otbBinaryFunctorNeighborhoodJoinHistogramImageFilter_txx
33 template <
class TInputImage1,
class TInputImage2,
34 class TOutputImage,
class TFunction>
38 this->SetNumberOfRequiredInputs(2);
40 m_HistogramSize.Fill(256);
41 m_UsePaddingValue =
false;
42 m_UpperBoundIncreaseFactor = 0.001;
48 template <
class TInputImage1,
class TInputImage2,
49 class TOutputImage,
class TFunction>
55 this->SetNthInput(0, const_cast<TInputImage1 *>(image1));
61 template <
class TInputImage1,
class TInputImage2,
62 class TOutputImage,
class TFunction>
68 this->SetNthInput(1, const_cast<TInputImage2 *>(image2));
71 template <
class TInputImage1,
class TInputImage2,
72 class TOutputImage,
class TFunction>
77 if (this->GetNumberOfInputs() < 1)
84 template <
class TInputImage1,
class TInputImage2,
85 class TOutputImage,
class TFunction>
90 if (this->GetNumberOfInputs() < 2)
97 template <
class TInputImage1,
class TInputImage2,
98 class TOutputImage,
class TFunction>
104 Superclass::GenerateInputRequestedRegion();
108 const_cast<TInputImage1 *
>(this->GetInput1());
110 const_cast<TInputImage2 *
>(this->GetInput2());
113 if (!inputPtr1 || !inputPtr2 || !outputPtr)
119 typename TInputImage1::RegionType inputRequestedRegion1, inputRequestedRegion2;
120 inputRequestedRegion1 = inputPtr1->GetRequestedRegion();
123 inputRequestedRegion1.PadByRadius(m_Radius);
124 inputRequestedRegion2 = inputRequestedRegion1;
127 if (inputRequestedRegion1.Crop(inputPtr1->GetLargestPossibleRegion()))
129 inputPtr1->SetRequestedRegion(inputRequestedRegion1);
137 inputPtr1->SetRequestedRegion(inputRequestedRegion1);
141 std::ostringstream msg;
142 msg << this->GetNameOfClass()
143 <<
"::GenerateInputRequestedRegion()";
145 e.
SetDescription(
"Requested region is (at least partially) outside the largest possible region of image 1.");
149 if (inputRequestedRegion2.Crop(inputPtr2->GetLargestPossibleRegion()))
151 inputPtr2->SetRequestedRegion(inputRequestedRegion2);
159 inputPtr2->SetRequestedRegion(inputRequestedRegion2);
163 std::ostringstream msg;
164 msg << this->GetNameOfClass()
165 <<
"::GenerateInputRequestedRegion()";
167 e.
SetDescription(
"Requested region is (at least partially) outside the largest possible region of image 1.");
177 template <
class TInputImage1,
class TInputImage2,
178 class TOutputImage,
class TFunction>
180 ::HistogramType::Pointer
186 =
dynamic_cast<const TInputImage1*
>(ProcessObjectType::GetInput(0));
190 pInput1Image->GetBufferedRegion());
192 minInput1 = fiIt.Value();
193 maxInput1 = fiIt.Value();
195 while (!fiIt.IsAtEnd())
199 if (value < minInput1)
203 else if (value > maxInput1)
213 =
dynamic_cast<const TInputImage2*
>(ProcessObjectType::GetInput(1));
216 pInput2Image->GetBufferedRegion());
218 minInput2 = miIt.Value();
219 maxInput2 = miIt.Value();
221 while (!miIt.IsAtEnd())
225 if (value < minInput2)
229 else if (value > maxInput2)
237 m_LowerBound[0] = minInput1;
238 m_LowerBound[1] = minInput2;
240 maxInput1 + (maxInput1 - minInput1) * m_UpperBoundIncreaseFactor;
242 maxInput2 + (maxInput2 - minInput2) * m_UpperBoundIncreaseFactor;
247 typename Input1ImageType::RegionType input1Region;
248 typename Input1ImageType::RegionType input2Region;
250 input1Region = pInput1Image->GetRequestedRegion();
251 Input1IteratorType ti1(pInput1Image, input1Region);
253 input2Region = pInput2Image->GetRequestedRegion();
254 Input2IteratorType ti2(pInput2Image, input2Region);
258 histogram->Initialize(m_HistogramSize, m_LowerBound, m_UpperBound);
262 while (!ti1.IsAtEnd() && !ti2.IsAtEnd())
266 sample[0] = ti1.Get();
267 sample[1] = ti2.Get();
268 if (sample[0] != itk::NumericTraits<Input1ImagePixelType>::Zero &&
269 sample[1] != itk::NumericTraits<Input2ImagePixelType>::Zero) histogram->IncreaseFrequency(sample, 1);
282 template <
class TInputImage1,
class TInputImage2,
class TOutputImage,
class TFunction>
302 =
dynamic_cast<const TInputImage1*
>(ProcessObjectType::GetInput(0));
304 =
dynamic_cast<const TInputImage2*
>(ProcessObjectType::GetInput(1));
320 faceList1 = bC1(inputPtr1, outputRegionForThread, r1);
324 faceList2 = bC2(inputPtr2, outputRegionForThread, r2);
334 for (fit1 = faceList1.begin(), fit2 = faceList2.begin();
335 fit1 != faceList1.end() && fit2 != faceList2.end();
351 outputIt.
Set(m_Functor(neighInputIt1, neighInputIt2, histogram));
356 progress.CompletedPixel();