OTB  9.0.0
Orfeo Toolbox
otbAdhesionCorrectionFilter.hxx
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2022 Centre National d'Etudes Spatiales (CNES)
3  *
4  * This file is part of Orfeo Toolbox
5  *
6  * https://www.orfeo-toolbox.org/
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20 
21 #ifndef otbAdhesionCorrectionFilter_hxx
22 #define otbAdhesionCorrectionFilter_hxx
23 
25 
26 #include "itkProgressReporter.h"
27 #include "itkLinearInterpolateImageFunction.h"
28 #include "itkImageRegionIteratorWithIndex.h"
29 #include "itkNormalizedCorrelationImageToImageMetric.h"
30 #include "itkExceptionObject.h"
31 
32 namespace otb
33 {
37 template <class TImage, class TMask>
39 {
40  this->SetNumberOfRequiredInputs(5);
41  this->SetNumberOfRequiredOutputs(3);
43 
44  this->SetNthOutput(1, TMask::New());
45  this->SetNthOutput(2, TImage::New());
46 
47  // Default radius
48  m_Radius.Fill(3);
49 
50  // Default Tolerance
51  m_Tolerance = 0.25;
52 
53  // Default Thresholds
54  m_DiscontinuityThreshold = 10.0;
55  m_DiscontinuityHighThreshold = 30.0;
56  m_MaxEdgeGap = 100.0;
57  m_EdgeThreshold = 100.0;
58 }
59 
60 template <class TImage, class TMask>
62 {
63  // Process object is not const-correct so the const casting is required.
64  this->SetNthInput(1, const_cast<TImage*>(medianmap));
65 }
66 
67 template <class TImage, class TMask>
69 {
70  // Process object is not const-correct so the const casting is required.
71  this->SetNthInput(2, const_cast<TMask*>(medianmask));
72 }
73 
74 template <class TImage, class TMask>
76 {
77  // Process object is not const-correct so the const casting is required.
78  this->SetNthInput(3, const_cast<TImage*>(cannymedianmap));
79 }
80 
81 template <class TImage, class TMask>
83 {
84  // Process object is not const-correct so the const casting is required.
85  this->SetNthInput(4, const_cast<TMask*>(subpixelmask));
86 }
87 
88 template <class TImage, class TMask>
90 {
91  if (this->GetNumberOfInputs() < 2)
92  {
93  return nullptr;
94  }
95  return static_cast<const TImage*>(this->itk::ProcessObject::GetInput(1));
96 }
97 
98 template <class TImage, class TMask>
100 {
101  if (this->GetNumberOfInputs() < 3)
102  {
103  return nullptr;
104  }
105  return static_cast<const TMask*>(this->itk::ProcessObject::GetInput(2));
106 }
107 
108 template <class TImage, class TMask>
110 {
111  if (this->GetNumberOfInputs() < 4)
112  {
113  return nullptr;
114  }
115  return static_cast<const TImage*>(this->itk::ProcessObject::GetInput(3));
116 }
117 
118 template <class TImage, class TMask>
120 {
121  if (this->GetNumberOfInputs() < 5)
122  {
123  return nullptr;
124  }
125  return static_cast<const TMask*>(this->itk::ProcessObject::GetInput(4));
126 }
127 
128 template <class TImage, class TMask>
130 {
131  if (this->GetNumberOfOutputs() < 2)
132  {
133  return nullptr;
134  }
135  return static_cast<TMask*>(this->itk::ProcessObject::GetOutput(1));
136 }
137 
138 template <class TImage, class TMask>
140 {
141  if (this->GetNumberOfOutputs() < 3)
142  {
143  return nullptr;
144  }
145  return static_cast<TImage*>(this->itk::ProcessObject::GetOutput(2));
146 }
147 
148 template <class TImage, class TMask>
150 {
151  // Call superclass implementation
152  Superclass::GenerateOutputInformation();
153 
154  // Retrieve output pointers
155  TImage* outputPtr = this->GetOutput();
156  TMask* outputMaskPtr = this->GetOutputMask();
157  TImage* outputriskedgesPtr = this->GetOutputRiskEdges();
158 
159  // Update size and spacing according to grid step
160  ImageRegionType largestRegion = outputPtr->GetLargestPossibleRegion();
161  SizeType outputSize = largestRegion.GetSize();
162  m_ImageSize = outputSize;
163  SpacingType outputSpacing = outputPtr->GetSignedSpacing();
164 
165  // Set spacing
166  outputPtr->SetSignedSpacing(outputSpacing);
167  outputMaskPtr->SetSignedSpacing(outputSpacing);
168  outputriskedgesPtr->SetSignedSpacing(outputSpacing);
169 
170  // Set largest region size
171  largestRegion.SetSize(outputSize);
172  outputPtr->SetLargestPossibleRegion(largestRegion);
173  outputMaskPtr->SetLargestPossibleRegion(largestRegion);
174  outputriskedgesPtr->SetLargestPossibleRegion(largestRegion);
175 }
176 
177 template <class TImage, class TMask>
179 {
180  // call the superclass' implementation of this method
181  Superclass::GenerateInputRequestedRegion();
182 
183  // get pointers to the input and output
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();
192 
193  if (!canny_edges || !old_disparityPtr || !old_maskPtr || !canny_disparity || !subpixelmaskPtr || !outputPtr || !outputmaskPtr || !outputriskedgesPtr)
194  {
195  return;
196  }
197 
198  // get a copy of the fixed requested region (should equal the output
199  // requested region)
200  ImageRegionType RequestedRegion;
201  RequestedRegion = outputPtr->GetRequestedRegion();
202 
203  SizeType Big_Radius;
204  Big_Radius[0] = m_Radius[0] + 2;
205  Big_Radius[1] = m_Radius[1] + 2;
206  RequestedRegion.PadByRadius(Big_Radius);
207 
208  // crop the region at the largest possible region
209  if (RequestedRegion.Crop(canny_edges->GetLargestPossibleRegion()))
210  {
211  canny_edges->SetRequestedRegion(RequestedRegion);
212  }
213  else
214  {
215  // Couldn't crop the region (requested region is outside the largest
216  // possible region). Throw an exception.
217  // store what we tried to request (prior to trying to crop)
218  canny_edges->SetRequestedRegion(RequestedRegion);
219 
220  // build an exception
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);
227  throw e;
228  }
229 
230  // crop the region at the largest possible region
231  if (RequestedRegion.Crop(old_disparityPtr->GetLargestPossibleRegion()))
232  {
233  old_disparityPtr->SetRequestedRegion(RequestedRegion);
234  }
235  else
236  {
237  // Couldn't crop the region (requested region is outside the largest
238  // possible region). Throw an exception.
239  // store what we tried to request (prior to trying to crop)
240  old_disparityPtr->SetRequestedRegion(RequestedRegion);
241 
242  // build an exception
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);
249  throw e;
250  }
251 
252  // crop the region at the largest possible region
253  if (RequestedRegion.Crop(old_maskPtr->GetLargestPossibleRegion()))
254  {
255  old_maskPtr->SetRequestedRegion(RequestedRegion);
256  }
257  else
258  {
259  // Couldn't crop the region (requested region is outside the largest
260  // possible region). Throw an exception.
261  // store what we tried to request (prior to trying to crop)
262  old_maskPtr->SetRequestedRegion(RequestedRegion);
263 
264  // build an exception
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);
271  throw e;
272  }
273 
274  // crop the region at the largest possible region
275  if (RequestedRegion.Crop(canny_disparity->GetLargestPossibleRegion()))
276  {
277  canny_disparity->SetRequestedRegion(RequestedRegion);
278  }
279  else
280  {
281  // Couldn't crop the region (requested region is outside the largest
282  // possible region). Throw an exception.
283  // store what we tried to request (prior to trying to crop)
284  canny_disparity->SetRequestedRegion(RequestedRegion);
285 
286  // build an exception
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);
293  throw e;
294  }
295 
296  // crop the region at the largest possible region
297  if (RequestedRegion.Crop(subpixelmaskPtr->GetLargestPossibleRegion()))
298  {
299  subpixelmaskPtr->SetRequestedRegion(RequestedRegion);
300  }
301  else
302  {
303  // Couldn't crop the region (requested region is outside the largest
304  // possible region). Throw an exception.
305  // store what we tried to request (prior to trying to crop)
306  subpixelmaskPtr->SetRequestedRegion(RequestedRegion);
307 
308  // build an exception
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);
315  throw e;
316  }
317 
318  return;
319 }
320 
321 template <class TImage, class TMask>
323 {
324  // Allocate outputs
325  this->AllocateOutputs();
326 
327  // get pointers to the input and output
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();
336 
337  outputriskedgesPtr->FillBuffer(0.0);
338 
339  int win = m_Radius[0] + 1; // should be also equal to m_Radius[1]
340  int patch_side = 2 * win + 1;
341  int patch_side_small = 2 * (win - 1) + 1;
342  int big_dist = 3 * win;
343  int dif, new_step;
344  /* positions around a pixel*/
345  IntVectorType ring;
346  IntVectorType pix;
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]);
350  ring.push_back(1);
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]);
354  ring.push_back(-1);
355 
362 
363  AuxImagePointerType disparity_jump = AuxImageType::New();
364  disparity_jump->SetRegions(old_disparityPtr->GetRequestedRegion());
365  disparity_jump->Allocate();
366  disparity_jump->FillBuffer(0);
367 
368  AuxImagePointerType disparity_jump2 = AuxImageType::New();
369  disparity_jump2->SetRegions(old_disparityPtr->GetRequestedRegion());
370  disparity_jump2->Allocate();
371  disparity_jump2->FillBuffer(0);
372 
373  AuxImagePointerType aux = AuxImageType::New();
374  aux->SetRegions(outputPtr->GetRequestedRegion());
375  aux->Allocate();
376  aux->FillBuffer(0);
377 
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());
384 
385  IndexType index, index2, index_pos, index_pos_actual, index_pos_old, index_pos_new, index_pos0;
386 
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());
395 
396 
397  new_maskIt.GoToBegin();
398  new_disparityIt.GoToBegin();
399 
401  while (!new_maskIt.IsAtEnd() && !new_disparityIt.IsAtEnd())
402  {
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());
407  ++old_disparityIt;
408  ++new_maskIt;
409  ++new_disparityIt;
410  ++old_maskIt;
411  }
413 
414  new_disparityIt.GoToBegin();
415  while (new_disparityIt.GetIndex()[1] < static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[1]) + outputPtr->GetRequestedRegion().GetIndex()[1])
416  {
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)
420  {
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])
424  {
425  ++new_disparityIt;
426  old_maskIt.SetIndex(new_disparityIt.GetIndex());
427  }
428  index_pos = new_disparityIt.GetIndex();
429  disparity_jumpIt.SetIndex(index_pos);
430  disparity_jumpIt.Set(-1); // first disparity in the epipolar line
431  int k = 0;
432  while (new_disparityIt.GetIndex()[0] <
433  static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[0]) + outputPtr->GetRequestedRegion().GetIndex()[0] - win)
434  {
435  index_pos = new_disparityIt.GetIndex();
436  if (old_maskPtr->GetPixel(index_pos) == 0) // holes in the disparity map
437  {
438  if (k == 0)
439  {
440  k++;
441  int i = 1;
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)
449  {
450  i++;
451  index[0] = index_pos[0] + i;
452  new_disparityIt.SetIndex(index);
453  old_maskIt.SetIndex(index);
454  }
455  if (new_disparityIt.GetIndex()[0] ==
456  static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[0]) + outputPtr->GetRequestedRegion().GetIndex()[0] - 1)
457  {
458  disparity_jumpIt.SetIndex(index_pos);
459  disparity_jumpIt.Set(4);
460  }
461  else
462  {
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)
467  {
468  if (old_disparityPtr->GetPixel(index) < old_disparityPtr->GetPixel(index2))
469  {
470  index2[0] = index_pos[0] + i - 1;
471  disparity_jumpIt.SetIndex(index2);
472  disparity_jumpIt.Set(3);
473  if (i >= win)
474  {
475  disparity_jumpIt.SetIndex(index_pos);
476  disparity_jumpIt.Set(4); // big holes
477  }
478  }
479  else
480  {
481  disparity_jumpIt.SetIndex(index_pos);
482  disparity_jumpIt.Set(4);
483  if (i >= win)
484  {
485  index[0] = index_pos[0] + i - 1;
486  disparity_jumpIt.SetIndex(index);
487  disparity_jumpIt.Set(3); // big holes
488  }
489  }
490  }
491  }
492  }
493  }
494  else // Disparity map discontinuities
495  {
496  if (canny_disparity->GetPixel(index_pos) > m_DiscontinuityThreshold)
497  {
498  int pp = 0;
499 
500  for (k = 0; k < 8; k++)
501  {
502  index[0] = index_pos[0] + ring[k];
503  index[1] = index_pos[1];
504  if (old_maskPtr->GetPixel(index) == 0)
505  pp++;
506  }
507  if (pp == 0)
508  {
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))
514  {
515  disparity_jumpIt.SetIndex(index);
516  disparity_jumpIt.Set(1);
517  }
518  if (old_disparityPtr->GetPixel(index) > old_disparityPtr->GetPixel(index2))
519  {
520  disparity_jumpIt.SetIndex(index2);
521  disparity_jumpIt.Set(2);
522  }
523  }
524  }
525  k = 0;
526  }
527  new_disparityIt.SetIndex(index_pos);
528  ++new_disparityIt;
529  }
530  }
531  index[0] = outputPtr->GetRequestedRegion().GetIndex()[0];
532  index[1] = index_pos[1] + 1;
533  new_disparityIt.SetIndex(index);
534  }
535 
538  new_disparityIt.GoToBegin();
539 
540  while (new_disparityIt.GetIndex()[1] < static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[1]) + outputPtr->GetRequestedRegion().GetIndex()[1])
541  {
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)
546  {
547  ++new_disparityIt;
548  old_maskIt.SetIndex(new_disparityIt.GetIndex());
549  }
550  index_pos = new_disparityIt.GetIndex();
551  old_disparityIt.SetIndex(index_pos);
552  // double disp = old_disparityIt.Get();
553  while (new_disparityIt.GetIndex()[0] < static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[0]) + outputPtr->GetRequestedRegion().GetIndex()[0] - 1)
554  {
555  index_pos = new_disparityIt.GetIndex();
556  index = index_pos;
557  index[0] = index_pos[0] + 1;
558  old_maskIt.SetIndex(index_pos);
559  if (old_maskIt.Get() != 0 && old_maskPtr->GetPixel(index) != 0)
560  {
561  if (std::abs(old_disparityPtr->GetPixel(index_pos) - old_disparityPtr->GetPixel(index)) > m_Tolerance)
562  {
563  if (old_disparityPtr->GetPixel(index) > old_disparityPtr->GetPixel(index_pos) && disparity_jump->GetPixel(index_pos) == 0)
564  {
565  disparity_jumpIt.SetIndex(index_pos);
566  disparity_jumpIt.Set(1);
567  }
568  if (old_disparityPtr->GetPixel(index) < old_disparityPtr->GetPixel(index_pos) && disparity_jump->GetPixel(index) == 0)
569  {
570  disparity_jumpIt.SetIndex(index);
571  disparity_jumpIt.Set(2);
572  }
573  }
574  }
575  new_disparityIt.SetIndex(index_pos);
576  ++new_disparityIt;
577  }
578  index[0] = outputPtr->GetRequestedRegion().GetIndex()[0];
579  index[1] = index_pos[1] + 1;
580  new_disparityIt.SetIndex(index);
581  }
582 
587  new_disparityIt.GoToBegin();
588 
589  while (new_disparityIt.GetIndex()[1] < static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[1]) + outputPtr->GetRequestedRegion().GetIndex()[1])
590  {
591  index_pos = new_disparityIt.GetIndex();
592  ++new_disparityIt;
593  while (new_disparityIt.GetIndex()[0] < static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[0]) + outputPtr->GetRequestedRegion().GetIndex()[0] - 1)
594  {
595  index_pos = new_disparityIt.GetIndex();
596  disparity_jumpIt.SetIndex(index_pos);
597  if (disparity_jumpIt.Get() == 1 || disparity_jumpIt.Get() == 2)
598  {
599  for (int k = 0; k < 8; k++)
600  {
601  index = index_pos;
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))
605  {
606  for (int i = -2 * win; i <= 2 * win; i++)
607  {
608  int l = -2 - win;
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)
612  {
613  l++;
614  index2[1] = index_pos[1] + l;
615  }
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]) // add this condition to avoid seg fault
619  {
620  disparity_jump2It.SetIndex(index2);
621  disparity_jump2It.Set(7);
622  }
623  }
624  }
625  }
626  }
627  new_disparityIt.SetIndex(index_pos);
628  ++new_disparityIt;
629  }
630  index[0] = outputPtr->GetRequestedRegion().GetIndex()[0];
631  index[1] = index_pos[1] + 1;
632  new_disparityIt.SetIndex(index);
633  }
634 
637  new_disparityIt.GoToBegin();
638 
639  while (new_disparityIt.GetIndex()[1] < static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[1]) + outputPtr->GetRequestedRegion().GetIndex()[1])
640  {
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)
645  {
646  ++new_disparityIt;
647  old_maskIt.SetIndex(new_disparityIt.GetIndex());
648  }
649  while (new_disparityIt.GetIndex()[0] < static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[0]) + outputPtr->GetRequestedRegion().GetIndex()[0] - 1)
650  {
651  index_pos = new_disparityIt.GetIndex();
652  disparity_jumpIt.SetIndex(index_pos);
653  if (disparity_jumpIt.Get() == 1)
654  {
655  int i = 1;
656  index = index_pos;
657  index[0] = index_pos[0] + i;
658  disparity_jumpIt.SetIndex(index);
659  while (disparity_jumpIt.Get() == 1)
660  {
661  disparity_jumpIt.Set(0);
662  i++;
663  index[0] = index_pos[0] + i;
664  disparity_jumpIt.SetIndex(index);
665  }
666  }
667  disparity_jumpIt.SetIndex(index_pos);
668  if (disparity_jumpIt.Get() == 2)
669  {
670  int i = -1;
671  index = index_pos;
672  index[0] = index_pos[0] + i;
673  disparity_jumpIt.SetIndex(index);
674  while (disparity_jumpIt.Get() == 2)
675  {
676  disparity_jumpIt.Set(0);
677  i--;
678  index[0] = index_pos[0] + i;
679  disparity_jumpIt.SetIndex(index);
680  }
681  }
682  new_disparityIt.SetIndex(index_pos);
683  ++new_disparityIt;
684  }
685  index[0] = outputPtr->GetRequestedRegion().GetIndex()[0];
686  index[1] = index_pos[1] + 1;
687  new_disparityIt.SetIndex(index);
688  }
689 
694  // Exploring the left-right epipolar direction
695  new_disparityIt.GoToBegin();
696  while (new_disparityIt.GetIndex()[1] < static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[1]) + outputPtr->GetRequestedRegion().GetIndex()[1])
697  {
698  index_pos = new_disparityIt.GetIndex();
699  while (new_disparityIt.GetIndex()[0] < static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[0]) + outputPtr->GetRequestedRegion().GetIndex()[0] - 1)
700  {
701  index_pos = new_disparityIt.GetIndex();
702  disparity_jumpIt.SetIndex(index_pos);
703  double value_max = m_EdgeThreshold;
704  int index_max = -100; // Canny edges should be larger than m_EdgeThreshold
705  if (disparity_jumpIt.Get() == 1)
706  {
707  int l = 1;
708  while (index_pos[0] + l < static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[0]) + outputPtr->GetRequestedRegion().GetIndex()[0] &&
709  l <= big_dist &&
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])
712  {
713  index = index_pos;
714  index[0] = index_pos[0] + l;
715  if (canny_edges->GetPixel(index) > value_max)
716  {
717  value_max = canny_edges->GetPixel(index);
718  index_max = index_pos[0] + l;
719  }
720  l++;
721  }
722  }
723  if (disparity_jumpIt.Get() == 3)
724  {
725  int l = 1;
726  while (index_pos[0] + l < static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[0]) + outputPtr->GetRequestedRegion().GetIndex()[0] &&
727  l <= big_dist &&
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])
730  {
731  index = index_pos;
732  index[0] = index_pos[0] + l;
733  if (canny_edges->GetPixel(index) > value_max)
734  {
735  value_max = canny_edges->GetPixel(index);
736  index_max = index_pos[0] + l;
737  }
738  l++;
739  }
740  }
741  if (disparity_jumpIt.Get() == 2)
742  {
743  int l = -1;
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])
747  {
748  index = index_pos;
749  index[0] = index_pos[0] + l;
750  if (canny_edges->GetPixel(index) > value_max)
751  {
752  value_max = canny_edges->GetPixel(index);
753  index_max = index_pos[0] + l;
754  }
755  l--;
756  }
757  }
758  if (disparity_jumpIt.Get() == 4)
759  {
760  int l = -1;
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])
764  {
765  index = index_pos;
766  index[0] = index_pos[0] + l;
767  if (canny_edges->GetPixel(index) > value_max)
768  {
769  value_max = canny_edges->GetPixel(index);
770  index_max = index_pos[0] + l;
771  }
772  l--;
773  }
774  }
775  if (index_max != -100)
776  {
777  index = index_pos;
778  index[0] = index_max;
779  risk_edgesIt.SetIndex(index);
780  risk_edgesIt.Set(1); // flag= 1 for risk edges
781  }
782  new_disparityIt.SetIndex(index_pos);
783  ++new_disparityIt;
784  }
785  index[0] = outputPtr->GetRequestedRegion().GetIndex()[0];
786  index[1] = index_pos[1] + 1;
787  new_disparityIt.SetIndex(index);
788  }
789 
792  new_disparityIt.GoToBegin();
793 
794  while (new_disparityIt.GetIndex()[1] < static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[1]) + outputPtr->GetRequestedRegion().GetIndex()[1])
795  {
796  index_pos = new_disparityIt.GetIndex();
797  while (new_disparityIt.GetIndex()[0] < static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[0]) + outputPtr->GetRequestedRegion().GetIndex()[0] - 1)
798  {
799  index_pos = new_disparityIt.GetIndex();
800  risk_edgesIt.SetIndex(index_pos);
801  if (risk_edgesIt.Get() == 1)
802  {
803  int pp = 0;
804  for (int k = 0; k < 8; k++)
805  {
806  index = index_pos;
807  index[0] = index_pos[0] + ring[k];
808  risk_edgesIt.SetIndex(index);
809  if (risk_edgesIt.Get() > 0)
810  pp++;
811  }
812  risk_edgesIt.SetIndex(index_pos);
813  if (pp == 0)
814  risk_edgesIt.Set(0); // remove isolate points
815  if (pp == 1)
816  risk_edgesIt.Set(2);
817  if (pp == 2)
818  {
819  int l = 0;
820  pix.clear();
821  for (int k = 0; k < 8; k++)
822  {
823  index = index_pos;
824  index[0] = index_pos[0] + ring[k];
825  risk_edgesIt.SetIndex(index);
826  if (risk_edgesIt.Get() > 0)
827  {
828  pix.push_back(k);
829  l++;
830  }
831  }
832  dif = (int)std::abs(pix[0] - pix[1]);
833  risk_edgesIt.SetIndex(index_pos);
834  if (dif == 1 || dif == 7)
835  risk_edgesIt.Set(2);
836  }
837  }
838  new_disparityIt.SetIndex(index_pos);
839  ++new_disparityIt;
840  }
841  index[0] = outputPtr->GetRequestedRegion().GetIndex()[0];
842  index[1] = index_pos[1] + 1;
843  new_disparityIt.SetIndex(index);
844  }
845 
850  new_disparityIt.GoToBegin();
851 
852  while (new_disparityIt.GetIndex()[1] < static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[1]) + outputPtr->GetRequestedRegion().GetIndex()[1] - 1)
853  {
854  index_pos = new_disparityIt.GetIndex();
855  ++new_disparityIt;
856  while (new_disparityIt.GetIndex()[0] < static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[0]) + outputPtr->GetRequestedRegion().GetIndex()[0] - 1)
857  {
858  index_pos = new_disparityIt.GetIndex();
859  risk_edgesIt.SetIndex(index_pos);
860  if (risk_edgesIt.Get() == 2)
861  {
862  new_step = 1;
863  index_pos_old = index_pos;
864  while (new_step == 1)
865  {
866  new_step = 0;
867  for (int k = 0; k < 8; k++)
868  { // Ignore merging cases
869  index_pos_actual = index_pos_old;
870  index_pos_actual[0] = index_pos_old[0] + ring[k];
871  double m_max = 0;
872  // if the next pixel is the continuation of the border,we extend the risk edge //
873  // The extend the border, it has to be as prevalent as before //
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)
876  {
877  if (outputriskedgesPtr->GetPixel(index_pos_actual) == 0 && canny_edges->GetPixel(index_pos_actual) > m_max)
878  {
879  index_pos_new = index_pos_actual;
880  new_step = 1;
881  }
882  }
883  }
884  if (new_step == 1)
885  {
886  risk_edgesIt.SetIndex(index_pos_old);
887  risk_edgesIt.Set(1);
888  risk_edgesIt.SetIndex(index_pos_new);
889  risk_edgesIt.Set(2);
890  auxIt.SetIndex(index_pos_new);
891  auxIt.Set(1);
892  index_pos_old = index_pos_new;
893  // steps++;
894  }
895  }
896  }
897  new_disparityIt.SetIndex(index_pos);
898  ++new_disparityIt;
899  }
900  index[0] = outputPtr->GetRequestedRegion().GetIndex()[0];
901  index[1] = index_pos[1] + 1;
902  new_disparityIt.SetIndex(index);
903  }
904 
910  int Count;
911  int big_win = win + 1;
912  // int half_big_win = (2*big_win +1)*(2*big_win +1) /2;
913  double Tol2 = m_Tolerance / 2;
914 
915  new_disparityIt.GoToBegin();
916 
917  while (new_disparityIt.GetIndex()[1] < static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[1]) + outputPtr->GetRequestedRegion().GetIndex()[1])
918  {
919  index_pos = new_disparityIt.GetIndex();
920  if (index_pos[1] >= big_win + outputPtr->GetRequestedRegion().GetIndex()[1])
921  {
922  while (new_disparityIt.GetIndex()[0] < static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[0]) + outputPtr->GetRequestedRegion().GetIndex()[0] - 1)
923  {
924  index_pos = new_disparityIt.GetIndex();
925  auxIt.SetIndex(index_pos);
926  if (auxIt.Get() != 0)
927  {
928  double m_max = -10000000.;
929  double m_min = -m_max;
930  Count = 0;
931  for (int j = -big_win; j <= big_win; j++)
932  {
933  for (int i = -big_win; i <= big_win; i++)
934  {
935  if (index_pos[0] + i >= old_disparityPtr->GetRequestedRegion().GetIndex()[0] &&
936  index_pos[0] + i <
937  static_cast<int>(old_disparityPtr->GetRequestedRegion().GetSize()[0]) + old_disparityPtr->GetRequestedRegion().GetIndex()[0] &&
938  index_pos[1] + j >= old_disparityPtr->GetRequestedRegion().GetIndex()[1] &&
939  index_pos[1] + j <
940  static_cast<int>(old_disparityPtr->GetRequestedRegion().GetSize()[1]) + old_disparityPtr->GetRequestedRegion().GetIndex()[1])
941  {
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)
946  {
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);
951  Count++;
952  }
953  new_disparityIt.SetIndex(index_pos);
954  }
955  }
956  }
958  risk_edgesIt.SetIndex(index_pos);
959  if ((m_max - m_min) < Tol2 && Count > 0)
960  risk_edgesIt.Set(0);
961  else
962  {
963  for (int j = -win; j <= win; j++)
964  {
965  for (int i = -win; i <= win; i++)
966  {
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])
971  {
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);
977  new_maskIt.Set(0);
978  }
979  }
980  }
981  }
982  }
983  new_disparityIt.SetIndex(index_pos);
984  ++new_disparityIt;
985  index_pos = new_disparityIt.GetIndex();
986  }
987  }
988  index[0] = outputPtr->GetRequestedRegion().GetIndex()[0];
989  index[1] = index_pos[1] + 1;
990  new_disparityIt.SetIndex(index);
991  }
992 
995  new_disparityIt.GoToBegin();
996 
997  while (new_disparityIt.GetIndex()[1] < static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[1]) + outputPtr->GetRequestedRegion().GetIndex()[1] - 1)
998  {
999  ++new_disparityIt;
1000  while (new_disparityIt.GetIndex()[0] < static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[0]) + outputPtr->GetRequestedRegion().GetIndex()[0] - 1)
1001  {
1002  index_pos = new_disparityIt.GetIndex();
1003  risk_edgesIt.SetIndex(index_pos);
1004  if (risk_edgesIt.Get() == 2)
1005  {
1006  int pp = 0;
1007  for (int k = 0; k < 8; k++)
1008  {
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)
1013  { // 2pix edge
1014  risk_edgesIt.Set(0);
1015  risk_edgesIt.SetIndex(index_pos);
1016  risk_edgesIt.Set(0);
1017  }
1018  risk_edgesIt.SetIndex(index);
1019  if (risk_edgesIt.Get() == 0)
1020  pp++;
1021  }
1022  risk_edgesIt.SetIndex(index_pos);
1023  if (pp == 8)
1024  risk_edgesIt.Set(0); // 1pix edge
1025  }
1026  ++new_disparityIt;
1027  ++disparity_jumpIt;
1028  }
1029  index[0] = outputPtr->GetRequestedRegion().GetIndex()[0];
1030  index[1] = index_pos[1] + 1;
1031  new_disparityIt.SetIndex(index);
1032  }
1033 
1036  new_disparityIt.GoToBegin();
1037 
1038  while (new_disparityIt.GetIndex()[1] < static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[1]) + outputPtr->GetRequestedRegion().GetIndex()[1] - 1)
1039  {
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)
1044  {
1045  ++new_disparityIt;
1046  old_maskIt.SetIndex(new_disparityIt.GetIndex());
1047  }
1048  index_pos = new_disparityIt.GetIndex();
1049  while (new_disparityIt.GetIndex()[0] < static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[0]) + outputPtr->GetRequestedRegion().GetIndex()[0] - 1)
1050  {
1051  index_pos = new_disparityIt.GetIndex();
1052  int pp = 0;
1053  int pp2 = 0;
1054  if (outputriskedgesPtr->GetPixel(index_pos) != 0)
1055  { // left
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)
1060  {
1061  l++;
1062  index[0] = index_pos[0] + l;
1063  }
1064  index[0] = index_pos[0] + l;
1065  if (disparity_jump->GetPixel(index) == 1)
1066  {
1067  pp++;
1068  for (int ii = l + 1; ii <= 0; ii++)
1069  {
1070  index[0] = index_pos[0] + ii;
1071  new_disparityIt.SetIndex(index);
1072  new_disparityIt.Set(0);
1073  new_maskIt.SetIndex(index);
1074  new_maskIt.Set(0);
1075  }
1076  int i = 1;
1077  index[0] = index_pos[0] + i;
1078  while (disparity_jump->GetPixel(index) != 1 && i <= win)
1079  {
1080  index[0] = index_pos[0] + i;
1081  new_disparityIt.SetIndex(index);
1082  new_disparityIt.Set(0);
1083  new_maskIt.SetIndex(index);
1084  new_maskIt.Set(0);
1085  i++;
1086  index[0] = index_pos[0] + i;
1087  }
1088  pp2 = 0;
1089  index[0] = index_pos[0] + i;
1090  index[1] = index_pos[1];
1091  if (disparity_jump->GetPixel(index) == 1)
1092  { // 2a adhesion
1093  for (int j = 1; j <= win; j++)
1094  {
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)
1099  pp2++;
1100  }
1101  index[0] = index_pos[0] + i;
1102  disparity_jumpIt.SetIndex(index);
1103  if (pp2 == 0)
1104  disparity_jumpIt.Set(0);
1105  }
1106  index[0] = index_pos[0] + i + 1;
1107  disparity_jumpIt.SetIndex(index);
1108  if (disparity_jumpIt.Get() == 1)
1109  {
1110  for (int j = 1; j <= win; j++)
1111  {
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)
1116  pp2++;
1117  }
1118  index[0] = index_pos[0] + i + 1;
1119  disparity_jumpIt.SetIndex(index);
1120  if (pp2 == 0)
1121  disparity_jumpIt.Set(0);
1122  }
1123  }
1124  l = -big_dist;
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)
1128  {
1129  l++;
1130  index[0] = index_pos[0] + l;
1131  }
1132  index[0] = index_pos[0] + l;
1133  if (disparity_jump->GetPixel(index) == 3)
1134  {
1135  pp++;
1136  for (int ii = l + 1; ii <= 0; ii++)
1137  {
1138  index[0] = index_pos[0] + ii;
1139  new_disparityIt.SetIndex(index);
1140  new_disparityIt.Set(0);
1141  new_maskIt.SetIndex(index);
1142  new_maskIt.Set(0);
1143  }
1144  int i = 1;
1145  index[0] = index_pos[0] + i;
1146  while (disparity_jump->GetPixel(index) != 1 && i <= win)
1147  {
1148  index[0] = index_pos[0] + i;
1149  new_disparityIt.SetIndex(index);
1150  new_disparityIt.Set(0);
1151  new_maskIt.SetIndex(index);
1152  new_maskIt.Set(0);
1153  i++;
1154  index[0] = index_pos[0] + i;
1155  }
1156  pp2 = 0;
1157  index[0] = index_pos[0] + i;
1158  if (disparity_jump->GetPixel(index) == 1)
1159  { // 2a adhesion
1160  for (int j = 1; j <= win; j++)
1161  {
1162  index2[0] = index_pos[0] + i + j;
1163  index2[1] = index_pos[1];
1164  if (outputriskedgesPtr->GetPixel(index2) != 0)
1165  pp2++;
1166  }
1167  index[0] = index_pos[0] + i;
1168  disparity_jumpIt.SetIndex(index);
1169  if (pp2 == 0)
1170  disparity_jumpIt.Set(0);
1171  }
1172  index[0] = index_pos[0] + i + 1;
1173  if (disparity_jump->GetPixel(index) == 1)
1174  {
1175  for (int j = 1; j <= win; j++)
1176  {
1177  index2[0] = index_pos[0] + i + 1 + j;
1178  index2[1] = index_pos[1];
1179  if (outputriskedgesPtr->GetPixel(index2) != 0)
1180  pp2++;
1181  }
1182  index[0] = index_pos[0] + i + 1;
1183  disparity_jumpIt.SetIndex(index);
1184  if (pp2 == 0)
1185  disparity_jumpIt.Set(0);
1186  }
1187  }
1188  // right
1189  l = patch_side;
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)
1195  {
1196  l--;
1197  index[0] = index_pos[0] + l;
1198  }
1199  index[0] = index_pos[0] + l;
1200  if (disparity_jump->GetPixel(index) == 2)
1201  {
1202  pp++;
1203  for (int ii = l - 1; ii >= 0; ii--)
1204  {
1205  index[0] = index_pos[0] + ii;
1206  new_disparityIt.SetIndex(index);
1207  new_disparityIt.Set(0);
1208  new_maskIt.SetIndex(index);
1209  new_maskIt.Set(0);
1210  }
1211  int i = -1;
1212  index[0] = index_pos[0] + i;
1213  while (disparity_jump->GetPixel(index) != 2 && i >= -win)
1214  {
1215  index[0] = index_pos[0] + i;
1216  new_disparityIt.SetIndex(index);
1217  new_disparityIt.Set(0);
1218  new_maskIt.SetIndex(index);
1219  new_maskIt.Set(0);
1220  i--;
1221  index[0] = index_pos[0] + i;
1222  }
1223  pp2 = 0;
1224  index[0] = index_pos[0] + i;
1225  if (disparity_jump->GetPixel(index) == 2)
1226  { // 2a adhesion
1227  for (int j = -1; j >= -win; j--)
1228  {
1229  index2[0] = index_pos[0] + i + j;
1230  index2[1] = index_pos[1];
1231  if (outputriskedgesPtr->GetPixel(index2) != 0)
1232  pp2++;
1233  }
1234  index[0] = index_pos[0] + i;
1235  disparity_jumpIt.SetIndex(index);
1236  if (pp2 == 0)
1237  disparity_jumpIt.Set(0);
1238  }
1239  index[0] = index_pos[0] + i - 1;
1240  if (disparity_jump->GetPixel(index) == 2)
1241  {
1242  for (int j = -1; j >= -win; j--)
1243  {
1244  index2[0] = index_pos[0] + i - 1 + j;
1245  index2[1] = index_pos[1];
1246  if (outputriskedgesPtr->GetPixel(index2) != 0)
1247  pp2++;
1248  }
1249  index[0] = index_pos[0] + i - 1;
1250  disparity_jumpIt.SetIndex(index);
1251  if (pp2 == 0)
1252  disparity_jumpIt.Set(0);
1253  }
1254  }
1255  l = big_dist;
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)
1261  {
1262  l--;
1263  index[0] = index_pos[0] + l;
1264  }
1265  index[0] = index_pos[0] + l;
1266  if (disparity_jump->GetPixel(index) == 4)
1267  {
1268  pp++;
1269  for (int ii = l - 1; ii >= 0; ii--)
1270  {
1271  index[0] = index_pos[0] + ii;
1272  new_disparityIt.SetIndex(index);
1273  new_disparityIt.Set(0);
1274  new_maskIt.SetIndex(index);
1275  new_maskIt.Set(0);
1276  }
1277  int i = -1;
1278  index[0] = index_pos[0] + i;
1279  while (disparity_jump->GetPixel(index) != 2 && i >= -win)
1280  {
1281  index[0] = index_pos[0] + i;
1282  new_disparityIt.SetIndex(index);
1283  new_disparityIt.Set(0);
1284  new_maskIt.SetIndex(index);
1285  new_maskIt.Set(0);
1286  i--;
1287  index[0] = index_pos[0] + i;
1288  }
1289  pp2 = 0;
1290  index[0] = index_pos[0] + i;
1291  if (disparity_jump->GetPixel(index) == 2)
1292  { // 2a adhesion
1293  for (int j = -1; j >= -win; j--)
1294  {
1295  index2[0] = index_pos[0] + i + j;
1296  index2[1] = index_pos[1];
1297  if (outputriskedgesPtr->GetPixel(index2) != 0)
1298  pp2++;
1299  }
1300  index[0] = index_pos[0] + i;
1301  disparity_jumpIt.SetIndex(index);
1302  if (pp2 == 0)
1303  disparity_jumpIt.Set(0);
1304  }
1305  index[0] = index_pos[0] + i - 1;
1306  if (disparity_jump->GetPixel(index) == 2)
1307  {
1308  for (int j = -1; j >= -win; j--)
1309  {
1310  index2[0] = index_pos[0] + i - 1 + j;
1311  index2[1] = index_pos[1];
1312  if (outputriskedgesPtr->GetPixel(index2) != 0)
1313  pp2++;
1314  }
1315  index[0] = index_pos[0] + i - 1;
1316  disparity_jumpIt.SetIndex(index);
1317  if (pp2 == 0)
1318  disparity_jumpIt.Set(0);
1319  }
1320  }
1321  // if(pp==0) /// remove around the risk_edge if no disparity jump have been found
1322  // unique difference between new_adhesion and new_adhesion_2
1323  // the version 2 commented the previous line
1324  for (int i = -win + 1; i <= win - 1; i++)
1325  {
1326  for (int k = -win + 1; k <= win - 1; k++)
1327  {
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])
1333  {
1334  new_disparityIt.SetIndex(index2);
1335  new_maskIt.SetIndex(index2);
1336  new_disparityIt.Set(0);
1337  new_maskIt.Set(0);
1338  }
1339  }
1340  }
1341  }
1342  new_disparityIt.SetIndex(index_pos);
1343  ++new_disparityIt;
1344  }
1345  index[0] = outputPtr->GetRequestedRegion().GetIndex()[0];
1346  index[1] = index_pos[1] + 1;
1347  new_disparityIt.SetIndex(index);
1348  }
1349 
1352  new_disparityIt.GoToBegin();
1353 
1354  while (new_disparityIt.GetIndex()[1] < static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[1]) + outputPtr->GetRequestedRegion().GetIndex()[1])
1355  {
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)
1360  {
1361  ++new_disparityIt;
1362  old_maskIt.SetIndex(new_disparityIt.GetIndex());
1363  }
1364  while (new_disparityIt.GetIndex()[0] < static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[0]) + outputPtr->GetRequestedRegion().GetIndex()[0] - 1)
1365  {
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)
1372  {
1373  int i = 1;
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)
1380  {
1381  new_disparityIt.SetIndex(index);
1382  new_maskIt.SetIndex(index);
1383  new_disparityIt.Set(0);
1384  new_maskIt.Set(0);
1385  i++;
1386  index[0] = index_pos[0] + i;
1387  disparity_jumpIt.SetIndex(index);
1388  }
1389  }
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)
1395  {
1396  int i = -1;
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)
1403  {
1404  new_disparityIt.SetIndex(index);
1405  new_maskIt.SetIndex(index);
1406  new_disparityIt.Set(0);
1407  new_maskIt.Set(0);
1408  i--;
1409  index[0] = index_pos[0] + i;
1410  disparity_jumpIt.SetIndex(index);
1411  }
1412  }
1413  new_disparityIt.SetIndex(index_pos);
1414  ++new_disparityIt;
1415  }
1416  index[0] = outputPtr->GetRequestedRegion().GetIndex()[0];
1417  index[1] = index_pos[1] + 1;
1418  new_disparityIt.SetIndex(index);
1419  }
1420 
1431  new_disparityIt.GoToBegin();
1432 
1433  while (new_disparityIt.GetIndex()[0] < static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[0]) + outputPtr->GetRequestedRegion().GetIndex()[0] - 1)
1434  {
1435  index2 = new_disparityIt.GetIndex();
1436  index = index2;
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)
1440  {
1441  index[1] = index[1] + 1;
1442  old_maskIt.SetIndex(index);
1443  new_disparityIt.SetIndex(index);
1444  }
1445  double disp = old_disparityPtr->GetPixel(index);
1446  int k = 0;
1447  while (new_disparityIt.GetIndex()[1] < static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[1]) + outputPtr->GetRequestedRegion().GetIndex()[1] - 1)
1448  {
1449  index_pos = new_disparityIt.GetIndex();
1450  old_maskIt.SetIndex(index_pos);
1451  if (old_maskIt.Get() == 0)
1452  k++;
1453  else
1454  {
1455  if (std::abs(old_disparityPtr->GetPixel(index_pos) - disp) > m_Tolerance && k <= win)
1456  { // only small holes
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);
1465  }
1466  k = 0;
1467  disp = old_disparityPtr->GetPixel(index_pos);
1468  }
1469  index[0] = index_pos[0];
1470  index[1] = index_pos[1] + 1;
1471  new_disparityIt.SetIndex(index);
1472  }
1473  new_disparityIt.SetIndex(index2);
1474  ++new_disparityIt;
1475  }
1476 
1479  new_disparityIt.GoToBegin();
1480 
1481  while (new_disparityIt.GetIndex()[0] < static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[0]) + outputPtr->GetRequestedRegion().GetIndex()[0] - 1)
1482  {
1483  int k = 0;
1484  index2 = new_disparityIt.GetIndex();
1485  index = index2;
1486  while (new_disparityIt.GetIndex()[1] < static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[1]) + outputPtr->GetRequestedRegion().GetIndex()[1] - 1)
1487  {
1488  index_pos = new_disparityIt.GetIndex();
1489  if (disparity_jump2->GetPixel(index_pos) == 7)
1490  {
1491  double disp = old_disparityPtr->GetPixel(index_pos);
1492  for (int i = 0; i <= big_dist; i++)
1493  {
1494  if (index_pos[1] + i < static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[1]) + outputPtr->GetRequestedRegion().GetIndex()[1])
1495  {
1496  index_pos0[0] = index_pos[0];
1497  index_pos0[1] = index_pos[1] + i;
1498  if (old_maskPtr->GetPixel(index_pos0) == 0)
1499  k++;
1500  else
1501  {
1502  if (std::abs(old_disparityPtr->GetPixel(index_pos0) - disp) > m_Tolerance / 2 && k <= win)
1503  { // only small holes
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);
1512  }
1513  k = 0;
1514  disp = old_disparityPtr->GetPixel(index_pos0);
1515  }
1516  }
1517  }
1518  }
1519  index[0] = index_pos[0];
1520  index[1] = index_pos[1] + 1;
1521  new_disparityIt.SetIndex(index);
1522  }
1523  new_disparityIt.SetIndex(index2);
1524  ++new_disparityIt;
1525  }
1526 
1529  new_disparityIt.GoToBegin();
1530 
1531  while (new_disparityIt.GetIndex()[1] < static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[1]) + outputPtr->GetRequestedRegion().GetIndex()[1] - 1)
1532  {
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)
1537  {
1538  ++new_disparityIt;
1539  old_maskIt.SetIndex(new_disparityIt.GetIndex());
1540  }
1541  index_pos = new_disparityIt.GetIndex();
1542  for (int l = patch_side; l > 0; l--)
1543  {
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)
1547  {
1548  for (int i = -win; i <= win; i++)
1549  {
1550  for (int k = -win; k <= win; k++)
1551  {
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])
1557  {
1558  new_disparityIt.SetIndex(index2);
1559  new_maskIt.SetIndex(index2);
1560  new_disparityIt.Set(0);
1561  new_maskIt.Set(0);
1562  }
1563  }
1564  }
1565  }
1566  }
1567  index[0] = outputPtr->GetRequestedRegion().GetIndex()[0];
1568  index[1] = index_pos[1] + 1;
1569  new_disparityIt.SetIndex(index);
1570  }
1571 
1574  new_disparityIt.GoToBegin();
1575  while (new_disparityIt.GetIndex()[0] < static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[0]) + outputPtr->GetRequestedRegion().GetIndex()[0] - 1)
1576  {
1577  index2 = new_disparityIt.GetIndex();
1578  while (new_disparityIt.GetIndex()[1] < static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[1]) + outputPtr->GetRequestedRegion().GetIndex()[1] - 1)
1579  {
1580  index_pos = new_disparityIt.GetIndex();
1581  if (outputriskedgesPtr->GetPixel(index_pos) != 0)
1582  {
1583  int l = 0 - std::min(big_dist, static_cast<int>(index_pos[1])); // out of bound checking
1584  index[0] = index_pos[0];
1585  index[1] = index_pos[1] + l;
1586 
1587  while (l <= 0 && disparity_jump2->GetPixel(index) != 5)
1588  {
1589  l++;
1590  index[1] = index_pos[1] + l;
1591  }
1592 
1593 
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++)
1599  {
1600  index[1] = index_pos[1] + i;
1601  new_disparityIt.SetIndex(index);
1602  new_maskIt.SetIndex(index);
1603  new_disparityIt.Set(0);
1604  new_maskIt.Set(0);
1605  }
1606 
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); // out of bound checking
1609  index[0] = index_pos[0];
1610  index[1] = index_pos[1] + l;
1611  while (l >= 0 && disparity_jump2->GetPixel(index) != 6)
1612  {
1613  l--;
1614  index[1] = index_pos[1] + l;
1615  }
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--)
1621  {
1622  index[1] = index_pos[1] + i;
1623  new_disparityIt.SetIndex(index);
1624  new_maskIt.SetIndex(index);
1625  new_disparityIt.Set(0);
1626  new_maskIt.Set(0);
1627  }
1628  l = 0 - std::min(big_dist, static_cast<int>(index_pos[1]));
1629 
1630  index[0] = index_pos[0];
1631  index[1] = index_pos[1] + l;
1632 
1633  while (l <= 0 && disparity_jump2->GetPixel(index) != 8)
1634  {
1635  l++;
1636  index[1] = index_pos[1] + l;
1637  }
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++)
1643  {
1644  index[1] = index_pos[1] + i;
1645  new_disparityIt.SetIndex(index);
1646  new_maskIt.SetIndex(index);
1647  new_disparityIt.Set(0);
1648  new_maskIt.Set(0);
1649  }
1650 
1651  l = std::min(static_cast<int>((maxSize - 1) - index_pos[1]), big_dist);
1652 
1653  index[0] = index_pos[0];
1654  index[1] = index_pos[1] + l;
1655  while (l >= 0 && disparity_jump2->GetPixel(index) != 9)
1656  {
1657  l--;
1658  index[1] = index_pos[1] + l;
1659  }
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--)
1665  {
1666  index[1] = index_pos[1] + i;
1667  new_disparityIt.SetIndex(index);
1668  new_maskIt.SetIndex(index);
1669  new_disparityIt.Set(0);
1670  new_maskIt.Set(0);
1671  }
1672  }
1673  index[0] = index_pos[0];
1674  index[1] = index_pos[1] + 1;
1675  new_disparityIt.SetIndex(index);
1676  }
1677  new_disparityIt.SetIndex(index2);
1678  ++new_disparityIt;
1679  }
1680 
1683  new_disparityIt.GoToBegin();
1684  while (new_disparityIt.GetIndex()[0] < static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[0]) + outputPtr->GetRequestedRegion().GetIndex()[0] - 1)
1685  {
1686  index2 = new_disparityIt.GetIndex();
1687  while (new_disparityIt.GetIndex()[1] < static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[1]) + outputPtr->GetRequestedRegion().GetIndex()[1] - 1)
1688  {
1689  index_pos = new_disparityIt.GetIndex();
1690  if (disparity_jump2->GetPixel(index_pos) == 5 || disparity_jump2->GetPixel(index_pos) == 8)
1691  {
1692  int l = 0;
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)
1698  {
1699  new_disparityIt.SetIndex(index);
1700  new_maskIt.SetIndex(index);
1701  new_disparityIt.Set(0);
1702  new_maskIt.Set(0);
1703  l++;
1704  index[1] = index_pos[1] + l;
1705  }
1706  }
1707  if (disparity_jump2->GetPixel(index_pos) == 6 || disparity_jump2->GetPixel(index_pos) == 9)
1708  {
1709  int l = 0;
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)
1713  {
1714  new_disparityIt.SetIndex(index);
1715  new_maskIt.SetIndex(index);
1716  new_disparityIt.Set(0);
1717  new_maskIt.Set(0);
1718  l--;
1719  index[1] = index_pos[1] + l;
1720  }
1721  }
1722  index[0] = index_pos[0];
1723  index[1] = index_pos[1] + 1;
1724  new_disparityIt.SetIndex(index);
1725  }
1726  new_disparityIt.SetIndex(index2);
1727  ++new_disparityIt;
1728  }
1729 
1734  int nb_disp = 3;
1735  new_disparityIt.GoToBegin();
1736 
1737  while (new_disparityIt.GetIndex()[1] < static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[1]) + outputPtr->GetRequestedRegion().GetIndex()[1] - 1)
1738  {
1739  index_pos = new_disparityIt.GetIndex();
1740  while (new_disparityIt.GetIndex()[0] < static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[0]) + outputPtr->GetRequestedRegion().GetIndex()[0] - 1)
1741  {
1742  index_pos = new_disparityIt.GetIndex();
1743  new_maskIt.SetIndex(index_pos);
1744  if (new_maskIt.Get() != 0 && subpixelmaskPtr->GetPixel(index_pos) != 0)
1745  {
1746  nb_disp = 0;
1747  for (int j = -win + 1; j <= win - 1; j++)
1748  {
1749  for (int i = -win + 1; i <= win - 1; i++)
1750  {
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)
1755  nb_disp++;
1756  }
1757  }
1758  }
1759  if (nb_disp <= 2)
1760  {
1761  new_maskIt.SetIndex(index_pos);
1762  new_disparityIt.SetIndex(index_pos);
1763  new_maskIt.Set(0);
1764  new_disparityIt.Set(0);
1765  }
1766  ++new_disparityIt;
1767  }
1768  index[0] = outputPtr->GetRequestedRegion().GetIndex()[0];
1769  index[1] = index_pos[1] + 1;
1770  new_disparityIt.SetIndex(index);
1771  }
1772 }
1773 
1774 } // end namespace otb
1775 
1776 #endif
otb::AdhesionCorrectionFilter::GetMedianMaskInput
const TMask * GetMedianMaskInput()
Definition: otbAdhesionCorrectionFilter.hxx:99
otb::AdhesionCorrectionFilter::AuxImagePointerType
AuxImageType::Pointer AuxImagePointerType
Definition: otbAdhesionCorrectionFilter.h:100
otb::AdhesionCorrectionFilter::SetSubPixelMaskInput
void SetSubPixelMaskInput(const TMask *subpixelmask)
Definition: otbAdhesionCorrectionFilter.hxx:82
otb::AdhesionCorrectionFilter::GetOutputRiskEdges
TImage * GetOutputRiskEdges()
Definition: otbAdhesionCorrectionFilter.hxx:139
otb::AdhesionCorrectionFilter::SizeType
TImage::SizeType SizeType
Definition: otbAdhesionCorrectionFilter.h:89
otb::AdhesionCorrectionFilter::SetEdgesDisparityInput
void SetEdgesDisparityInput(const TImage *cannymedianmap)
Definition: otbAdhesionCorrectionFilter.hxx:75
otb
The "otb" namespace contains all Orfeo Toolbox (OTB) classes.
Definition: otbJoinContainer.h:32
otb::Count
Compute the density of a neighborhood centerred in a pixel.
Definition: otbSimplePointCountStrategy.h:43
otb::AdhesionCorrectionFilter::GetSubPixelMaskInput
const TMask * GetSubPixelMaskInput()
Definition: otbAdhesionCorrectionFilter.hxx:119
otb::AdhesionCorrectionFilter::GetMedianDisparityInput
const TImage * GetMedianDisparityInput()
Definition: otbAdhesionCorrectionFilter.hxx:89
otb::AdhesionCorrectionFilter::GetEdgesDisparityInput
const TImage * GetEdgesDisparityInput()
Definition: otbAdhesionCorrectionFilter.hxx:109
otb::AdhesionCorrectionFilter::GetOutputMask
TMask * GetOutputMask()
Definition: otbAdhesionCorrectionFilter.hxx:129
otb::AdhesionCorrectionFilter::GenerateOutputInformation
void GenerateOutputInformation(void) override
Definition: otbAdhesionCorrectionFilter.hxx:149
otbAdhesionCorrectionFilter.h
otb::AdhesionCorrectionFilter::GenerateData
void GenerateData() override
Definition: otbAdhesionCorrectionFilter.hxx:322
otb::AdhesionCorrectionFilter::AdhesionCorrectionFilter
AdhesionCorrectionFilter()
Definition: otbAdhesionCorrectionFilter.hxx:38
otb::AdhesionCorrectionFilter::IntVectorType
std::vector< int > IntVectorType
Definition: otbAdhesionCorrectionFilter.h:102
otb::AdhesionCorrectionFilter::SetMedianDisparityInput
void SetMedianDisparityInput(const TImage *medianmap)
Definition: otbAdhesionCorrectionFilter.hxx:61
otb::AdhesionCorrectionFilter::GenerateInputRequestedRegion
void GenerateInputRequestedRegion(void) override
Definition: otbAdhesionCorrectionFilter.hxx:178
otb::AdhesionCorrectionFilter::SpacingType
TImage::SpacingType SpacingType
Definition: otbAdhesionCorrectionFilter.h:91
otb::AdhesionCorrectionFilter::SetMedianMaskInput
void SetMedianMaskInput(const TMask *medianmask)
Definition: otbAdhesionCorrectionFilter.hxx:68
otb::AdhesionCorrectionFilter::IndexType
TImage::IndexType IndexType
Definition: otbAdhesionCorrectionFilter.h:90
otb::AdhesionCorrectionFilter::ImageRegionType
TImage::RegionType ImageRegionType
Definition: otbAdhesionCorrectionFilter.h:83