21 #ifndef otbAdhesionCorrectionFilter_hxx
22 #define otbAdhesionCorrectionFilter_hxx
26 #include "itkProgressReporter.h"
27 #include "itkLinearInterpolateImageFunction.h"
28 #include "itkImageRegionIteratorWithIndex.h"
29 #include "itkNormalizedCorrelationImageToImageMetric.h"
30 #include "itkExceptionObject.h"
37 template <
class TImage,
class TMask>
40 this->SetNumberOfRequiredInputs(5);
41 this->SetNumberOfRequiredOutputs(3);
44 this->SetNthOutput(1, TMask::New());
45 this->SetNthOutput(2, TImage::New());
54 m_DiscontinuityThreshold = 10.0;
55 m_DiscontinuityHighThreshold = 30.0;
57 m_EdgeThreshold = 100.0;
60 template <
class TImage,
class TMask>
64 this->SetNthInput(1,
const_cast<TImage*
>(medianmap));
67 template <
class TImage,
class TMask>
71 this->SetNthInput(2,
const_cast<TMask*
>(medianmask));
74 template <
class TImage,
class TMask>
78 this->SetNthInput(3,
const_cast<TImage*
>(cannymedianmap));
81 template <
class TImage,
class TMask>
85 this->SetNthInput(4,
const_cast<TMask*
>(subpixelmask));
88 template <
class TImage,
class TMask>
91 if (this->GetNumberOfInputs() < 2)
95 return static_cast<const TImage*
>(this->itk::ProcessObject::GetInput(1));
98 template <
class TImage,
class TMask>
101 if (this->GetNumberOfInputs() < 3)
105 return static_cast<const TMask*
>(this->itk::ProcessObject::GetInput(2));
108 template <
class TImage,
class TMask>
111 if (this->GetNumberOfInputs() < 4)
115 return static_cast<const TImage*
>(this->itk::ProcessObject::GetInput(3));
118 template <
class TImage,
class TMask>
121 if (this->GetNumberOfInputs() < 5)
125 return static_cast<const TMask*
>(this->itk::ProcessObject::GetInput(4));
128 template <
class TImage,
class TMask>
131 if (this->GetNumberOfOutputs() < 2)
135 return static_cast<TMask*
>(this->itk::ProcessObject::GetOutput(1));
138 template <
class TImage,
class TMask>
141 if (this->GetNumberOfOutputs() < 3)
145 return static_cast<TImage*
>(this->itk::ProcessObject::GetOutput(2));
148 template <
class TImage,
class TMask>
152 Superclass::GenerateOutputInformation();
155 TImage* outputPtr = this->GetOutput();
156 TMask* outputMaskPtr = this->GetOutputMask();
157 TImage* outputriskedgesPtr = this->GetOutputRiskEdges();
161 SizeType outputSize = largestRegion.GetSize();
162 m_ImageSize = outputSize;
163 SpacingType outputSpacing = outputPtr->GetSignedSpacing();
166 outputPtr->SetSignedSpacing(outputSpacing);
167 outputMaskPtr->SetSignedSpacing(outputSpacing);
168 outputriskedgesPtr->SetSignedSpacing(outputSpacing);
171 largestRegion.SetSize(outputSize);
172 outputPtr->SetLargestPossibleRegion(largestRegion);
173 outputMaskPtr->SetLargestPossibleRegion(largestRegion);
174 outputriskedgesPtr->SetLargestPossibleRegion(largestRegion);
177 template <
class TImage,
class TMask>
181 Superclass::GenerateInputRequestedRegion();
184 TImage* canny_edges =
const_cast<TImage*
>(this->GetInput());
185 TImage* old_disparityPtr =
const_cast<TImage*
>(this->GetMedianDisparityInput());
186 TMask* old_maskPtr =
const_cast<TMask*
>(this->GetMedianMaskInput());
187 TImage* canny_disparity =
const_cast<TImage*
>(this->GetEdgesDisparityInput());
188 TMask* subpixelmaskPtr =
const_cast<TMask*
>(this->GetSubPixelMaskInput());
189 TImage* outputPtr = this->GetOutput();
190 TMask* outputmaskPtr = this->GetOutputMask();
191 TImage* outputriskedgesPtr = this->GetOutputRiskEdges();
193 if (!canny_edges || !old_disparityPtr || !old_maskPtr || !canny_disparity || !subpixelmaskPtr || !outputPtr || !outputmaskPtr || !outputriskedgesPtr)
201 RequestedRegion = outputPtr->GetRequestedRegion();
204 Big_Radius[0] = m_Radius[0] + 2;
205 Big_Radius[1] = m_Radius[1] + 2;
206 RequestedRegion.PadByRadius(Big_Radius);
209 if (RequestedRegion.Crop(canny_edges->GetLargestPossibleRegion()))
211 canny_edges->SetRequestedRegion(RequestedRegion);
218 canny_edges->SetRequestedRegion(RequestedRegion);
221 itk::InvalidRequestedRegionError e(__FILE__, __LINE__);
222 std::ostringstream msg;
223 msg << this->GetNameOfClass() <<
"::GenerateInputRequestedRegion()";
224 e.SetLocation(msg.str());
225 e.SetDescription(
"Requested region is (at least partially) outside the largest possible region of image 1.");
226 e.SetDataObject(canny_edges);
231 if (RequestedRegion.Crop(old_disparityPtr->GetLargestPossibleRegion()))
233 old_disparityPtr->SetRequestedRegion(RequestedRegion);
240 old_disparityPtr->SetRequestedRegion(RequestedRegion);
243 itk::InvalidRequestedRegionError e(__FILE__, __LINE__);
244 std::ostringstream msg;
245 msg << this->GetNameOfClass() <<
"::GenerateInputRequestedRegion()";
246 e.SetLocation(msg.str());
247 e.SetDescription(
"Requested region is (at least partially) outside the largest possible region of image 1.");
248 e.SetDataObject(old_disparityPtr);
253 if (RequestedRegion.Crop(old_maskPtr->GetLargestPossibleRegion()))
255 old_maskPtr->SetRequestedRegion(RequestedRegion);
262 old_maskPtr->SetRequestedRegion(RequestedRegion);
265 itk::InvalidRequestedRegionError e(__FILE__, __LINE__);
266 std::ostringstream msg;
267 msg << this->GetNameOfClass() <<
"::GenerateInputRequestedRegion()";
268 e.SetLocation(msg.str());
269 e.SetDescription(
"Requested region is (at least partially) outside the largest possible region of image 1.");
270 e.SetDataObject(old_maskPtr);
275 if (RequestedRegion.Crop(canny_disparity->GetLargestPossibleRegion()))
277 canny_disparity->SetRequestedRegion(RequestedRegion);
284 canny_disparity->SetRequestedRegion(RequestedRegion);
287 itk::InvalidRequestedRegionError e(__FILE__, __LINE__);
288 std::ostringstream msg;
289 msg << this->GetNameOfClass() <<
"::GenerateInputRequestedRegion()";
290 e.SetLocation(msg.str());
291 e.SetDescription(
"Requested region is (at least partially) outside the largest possible region of image 1.");
292 e.SetDataObject(canny_disparity);
297 if (RequestedRegion.Crop(subpixelmaskPtr->GetLargestPossibleRegion()))
299 subpixelmaskPtr->SetRequestedRegion(RequestedRegion);
306 subpixelmaskPtr->SetRequestedRegion(RequestedRegion);
309 itk::InvalidRequestedRegionError e(__FILE__, __LINE__);
310 std::ostringstream msg;
311 msg << this->GetNameOfClass() <<
"::GenerateInputRequestedRegion()";
312 e.SetLocation(msg.str());
313 e.SetDescription(
"Requested region is (at least partially) outside the largest possible region of image 1.");
314 e.SetDataObject(subpixelmaskPtr);
321 template <
class TImage,
class TMask>
325 this->AllocateOutputs();
328 TImage* canny_edges =
const_cast<TImage*
>(this->GetInput());
329 TImage* old_disparityPtr =
const_cast<TImage*
>(this->GetMedianDisparityInput());
330 TMask* old_maskPtr =
const_cast<TMask*
>(this->GetMedianMaskInput());
331 TImage* canny_disparity =
const_cast<TImage*
>(this->GetEdgesDisparityInput());
332 TMask* subpixelmaskPtr =
const_cast<TMask*
>(this->GetSubPixelMaskInput());
333 TImage* outputPtr = this->GetOutput();
334 TMask* outputmaskPtr = this->GetOutputMask();
335 TImage* outputriskedgesPtr = this->GetOutputRiskEdges();
337 outputriskedgesPtr->FillBuffer(0.0);
339 int win = m_Radius[0] + 1;
340 int patch_side = 2 * win + 1;
341 int patch_side_small = 2 * (win - 1) + 1;
342 int big_dist = 3 * win;
347 ring.push_back(-1 - outputPtr->GetRequestedRegion().GetSize()[0] - outputPtr->GetRequestedRegion().GetIndex()[0]);
348 ring.push_back(0 - outputPtr->GetRequestedRegion().GetSize()[0] - outputPtr->GetRequestedRegion().GetIndex()[0]);
349 ring.push_back(1 - outputPtr->GetRequestedRegion().GetSize()[0] - outputPtr->GetRequestedRegion().GetIndex()[0]);
351 ring.push_back(1 + outputPtr->GetRequestedRegion().GetSize()[0] + outputPtr->GetRequestedRegion().GetIndex()[0]);
352 ring.push_back(outputPtr->GetRequestedRegion().GetSize()[0] + outputPtr->GetRequestedRegion().GetIndex()[0]);
353 ring.push_back(-1 + outputPtr->GetRequestedRegion().GetSize()[0] + outputPtr->GetRequestedRegion().GetIndex()[0]);
364 disparity_jump->SetRegions(old_disparityPtr->GetRequestedRegion());
365 disparity_jump->Allocate();
366 disparity_jump->FillBuffer(0);
369 disparity_jump2->SetRegions(old_disparityPtr->GetRequestedRegion());
370 disparity_jump2->Allocate();
371 disparity_jump2->FillBuffer(0);
374 aux->SetRegions(outputPtr->GetRequestedRegion());
379 itk::ImageRegionConstIterator<TImage> old_disparityIt(old_disparityPtr, old_disparityPtr->GetRequestedRegion());
380 itk::ImageRegionConstIterator<TMask> old_maskIt(old_maskPtr, old_maskPtr->GetRequestedRegion());
381 itk::ImageRegionConstIterator<TImage> canny_disparityIt(canny_disparity, canny_disparity->GetRequestedRegion());
382 itk::ImageRegionConstIterator<TImage> canny_edgesIt(canny_edges, canny_edges->GetRequestedRegion());
385 IndexType index, index2, index_pos, index_pos_actual, index_pos_old, index_pos_new, index_pos0;
388 itk::ImageRegionIterator<TImage> new_disparityIt(outputPtr, outputPtr->GetRequestedRegion());
389 itk::ImageRegionIterator<TMask> new_maskIt(outputmaskPtr, outputPtr->GetRequestedRegion());
390 itk::ImageRegionIterator<AuxImageType> disparity_jumpIt(disparity_jump, outputPtr->GetRequestedRegion());
391 itk::ImageRegionIterator<AuxImageType> disparity_jump2It(disparity_jump2, outputPtr->GetRequestedRegion());
392 itk::ImageRegionIterator<TImage> risk_edgesIt(outputriskedgesPtr, outputPtr->GetRequestedRegion());
393 itk::ImageRegionIterator<AuxImageType> auxIt(aux, outputPtr->GetRequestedRegion());
397 new_maskIt.GoToBegin();
398 new_disparityIt.GoToBegin();
401 while (!new_maskIt.IsAtEnd() && !new_disparityIt.IsAtEnd())
403 old_maskIt.SetIndex(new_maskIt.GetIndex());
404 old_disparityIt.SetIndex(new_disparityIt.GetIndex());
405 new_maskIt.Set(old_maskIt.Get());
406 new_disparityIt.Set(old_disparityIt.Get());
414 new_disparityIt.GoToBegin();
415 while (new_disparityIt.GetIndex()[1] <
static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[1]) + outputPtr->GetRequestedRegion().GetIndex()[1])
417 index_pos = new_disparityIt.GetIndex();
418 if (new_disparityIt.GetIndex()[1] >= outputPtr->GetRequestedRegion().GetIndex()[1] &&
419 new_disparityIt.GetIndex()[1] <
static_cast<int>(m_ImageSize[1]) - win)
421 old_maskIt.SetIndex(index_pos);
422 while (old_maskIt.Get() == 0 &&
423 new_disparityIt.GetIndex()[0] <
static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[0]) + outputPtr->GetRequestedRegion().GetIndex()[0])
426 old_maskIt.SetIndex(new_disparityIt.GetIndex());
428 index_pos = new_disparityIt.GetIndex();
429 disparity_jumpIt.SetIndex(index_pos);
430 disparity_jumpIt.Set(-1);
432 while (new_disparityIt.GetIndex()[0] <
433 static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[0]) + outputPtr->GetRequestedRegion().GetIndex()[0] - win)
435 index_pos = new_disparityIt.GetIndex();
436 if (old_maskPtr->GetPixel(index_pos) == 0)
442 index[0] = index_pos[0] + i;
443 index[1] = index_pos[1];
444 old_maskIt.SetIndex(index);
445 new_disparityIt.SetIndex(index);
446 while (new_disparityIt.GetIndex()[0] <
447 static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[0]) + outputPtr->GetRequestedRegion().GetIndex()[0] &&
448 old_maskIt.Get() == 0)
451 index[0] = index_pos[0] + i;
452 new_disparityIt.SetIndex(index);
453 old_maskIt.SetIndex(index);
455 if (new_disparityIt.GetIndex()[0] ==
456 static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[0]) + outputPtr->GetRequestedRegion().GetIndex()[0] - 1)
458 disparity_jumpIt.SetIndex(index_pos);
459 disparity_jumpIt.Set(4);
463 index[0] = index_pos[0] - 1;
464 index2[0] = index_pos[0] + i;
465 index2[1] = index_pos[1];
466 if (std::abs(old_disparityPtr->GetPixel(index) - old_disparityPtr->GetPixel(index2)) > m_Tolerance)
468 if (old_disparityPtr->GetPixel(index) < old_disparityPtr->GetPixel(index2))
470 index2[0] = index_pos[0] + i - 1;
471 disparity_jumpIt.SetIndex(index2);
472 disparity_jumpIt.Set(3);
475 disparity_jumpIt.SetIndex(index_pos);
476 disparity_jumpIt.Set(4);
481 disparity_jumpIt.SetIndex(index_pos);
482 disparity_jumpIt.Set(4);
485 index[0] = index_pos[0] + i - 1;
486 disparity_jumpIt.SetIndex(index);
487 disparity_jumpIt.Set(3);
496 if (canny_disparity->GetPixel(index_pos) > m_DiscontinuityThreshold)
500 for (k = 0; k < 8; k++)
502 index[0] = index_pos[0] + ring[k];
503 index[1] = index_pos[1];
504 if (old_maskPtr->GetPixel(index) == 0)
509 index[0] = index_pos[0] - 1;
510 index[1] = index_pos[1];
511 index2[0] = index_pos[0] + 1;
512 index2[1] = index_pos[1];
513 if (old_disparityPtr->GetPixel(index) < old_disparityPtr->GetPixel(index2))
515 disparity_jumpIt.SetIndex(index);
516 disparity_jumpIt.Set(1);
518 if (old_disparityPtr->GetPixel(index) > old_disparityPtr->GetPixel(index2))
520 disparity_jumpIt.SetIndex(index2);
521 disparity_jumpIt.Set(2);
527 new_disparityIt.SetIndex(index_pos);
531 index[0] = outputPtr->GetRequestedRegion().GetIndex()[0];
532 index[1] = index_pos[1] + 1;
533 new_disparityIt.SetIndex(index);
538 new_disparityIt.GoToBegin();
540 while (new_disparityIt.GetIndex()[1] <
static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[1]) + outputPtr->GetRequestedRegion().GetIndex()[1])
542 index_pos = new_disparityIt.GetIndex();
543 old_maskIt.SetIndex(index_pos);
544 while (old_maskIt.Get() == 0 &&
545 new_disparityIt.GetIndex()[0] <
static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[0]) + outputPtr->GetRequestedRegion().GetIndex()[0] - 1)
548 old_maskIt.SetIndex(new_disparityIt.GetIndex());
550 index_pos = new_disparityIt.GetIndex();
551 old_disparityIt.SetIndex(index_pos);
553 while (new_disparityIt.GetIndex()[0] <
static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[0]) + outputPtr->GetRequestedRegion().GetIndex()[0] - 1)
555 index_pos = new_disparityIt.GetIndex();
557 index[0] = index_pos[0] + 1;
558 old_maskIt.SetIndex(index_pos);
559 if (old_maskIt.Get() != 0 && old_maskPtr->GetPixel(index) != 0)
561 if (std::abs(old_disparityPtr->GetPixel(index_pos) - old_disparityPtr->GetPixel(index)) > m_Tolerance)
563 if (old_disparityPtr->GetPixel(index) > old_disparityPtr->GetPixel(index_pos) && disparity_jump->GetPixel(index_pos) == 0)
565 disparity_jumpIt.SetIndex(index_pos);
566 disparity_jumpIt.Set(1);
568 if (old_disparityPtr->GetPixel(index) < old_disparityPtr->GetPixel(index_pos) && disparity_jump->GetPixel(index) == 0)
570 disparity_jumpIt.SetIndex(index);
571 disparity_jumpIt.Set(2);
575 new_disparityIt.SetIndex(index_pos);
578 index[0] = outputPtr->GetRequestedRegion().GetIndex()[0];
579 index[1] = index_pos[1] + 1;
580 new_disparityIt.SetIndex(index);
587 new_disparityIt.GoToBegin();
589 while (new_disparityIt.GetIndex()[1] <
static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[1]) + outputPtr->GetRequestedRegion().GetIndex()[1])
591 index_pos = new_disparityIt.GetIndex();
593 while (new_disparityIt.GetIndex()[0] <
static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[0]) + outputPtr->GetRequestedRegion().GetIndex()[0] - 1)
595 index_pos = new_disparityIt.GetIndex();
596 disparity_jumpIt.SetIndex(index_pos);
597 if (disparity_jumpIt.Get() == 1 || disparity_jumpIt.Get() == 2)
599 for (
int k = 0; k < 8; k++)
602 index[0] = index_pos[0] + ring[k];
603 disparity_jumpIt.SetIndex(index);
604 if ((disparity_jumpIt.Get() == 1 || disparity_jumpIt.Get() == 2) && disparity_jumpIt.Get() != disparity_jump->GetPixel(index_pos))
606 for (
int i = -2 * win; i <= 2 * win; i++)
609 index2[0] = index_pos[0] + i;
610 index2[1] = index_pos[1] + l;
611 while (old_maskPtr->GetBufferedRegion().IsInside(index2) && old_maskPtr->GetPixel(index2) == 0)
614 index2[1] = index_pos[1] + l;
616 if (index2[0] <
static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[0]) + outputPtr->GetRequestedRegion().GetIndex()[0] &&
617 index2[1] <
static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[1]) +
618 outputPtr->GetRequestedRegion().GetIndex()[1])
620 disparity_jump2It.SetIndex(index2);
621 disparity_jump2It.Set(7);
627 new_disparityIt.SetIndex(index_pos);
630 index[0] = outputPtr->GetRequestedRegion().GetIndex()[0];
631 index[1] = index_pos[1] + 1;
632 new_disparityIt.SetIndex(index);
637 new_disparityIt.GoToBegin();
639 while (new_disparityIt.GetIndex()[1] <
static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[1]) + outputPtr->GetRequestedRegion().GetIndex()[1])
641 index_pos = new_disparityIt.GetIndex();
642 old_maskIt.SetIndex(index_pos);
643 while (old_maskIt.Get() == 0 &&
644 new_disparityIt.GetIndex()[0] <
static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[0]) + outputPtr->GetRequestedRegion().GetIndex()[0] - 1)
647 old_maskIt.SetIndex(new_disparityIt.GetIndex());
649 while (new_disparityIt.GetIndex()[0] <
static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[0]) + outputPtr->GetRequestedRegion().GetIndex()[0] - 1)
651 index_pos = new_disparityIt.GetIndex();
652 disparity_jumpIt.SetIndex(index_pos);
653 if (disparity_jumpIt.Get() == 1)
657 index[0] = index_pos[0] + i;
658 disparity_jumpIt.SetIndex(index);
659 while (disparity_jumpIt.Get() == 1)
661 disparity_jumpIt.Set(0);
663 index[0] = index_pos[0] + i;
664 disparity_jumpIt.SetIndex(index);
667 disparity_jumpIt.SetIndex(index_pos);
668 if (disparity_jumpIt.Get() == 2)
672 index[0] = index_pos[0] + i;
673 disparity_jumpIt.SetIndex(index);
674 while (disparity_jumpIt.Get() == 2)
676 disparity_jumpIt.Set(0);
678 index[0] = index_pos[0] + i;
679 disparity_jumpIt.SetIndex(index);
682 new_disparityIt.SetIndex(index_pos);
685 index[0] = outputPtr->GetRequestedRegion().GetIndex()[0];
686 index[1] = index_pos[1] + 1;
687 new_disparityIt.SetIndex(index);
695 new_disparityIt.GoToBegin();
696 while (new_disparityIt.GetIndex()[1] <
static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[1]) + outputPtr->GetRequestedRegion().GetIndex()[1])
698 index_pos = new_disparityIt.GetIndex();
699 while (new_disparityIt.GetIndex()[0] <
static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[0]) + outputPtr->GetRequestedRegion().GetIndex()[0] - 1)
701 index_pos = new_disparityIt.GetIndex();
702 disparity_jumpIt.SetIndex(index_pos);
703 double value_max = m_EdgeThreshold;
704 int index_max = -100;
705 if (disparity_jumpIt.Get() == 1)
708 while (index_pos[0] + l <
static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[0]) + outputPtr->GetRequestedRegion().GetIndex()[0] &&
710 index_pos[0] + l <
static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[0]) + outputPtr->GetRequestedRegion().GetIndex()[0] &&
711 index_pos[1] <
static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[1]) + outputPtr->GetRequestedRegion().GetIndex()[1])
714 index[0] = index_pos[0] + l;
715 if (canny_edges->GetPixel(index) > value_max)
717 value_max = canny_edges->GetPixel(index);
718 index_max = index_pos[0] + l;
723 if (disparity_jumpIt.Get() == 3)
726 while (index_pos[0] + l <
static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[0]) + outputPtr->GetRequestedRegion().GetIndex()[0] &&
728 index_pos[0] + l <
static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[0]) + outputPtr->GetRequestedRegion().GetIndex()[0] &&
729 index_pos[1] <
static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[1]) + outputPtr->GetRequestedRegion().GetIndex()[1])
732 index[0] = index_pos[0] + l;
733 if (canny_edges->GetPixel(index) > value_max)
735 value_max = canny_edges->GetPixel(index);
736 index_max = index_pos[0] + l;
741 if (disparity_jumpIt.Get() == 2)
744 while (index_pos[0] + l >= outputPtr->GetRequestedRegion().GetIndex()[0] && l >= -big_dist &&
745 index_pos[0] + l <
static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[0]) + outputPtr->GetRequestedRegion().GetIndex()[0] &&
746 index_pos[1] <
static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[1]) + outputPtr->GetRequestedRegion().GetIndex()[1])
749 index[0] = index_pos[0] + l;
750 if (canny_edges->GetPixel(index) > value_max)
752 value_max = canny_edges->GetPixel(index);
753 index_max = index_pos[0] + l;
758 if (disparity_jumpIt.Get() == 4)
761 while (index_pos[0] + l >= outputPtr->GetRequestedRegion().GetIndex()[0] && l >= -big_dist &&
762 index_pos[0] + l <
static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[0]) + outputPtr->GetRequestedRegion().GetIndex()[0] &&
763 index_pos[1] <
static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[1]) + outputPtr->GetRequestedRegion().GetIndex()[1])
766 index[0] = index_pos[0] + l;
767 if (canny_edges->GetPixel(index) > value_max)
769 value_max = canny_edges->GetPixel(index);
770 index_max = index_pos[0] + l;
775 if (index_max != -100)
778 index[0] = index_max;
779 risk_edgesIt.SetIndex(index);
782 new_disparityIt.SetIndex(index_pos);
785 index[0] = outputPtr->GetRequestedRegion().GetIndex()[0];
786 index[1] = index_pos[1] + 1;
787 new_disparityIt.SetIndex(index);
792 new_disparityIt.GoToBegin();
794 while (new_disparityIt.GetIndex()[1] <
static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[1]) + outputPtr->GetRequestedRegion().GetIndex()[1])
796 index_pos = new_disparityIt.GetIndex();
797 while (new_disparityIt.GetIndex()[0] <
static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[0]) + outputPtr->GetRequestedRegion().GetIndex()[0] - 1)
799 index_pos = new_disparityIt.GetIndex();
800 risk_edgesIt.SetIndex(index_pos);
801 if (risk_edgesIt.Get() == 1)
804 for (
int k = 0; k < 8; k++)
807 index[0] = index_pos[0] + ring[k];
808 risk_edgesIt.SetIndex(index);
809 if (risk_edgesIt.Get() > 0)
812 risk_edgesIt.SetIndex(index_pos);
821 for (
int k = 0; k < 8; k++)
824 index[0] = index_pos[0] + ring[k];
825 risk_edgesIt.SetIndex(index);
826 if (risk_edgesIt.Get() > 0)
832 dif = (int)std::abs(pix[0] - pix[1]);
833 risk_edgesIt.SetIndex(index_pos);
834 if (dif == 1 || dif == 7)
838 new_disparityIt.SetIndex(index_pos);
841 index[0] = outputPtr->GetRequestedRegion().GetIndex()[0];
842 index[1] = index_pos[1] + 1;
843 new_disparityIt.SetIndex(index);
850 new_disparityIt.GoToBegin();
852 while (new_disparityIt.GetIndex()[1] <
static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[1]) + outputPtr->GetRequestedRegion().GetIndex()[1] - 1)
854 index_pos = new_disparityIt.GetIndex();
856 while (new_disparityIt.GetIndex()[0] <
static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[0]) + outputPtr->GetRequestedRegion().GetIndex()[0] - 1)
858 index_pos = new_disparityIt.GetIndex();
859 risk_edgesIt.SetIndex(index_pos);
860 if (risk_edgesIt.Get() == 2)
863 index_pos_old = index_pos;
864 while (new_step == 1)
867 for (
int k = 0; k < 8; k++)
869 index_pos_actual = index_pos_old;
870 index_pos_actual[0] = index_pos_old[0] + ring[k];
874 canny_edgesIt.SetIndex(index_pos_actual);
875 if (canny_edgesIt.Get() > m_DiscontinuityHighThreshold && std::abs(canny_edgesIt.Get() - canny_edges->GetPixel(index_pos_old)) < m_MaxEdgeGap)
877 if (outputriskedgesPtr->GetPixel(index_pos_actual) == 0 && canny_edges->GetPixel(index_pos_actual) > m_max)
879 index_pos_new = index_pos_actual;
886 risk_edgesIt.SetIndex(index_pos_old);
888 risk_edgesIt.SetIndex(index_pos_new);
890 auxIt.SetIndex(index_pos_new);
892 index_pos_old = index_pos_new;
897 new_disparityIt.SetIndex(index_pos);
900 index[0] = outputPtr->GetRequestedRegion().GetIndex()[0];
901 index[1] = index_pos[1] + 1;
902 new_disparityIt.SetIndex(index);
911 int big_win = win + 1;
913 double Tol2 = m_Tolerance / 2;
915 new_disparityIt.GoToBegin();
917 while (new_disparityIt.GetIndex()[1] <
static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[1]) + outputPtr->GetRequestedRegion().GetIndex()[1])
919 index_pos = new_disparityIt.GetIndex();
920 if (index_pos[1] >= big_win + outputPtr->GetRequestedRegion().GetIndex()[1])
922 while (new_disparityIt.GetIndex()[0] <
static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[0]) + outputPtr->GetRequestedRegion().GetIndex()[0] - 1)
924 index_pos = new_disparityIt.GetIndex();
925 auxIt.SetIndex(index_pos);
926 if (auxIt.Get() != 0)
928 double m_max = -10000000.;
929 double m_min = -m_max;
931 for (
int j = -big_win; j <= big_win; j++)
933 for (
int i = -big_win; i <= big_win; i++)
935 if (index_pos[0] + i >= old_disparityPtr->GetRequestedRegion().GetIndex()[0] &&
937 static_cast<int>(old_disparityPtr->GetRequestedRegion().GetSize()[0]) + old_disparityPtr->GetRequestedRegion().GetIndex()[0] &&
938 index_pos[1] + j >= old_disparityPtr->GetRequestedRegion().GetIndex()[1] &&
940 static_cast<int>(old_disparityPtr->GetRequestedRegion().GetSize()[1]) + old_disparityPtr->GetRequestedRegion().GetIndex()[1])
942 index_pos0[0] = index_pos[0] + i;
943 index_pos0[1] = index_pos[1] + j;
944 old_maskIt.SetIndex(index_pos0);
945 if (old_maskIt.Get() == 1)
947 if (old_disparityPtr->GetPixel(index_pos0) > m_max)
948 m_max = old_disparityPtr->GetPixel(index_pos0);
949 if (old_disparityPtr->GetPixel(index_pos0) < m_min)
950 m_min = old_disparityPtr->GetPixel(index_pos0);
953 new_disparityIt.SetIndex(index_pos);
958 risk_edgesIt.SetIndex(index_pos);
959 if ((m_max - m_min) < Tol2 &&
Count > 0)
963 for (
int j = -win; j <= win; j++)
965 for (
int i = -win; i <= win; i++)
967 if (index_pos[0] + i >= outputPtr->GetRequestedRegion().GetIndex()[0] &&
968 index_pos[0] + i < static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[0]) + outputPtr->GetRequestedRegion().GetIndex()[0] &&
969 index_pos[1] + j >= outputPtr->GetRequestedRegion().GetIndex()[1] &&
970 index_pos[1] + j < static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[1]) + outputPtr->GetRequestedRegion().GetIndex()[1])
972 index_pos0[0] = index_pos[0] + i;
973 index_pos0[1] = index_pos[1] + j;
974 new_disparityIt.SetIndex(index_pos0);
975 new_maskIt.SetIndex(index_pos0);
976 new_disparityIt.Set(0);
983 new_disparityIt.SetIndex(index_pos);
985 index_pos = new_disparityIt.GetIndex();
988 index[0] = outputPtr->GetRequestedRegion().GetIndex()[0];
989 index[1] = index_pos[1] + 1;
990 new_disparityIt.SetIndex(index);
995 new_disparityIt.GoToBegin();
997 while (new_disparityIt.GetIndex()[1] <
static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[1]) + outputPtr->GetRequestedRegion().GetIndex()[1] - 1)
1000 while (new_disparityIt.GetIndex()[0] <
static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[0]) + outputPtr->GetRequestedRegion().GetIndex()[0] - 1)
1002 index_pos = new_disparityIt.GetIndex();
1003 risk_edgesIt.SetIndex(index_pos);
1004 if (risk_edgesIt.Get() == 2)
1007 for (
int k = 0; k < 8; k++)
1009 index[0] = index_pos[0] + ring[k];
1010 index[1] = index_pos[1];
1011 risk_edgesIt.SetIndex(index);
1012 if (risk_edgesIt.Get() == 2)
1014 risk_edgesIt.Set(0);
1015 risk_edgesIt.SetIndex(index_pos);
1016 risk_edgesIt.Set(0);
1018 risk_edgesIt.SetIndex(index);
1019 if (risk_edgesIt.Get() == 0)
1022 risk_edgesIt.SetIndex(index_pos);
1024 risk_edgesIt.Set(0);
1029 index[0] = outputPtr->GetRequestedRegion().GetIndex()[0];
1030 index[1] = index_pos[1] + 1;
1031 new_disparityIt.SetIndex(index);
1036 new_disparityIt.GoToBegin();
1038 while (new_disparityIt.GetIndex()[1] <
static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[1]) + outputPtr->GetRequestedRegion().GetIndex()[1] - 1)
1040 index_pos = new_disparityIt.GetIndex();
1041 old_maskIt.SetIndex(index_pos);
1042 while (old_maskIt.Get() == 0 &&
1043 new_disparityIt.GetIndex()[0] <
static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[0]) + outputPtr->GetRequestedRegion().GetIndex()[0] - 1)
1046 old_maskIt.SetIndex(new_disparityIt.GetIndex());
1048 index_pos = new_disparityIt.GetIndex();
1049 while (new_disparityIt.GetIndex()[0] <
static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[0]) + outputPtr->GetRequestedRegion().GetIndex()[0] - 1)
1051 index_pos = new_disparityIt.GetIndex();
1054 if (outputriskedgesPtr->GetPixel(index_pos) != 0)
1056 int l = -patch_side;
1057 index[0] = index_pos[0] + l;
1058 index[1] = index_pos[1];
1059 while ((new_disparityIt.GetIndex()[0] + l) >= outputPtr->GetRequestedRegion().GetIndex()[0] && l <= 0 && disparity_jump->GetPixel(index) != 1)
1062 index[0] = index_pos[0] + l;
1064 index[0] = index_pos[0] + l;
1065 if (disparity_jump->GetPixel(index) == 1)
1068 for (
int ii = l + 1; ii <= 0; ii++)
1070 index[0] = index_pos[0] + ii;
1071 new_disparityIt.SetIndex(index);
1072 new_disparityIt.Set(0);
1073 new_maskIt.SetIndex(index);
1077 index[0] = index_pos[0] + i;
1078 while (disparity_jump->GetPixel(index) != 1 && i <= win)
1080 index[0] = index_pos[0] + i;
1081 new_disparityIt.SetIndex(index);
1082 new_disparityIt.Set(0);
1083 new_maskIt.SetIndex(index);
1086 index[0] = index_pos[0] + i;
1089 index[0] = index_pos[0] + i;
1090 index[1] = index_pos[1];
1091 if (disparity_jump->GetPixel(index) == 1)
1093 for (
int j = 1; j <= win; j++)
1095 index2[0] = index_pos[0] + i + j;
1096 index2[1] = index_pos[1];
1097 risk_edgesIt.SetIndex(index2);
1098 if (risk_edgesIt.Get() != 0)
1101 index[0] = index_pos[0] + i;
1102 disparity_jumpIt.SetIndex(index);
1104 disparity_jumpIt.Set(0);
1106 index[0] = index_pos[0] + i + 1;
1107 disparity_jumpIt.SetIndex(index);
1108 if (disparity_jumpIt.Get() == 1)
1110 for (
int j = 1; j <= win; j++)
1112 index2[0] = index_pos[0] + i + 1 + j;
1113 index2[1] = index_pos[1];
1114 risk_edgesIt.SetIndex(index2);
1115 if (risk_edgesIt.Get() != 0)
1118 index[0] = index_pos[0] + i + 1;
1119 disparity_jumpIt.SetIndex(index);
1121 disparity_jumpIt.Set(0);
1125 index[0] = index_pos[0] + l;
1126 index[1] = index_pos[1];
1127 while ((new_disparityIt.GetIndex()[0] + l) >= outputPtr->GetRequestedRegion().GetIndex()[0] && l <= 0 && disparity_jump->GetPixel(index) != 3)
1130 index[0] = index_pos[0] + l;
1132 index[0] = index_pos[0] + l;
1133 if (disparity_jump->GetPixel(index) == 3)
1136 for (
int ii = l + 1; ii <= 0; ii++)
1138 index[0] = index_pos[0] + ii;
1139 new_disparityIt.SetIndex(index);
1140 new_disparityIt.Set(0);
1141 new_maskIt.SetIndex(index);
1145 index[0] = index_pos[0] + i;
1146 while (disparity_jump->GetPixel(index) != 1 && i <= win)
1148 index[0] = index_pos[0] + i;
1149 new_disparityIt.SetIndex(index);
1150 new_disparityIt.Set(0);
1151 new_maskIt.SetIndex(index);
1154 index[0] = index_pos[0] + i;
1157 index[0] = index_pos[0] + i;
1158 if (disparity_jump->GetPixel(index) == 1)
1160 for (
int j = 1; j <= win; j++)
1162 index2[0] = index_pos[0] + i + j;
1163 index2[1] = index_pos[1];
1164 if (outputriskedgesPtr->GetPixel(index2) != 0)
1167 index[0] = index_pos[0] + i;
1168 disparity_jumpIt.SetIndex(index);
1170 disparity_jumpIt.Set(0);
1172 index[0] = index_pos[0] + i + 1;
1173 if (disparity_jump->GetPixel(index) == 1)
1175 for (
int j = 1; j <= win; j++)
1177 index2[0] = index_pos[0] + i + 1 + j;
1178 index2[1] = index_pos[1];
1179 if (outputriskedgesPtr->GetPixel(index2) != 0)
1182 index[0] = index_pos[0] + i + 1;
1183 disparity_jumpIt.SetIndex(index);
1185 disparity_jumpIt.Set(0);
1190 index[0] = index_pos[0] + l;
1191 index[1] = index_pos[1];
1192 while ((new_disparityIt.GetIndex()[0] + l) <
1193 static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[0]) + outputPtr->GetRequestedRegion().GetIndex()[0] - 1 &&
1194 l >= 0 && disparity_jump->GetPixel(index) != 2)
1197 index[0] = index_pos[0] + l;
1199 index[0] = index_pos[0] + l;
1200 if (disparity_jump->GetPixel(index) == 2)
1203 for (
int ii = l - 1; ii >= 0; ii--)
1205 index[0] = index_pos[0] + ii;
1206 new_disparityIt.SetIndex(index);
1207 new_disparityIt.Set(0);
1208 new_maskIt.SetIndex(index);
1212 index[0] = index_pos[0] + i;
1213 while (disparity_jump->GetPixel(index) != 2 && i >= -win)
1215 index[0] = index_pos[0] + i;
1216 new_disparityIt.SetIndex(index);
1217 new_disparityIt.Set(0);
1218 new_maskIt.SetIndex(index);
1221 index[0] = index_pos[0] + i;
1224 index[0] = index_pos[0] + i;
1225 if (disparity_jump->GetPixel(index) == 2)
1227 for (
int j = -1; j >= -win; j--)
1229 index2[0] = index_pos[0] + i + j;
1230 index2[1] = index_pos[1];
1231 if (outputriskedgesPtr->GetPixel(index2) != 0)
1234 index[0] = index_pos[0] + i;
1235 disparity_jumpIt.SetIndex(index);
1237 disparity_jumpIt.Set(0);
1239 index[0] = index_pos[0] + i - 1;
1240 if (disparity_jump->GetPixel(index) == 2)
1242 for (
int j = -1; j >= -win; j--)
1244 index2[0] = index_pos[0] + i - 1 + j;
1245 index2[1] = index_pos[1];
1246 if (outputriskedgesPtr->GetPixel(index2) != 0)
1249 index[0] = index_pos[0] + i - 1;
1250 disparity_jumpIt.SetIndex(index);
1252 disparity_jumpIt.Set(0);
1256 index[0] = index_pos[0] + l;
1257 index[1] = index_pos[1];
1258 while ((new_disparityIt.GetIndex()[0] + l) <
1259 static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[0]) + outputPtr->GetRequestedRegion().GetIndex()[0] - 1 &&
1260 l >= 0 && disparity_jump->GetPixel(index) != 4)
1263 index[0] = index_pos[0] + l;
1265 index[0] = index_pos[0] + l;
1266 if (disparity_jump->GetPixel(index) == 4)
1269 for (
int ii = l - 1; ii >= 0; ii--)
1271 index[0] = index_pos[0] + ii;
1272 new_disparityIt.SetIndex(index);
1273 new_disparityIt.Set(0);
1274 new_maskIt.SetIndex(index);
1278 index[0] = index_pos[0] + i;
1279 while (disparity_jump->GetPixel(index) != 2 && i >= -win)
1281 index[0] = index_pos[0] + i;
1282 new_disparityIt.SetIndex(index);
1283 new_disparityIt.Set(0);
1284 new_maskIt.SetIndex(index);
1287 index[0] = index_pos[0] + i;
1290 index[0] = index_pos[0] + i;
1291 if (disparity_jump->GetPixel(index) == 2)
1293 for (
int j = -1; j >= -win; j--)
1295 index2[0] = index_pos[0] + i + j;
1296 index2[1] = index_pos[1];
1297 if (outputriskedgesPtr->GetPixel(index2) != 0)
1300 index[0] = index_pos[0] + i;
1301 disparity_jumpIt.SetIndex(index);
1303 disparity_jumpIt.Set(0);
1305 index[0] = index_pos[0] + i - 1;
1306 if (disparity_jump->GetPixel(index) == 2)
1308 for (
int j = -1; j >= -win; j--)
1310 index2[0] = index_pos[0] + i - 1 + j;
1311 index2[1] = index_pos[1];
1312 if (outputriskedgesPtr->GetPixel(index2) != 0)
1315 index[0] = index_pos[0] + i - 1;
1316 disparity_jumpIt.SetIndex(index);
1318 disparity_jumpIt.Set(0);
1324 for (
int i = -win + 1; i <= win - 1; i++)
1326 for (
int k = -win + 1; k <= win - 1; k++)
1328 index2[0] = index_pos[0] + i;
1329 index2[1] = index_pos[1] + k;
1330 if (index2[0] >= outputPtr->GetRequestedRegion().GetIndex()[0] && index2[1] >= outputPtr->GetRequestedRegion().GetIndex()[1] &&
1331 index2[0] <
static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[0]) + outputPtr->GetRequestedRegion().GetIndex()[0] &&
1332 index2[1] <
static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[1]) + outputPtr->GetRequestedRegion().GetIndex()[1])
1334 new_disparityIt.SetIndex(index2);
1335 new_maskIt.SetIndex(index2);
1336 new_disparityIt.Set(0);
1342 new_disparityIt.SetIndex(index_pos);
1345 index[0] = outputPtr->GetRequestedRegion().GetIndex()[0];
1346 index[1] = index_pos[1] + 1;
1347 new_disparityIt.SetIndex(index);
1352 new_disparityIt.GoToBegin();
1354 while (new_disparityIt.GetIndex()[1] <
static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[1]) + outputPtr->GetRequestedRegion().GetIndex()[1])
1356 index_pos = new_disparityIt.GetIndex();
1357 old_maskIt.SetIndex(index_pos);
1358 while (old_maskIt.Get() == 0 &&
1359 new_disparityIt.GetIndex()[0] <
static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[0]) + outputPtr->GetRequestedRegion().GetIndex()[0] - 1)
1362 old_maskIt.SetIndex(new_disparityIt.GetIndex());
1364 while (new_disparityIt.GetIndex()[0] <
static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[0]) + outputPtr->GetRequestedRegion().GetIndex()[0] - 1)
1366 index_pos = new_disparityIt.GetIndex();
1367 index[0] = index_pos[0] + 1;
1368 index[1] = index_pos[1];
1369 new_maskIt.SetIndex(index);
1370 risk_edgesIt.SetIndex(index);
1371 if ((disparity_jump->GetPixel(index_pos) == 1 || disparity_jump->GetPixel(index_pos) == 3) && new_maskIt.Get() != 0 && risk_edgesIt.Get() == 0)
1374 index[0] = index_pos[0] + i;
1375 disparity_jumpIt.SetIndex(index);
1376 while (i <= patch_side_small &&
1377 disparity_jumpIt.GetIndex()[0] <
1378 static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[0]) + outputPtr->GetRequestedRegion().GetIndex()[0] - 1 &&
1379 disparity_jumpIt.Get() == 0)
1381 new_disparityIt.SetIndex(index);
1382 new_maskIt.SetIndex(index);
1383 new_disparityIt.Set(0);
1386 index[0] = index_pos[0] + i;
1387 disparity_jumpIt.SetIndex(index);
1390 index[0] = index_pos[0] - 1;
1391 index[1] = index_pos[1];
1392 new_maskIt.SetIndex(index);
1393 risk_edgesIt.SetIndex(index);
1394 if ((disparity_jump->GetPixel(index_pos) == 2 || disparity_jump->GetPixel(index_pos) == 4) && new_maskIt.Get() != 0 && risk_edgesIt.Get() == 0)
1397 index[0] = index_pos[0] + i;
1398 disparity_jumpIt.SetIndex(index);
1399 while (i >= -patch_side_small &&
1400 disparity_jumpIt.GetIndex()[0] <
1401 static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[0]) + outputPtr->GetRequestedRegion().GetIndex()[0] - 1 &&
1402 disparity_jumpIt.Get() == 0)
1404 new_disparityIt.SetIndex(index);
1405 new_maskIt.SetIndex(index);
1406 new_disparityIt.Set(0);
1409 index[0] = index_pos[0] + i;
1410 disparity_jumpIt.SetIndex(index);
1413 new_disparityIt.SetIndex(index_pos);
1416 index[0] = outputPtr->GetRequestedRegion().GetIndex()[0];
1417 index[1] = index_pos[1] + 1;
1418 new_disparityIt.SetIndex(index);
1431 new_disparityIt.GoToBegin();
1433 while (new_disparityIt.GetIndex()[0] <
static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[0]) + outputPtr->GetRequestedRegion().GetIndex()[0] - 1)
1435 index2 = new_disparityIt.GetIndex();
1437 old_maskIt.SetIndex(index2);
1438 while (old_maskIt.Get() == 0 &&
1439 new_disparityIt.GetIndex()[1] <
static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[1]) + outputPtr->GetRequestedRegion().GetIndex()[1] - 1)
1441 index[1] = index[1] + 1;
1442 old_maskIt.SetIndex(index);
1443 new_disparityIt.SetIndex(index);
1445 double disp = old_disparityPtr->GetPixel(index);
1447 while (new_disparityIt.GetIndex()[1] <
static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[1]) + outputPtr->GetRequestedRegion().GetIndex()[1] - 1)
1449 index_pos = new_disparityIt.GetIndex();
1450 old_maskIt.SetIndex(index_pos);
1451 if (old_maskIt.Get() == 0)
1455 if (std::abs(old_disparityPtr->GetPixel(index_pos) - disp) > m_Tolerance && k <= win)
1457 disparity_jump2It.SetIndex(index_pos);
1458 if (old_disparityPtr->GetPixel(index_pos) > disp)
1459 disparity_jump2It.Set(5);
1460 index[0] = index_pos[0] - 1;
1461 index[1] = index_pos[1];
1462 disparity_jump2It.SetIndex(index);
1463 if (old_disparityPtr->GetPixel(index_pos) < disp)
1464 disparity_jump2It.Set(6);
1467 disp = old_disparityPtr->GetPixel(index_pos);
1469 index[0] = index_pos[0];
1470 index[1] = index_pos[1] + 1;
1471 new_disparityIt.SetIndex(index);
1473 new_disparityIt.SetIndex(index2);
1479 new_disparityIt.GoToBegin();
1481 while (new_disparityIt.GetIndex()[0] <
static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[0]) + outputPtr->GetRequestedRegion().GetIndex()[0] - 1)
1484 index2 = new_disparityIt.GetIndex();
1486 while (new_disparityIt.GetIndex()[1] <
static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[1]) + outputPtr->GetRequestedRegion().GetIndex()[1] - 1)
1488 index_pos = new_disparityIt.GetIndex();
1489 if (disparity_jump2->GetPixel(index_pos) == 7)
1491 double disp = old_disparityPtr->GetPixel(index_pos);
1492 for (
int i = 0; i <= big_dist; i++)
1494 if (index_pos[1] + i <
static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[1]) + outputPtr->GetRequestedRegion().GetIndex()[1])
1496 index_pos0[0] = index_pos[0];
1497 index_pos0[1] = index_pos[1] + i;
1498 if (old_maskPtr->GetPixel(index_pos0) == 0)
1502 if (std::abs(old_disparityPtr->GetPixel(index_pos0) - disp) > m_Tolerance / 2 && k <= win)
1504 disparity_jump2It.SetIndex(index_pos0);
1505 if (old_disparityPtr->GetPixel(index_pos0) > disp)
1506 disparity_jump2It.Set(8);
1507 index[0] = index_pos0[0] - 1;
1508 index[1] = index_pos0[1];
1509 disparity_jump2It.SetIndex(index);
1510 if (old_disparityPtr->GetPixel(index_pos0) < disp)
1511 disparity_jump2It.Set(9);
1514 disp = old_disparityPtr->GetPixel(index_pos0);
1519 index[0] = index_pos[0];
1520 index[1] = index_pos[1] + 1;
1521 new_disparityIt.SetIndex(index);
1523 new_disparityIt.SetIndex(index2);
1529 new_disparityIt.GoToBegin();
1531 while (new_disparityIt.GetIndex()[1] <
static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[1]) + outputPtr->GetRequestedRegion().GetIndex()[1] - 1)
1533 index_pos = new_disparityIt.GetIndex();
1534 old_maskIt.SetIndex(index_pos);
1535 while (old_maskIt.Get() == 0 &&
1536 new_disparityIt.GetIndex()[0] <
static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[0]) + outputPtr->GetRequestedRegion().GetIndex()[0] - 1)
1539 old_maskIt.SetIndex(new_disparityIt.GetIndex());
1541 index_pos = new_disparityIt.GetIndex();
1542 for (
int l = patch_side; l > 0; l--)
1544 index[0] = index_pos[0] + l;
1545 index[1] = index_pos[1];
1546 if (disparity_jump->GetPixel(index) != 0 || disparity_jump2->GetPixel(index) != 0 || outputriskedgesPtr->GetPixel(index) != 0)
1548 for (
int i = -win; i <= win; i++)
1550 for (
int k = -win; k <= win; k++)
1552 index2[0] = index_pos[0] + l + i;
1553 index2[1] = index_pos[1] + k;
1554 if (index2[0] >= outputPtr->GetRequestedRegion().GetIndex()[0] && index2[1] >= outputPtr->GetRequestedRegion().GetIndex()[1] &&
1555 index2[0] <
static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[0]) + outputPtr->GetRequestedRegion().GetIndex()[0] &&
1556 index2[1] <
static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[1]) + outputPtr->GetRequestedRegion().GetIndex()[1])
1558 new_disparityIt.SetIndex(index2);
1559 new_maskIt.SetIndex(index2);
1560 new_disparityIt.Set(0);
1567 index[0] = outputPtr->GetRequestedRegion().GetIndex()[0];
1568 index[1] = index_pos[1] + 1;
1569 new_disparityIt.SetIndex(index);
1574 new_disparityIt.GoToBegin();
1575 while (new_disparityIt.GetIndex()[0] <
static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[0]) + outputPtr->GetRequestedRegion().GetIndex()[0] - 1)
1577 index2 = new_disparityIt.GetIndex();
1578 while (new_disparityIt.GetIndex()[1] <
static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[1]) + outputPtr->GetRequestedRegion().GetIndex()[1] - 1)
1580 index_pos = new_disparityIt.GetIndex();
1581 if (outputriskedgesPtr->GetPixel(index_pos) != 0)
1583 int l = 0 - std::min(big_dist,
static_cast<int>(index_pos[1]));
1584 index[0] = index_pos[0];
1585 index[1] = index_pos[1] + l;
1587 while (l <= 0 && disparity_jump2->GetPixel(index) != 5)
1590 index[1] = index_pos[1] + l;
1594 index[1] = index_pos[1] + l;
1595 disparity_jump2It.SetIndex(index);
1596 if (disparity_jump2It.Get() == 5 && l != 0)
1597 disparity_jump2It.Set(0);
1598 for (
int i = l; i <= 0; i++)
1600 index[1] = index_pos[1] + i;
1601 new_disparityIt.SetIndex(index);
1602 new_maskIt.SetIndex(index);
1603 new_disparityIt.Set(0);
1607 int maxSize =
static_cast<int>(disparity_jump2->GetRequestedRegion().GetSize()[1]);
1608 l = std::min(
static_cast<int>((maxSize - 1) - index_pos[1]), big_dist);
1609 index[0] = index_pos[0];
1610 index[1] = index_pos[1] + l;
1611 while (l >= 0 && disparity_jump2->GetPixel(index) != 6)
1614 index[1] = index_pos[1] + l;
1616 index[1] = index_pos[1] + l;
1617 disparity_jump2It.SetIndex(index);
1618 if (disparity_jump2It.Get() == 6 && l != 0)
1619 disparity_jump2It.Set(0);
1620 for (
int i = l; i >= 0; i--)
1622 index[1] = index_pos[1] + i;
1623 new_disparityIt.SetIndex(index);
1624 new_maskIt.SetIndex(index);
1625 new_disparityIt.Set(0);
1628 l = 0 - std::min(big_dist,
static_cast<int>(index_pos[1]));
1630 index[0] = index_pos[0];
1631 index[1] = index_pos[1] + l;
1633 while (l <= 0 && disparity_jump2->GetPixel(index) != 8)
1636 index[1] = index_pos[1] + l;
1638 index[1] = index_pos[1] + l;
1639 disparity_jump2It.SetIndex(index);
1640 if (disparity_jump2It.Get() == 8 && l != 0)
1641 disparity_jump2It.Set(0);
1642 for (
int i = l; i <= 0; i++)
1644 index[1] = index_pos[1] + i;
1645 new_disparityIt.SetIndex(index);
1646 new_maskIt.SetIndex(index);
1647 new_disparityIt.Set(0);
1651 l = std::min(
static_cast<int>((maxSize - 1) - index_pos[1]), big_dist);
1653 index[0] = index_pos[0];
1654 index[1] = index_pos[1] + l;
1655 while (l >= 0 && disparity_jump2->GetPixel(index) != 9)
1658 index[1] = index_pos[1] + l;
1660 index[1] = index_pos[1] + l;
1661 disparity_jump2It.SetIndex(index);
1662 if (disparity_jump2It.Get() == 9 && l != 0)
1663 disparity_jump2It.Set(0);
1664 for (
int i = l; i >= 0; i--)
1666 index[1] = index_pos[1] + i;
1667 new_disparityIt.SetIndex(index);
1668 new_maskIt.SetIndex(index);
1669 new_disparityIt.Set(0);
1673 index[0] = index_pos[0];
1674 index[1] = index_pos[1] + 1;
1675 new_disparityIt.SetIndex(index);
1677 new_disparityIt.SetIndex(index2);
1683 new_disparityIt.GoToBegin();
1684 while (new_disparityIt.GetIndex()[0] <
static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[0]) + outputPtr->GetRequestedRegion().GetIndex()[0] - 1)
1686 index2 = new_disparityIt.GetIndex();
1687 while (new_disparityIt.GetIndex()[1] <
static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[1]) + outputPtr->GetRequestedRegion().GetIndex()[1] - 1)
1689 index_pos = new_disparityIt.GetIndex();
1690 if (disparity_jump2->GetPixel(index_pos) == 5 || disparity_jump2->GetPixel(index_pos) == 8)
1693 index[0] = index_pos[0];
1694 index[1] = index_pos[1] + l;
1695 while (l <= patch_side_small &&
1696 index_pos[1] + l <
static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[1]) + outputPtr->GetRequestedRegion().GetIndex()[1] - 1 &&
1697 disparity_jump2->GetPixel(index) != 6)
1699 new_disparityIt.SetIndex(index);
1700 new_maskIt.SetIndex(index);
1701 new_disparityIt.Set(0);
1704 index[1] = index_pos[1] + l;
1707 if (disparity_jump2->GetPixel(index_pos) == 6 || disparity_jump2->GetPixel(index_pos) == 9)
1710 index[0] = index_pos[0];
1711 index[1] = index_pos[1] + l;
1712 while (l >= -patch_side_small && index_pos[1] + l >= outputPtr->GetRequestedRegion().GetIndex()[1] && disparity_jump2->GetPixel(index) != 5)
1714 new_disparityIt.SetIndex(index);
1715 new_maskIt.SetIndex(index);
1716 new_disparityIt.Set(0);
1719 index[1] = index_pos[1] + l;
1722 index[0] = index_pos[0];
1723 index[1] = index_pos[1] + 1;
1724 new_disparityIt.SetIndex(index);
1726 new_disparityIt.SetIndex(index2);
1735 new_disparityIt.GoToBegin();
1737 while (new_disparityIt.GetIndex()[1] <
static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[1]) + outputPtr->GetRequestedRegion().GetIndex()[1] - 1)
1739 index_pos = new_disparityIt.GetIndex();
1740 while (new_disparityIt.GetIndex()[0] <
static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[0]) + outputPtr->GetRequestedRegion().GetIndex()[0] - 1)
1742 index_pos = new_disparityIt.GetIndex();
1743 new_maskIt.SetIndex(index_pos);
1744 if (new_maskIt.Get() != 0 && subpixelmaskPtr->GetPixel(index_pos) != 0)
1747 for (
int j = -win + 1; j <= win - 1; j++)
1749 for (
int i = -win + 1; i <= win - 1; i++)
1751 index_pos0[0] = index_pos[0] + i;
1752 index_pos0[1] = index_pos[1] + j;
1753 new_maskIt.SetIndex(index_pos0);
1754 if (new_maskIt.Get() != 0 && subpixelmaskPtr->GetPixel(index_pos0) != 0)
1761 new_maskIt.SetIndex(index_pos);
1762 new_disparityIt.SetIndex(index_pos);
1764 new_disparityIt.Set(0);
1768 index[0] = outputPtr->GetRequestedRegion().GetIndex()[0];
1769 index[1] = index_pos[1] + 1;
1770 new_disparityIt.SetIndex(index);