OTB  6.7.0
Orfeo Toolbox
otbAdhesionCorrectionFilter.hxx
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2005-2019 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"
30 #include "itkExceptionObject.h"
31 
32 namespace otb
33 {
37 template <class TImage, class TMask>
40 {
41  this->SetNumberOfRequiredInputs( 5 );
42  this->SetNumberOfRequiredOutputs(3);
44 
45  this->SetNthOutput(1,TMask::New());
46  this->SetNthOutput(2,TImage::New());
47 
48  // Default radius
49  m_Radius.Fill(3);
50 
51  // Default Tolerance
52  m_Tolerance = 0.25;
53 
54  // Default Thresholds
55  m_DiscontinuityThreshold = 10.0;
56  m_DiscontinuityHighThreshold = 30.0;
57  m_MaxEdgeGap = 100.0;
58  m_EdgeThreshold = 100.0;
59 }
60 
61 template <class TImage, class TMask>
62 void
64 ::SetMedianDisparityInput( const TImage * medianmap )
65 {
66  // Process object is not const-correct so the const casting is required.
67  this->SetNthInput(1, const_cast<TImage *>( medianmap ));
68 }
69 
70 template <class TImage, class TMask>
71 void
73 ::SetMedianMaskInput( const TMask * medianmask)
74 {
75  // Process object is not const-correct so the const casting is required.
76  this->SetNthInput(2, const_cast<TMask *>( medianmask ));
77 }
78 
79 template <class TImage, class TMask>
80 void
82 ::SetEdgesDisparityInput( const TImage * cannymedianmap)
83 {
84  // Process object is not const-correct so the const casting is required.
85  this->SetNthInput(3, const_cast<TImage *>( cannymedianmap ));
86 }
87 
88 template <class TImage, class TMask>
89 void
91 ::SetSubPixelMaskInput( const TMask * subpixelmask)
92 {
93  // Process object is not const-correct so the const casting is required.
94  this->SetNthInput(4, const_cast<TMask *>( subpixelmask ));
95 }
96 
97 template <class TImage, class TMask>
98 const TImage *
101 {
102  if (this->GetNumberOfInputs()<2)
103  {
104  return nullptr;
105  }
106  return static_cast<const TImage *>(this->itk::ProcessObject::GetInput(1));
107 }
108 
109 template <class TImage, class TMask>
110 const TMask *
113 {
114  if (this->GetNumberOfInputs()<3)
115  {
116  return nullptr;
117  }
118  return static_cast<const TMask *>(this->itk::ProcessObject::GetInput(2));
119 }
120 
121 template <class TImage, class TMask>
122 const TImage *
125 {
126  if (this->GetNumberOfInputs()<4)
127  {
128  return nullptr;
129  }
130  return static_cast<const TImage *>(this->itk::ProcessObject::GetInput(3));
131 }
132 
133 template <class TImage, class TMask>
134 const TMask *
137 {
138  if (this->GetNumberOfInputs()<5)
139  {
140  return nullptr;
141  }
142  return static_cast<const TMask *>(this->itk::ProcessObject::GetInput(4));
143 }
144 
145 template <class TImage, class TMask>
146 TMask *
149 {
150  if (this->GetNumberOfOutputs()<2)
151  {
152  return nullptr;
153  }
154  return static_cast<TMask *>(this->itk::ProcessObject::GetOutput(1));
155 }
156 
157 template <class TImage, class TMask>
158 TImage *
161 {
162  if (this->GetNumberOfOutputs()<3)
163  {
164  return nullptr;
165  }
166  return static_cast<TImage *>(this->itk::ProcessObject::GetOutput(2));
167 }
168 
169 template <class TImage, class TMask>
170 void
173 {
174  // Call superclass implementation
175  Superclass::GenerateOutputInformation();
176 
177  // Retrieve output pointers
178  TImage * outputPtr = this->GetOutput();
179  TMask * outputMaskPtr = this->GetOutputMask();
180  TImage * outputriskedgesPtr = this->GetOutputRiskEdges();
181 
182  // Update size and spacing according to grid step
183  ImageRegionType largestRegion = outputPtr->GetLargestPossibleRegion();
184  SizeType outputSize = largestRegion.GetSize();
185  m_ImageSize = outputSize;
186  SpacingType outputSpacing = outputPtr->GetSignedSpacing();
187 
188  // Set spacing
189  outputPtr->SetSignedSpacing(outputSpacing);
190  outputMaskPtr->SetSignedSpacing(outputSpacing);
191  outputriskedgesPtr->SetSignedSpacing(outputSpacing);
192 
193  // Set largest region size
194  largestRegion.SetSize(outputSize);
195  outputPtr->SetLargestPossibleRegion(largestRegion);
196  outputMaskPtr->SetLargestPossibleRegion(largestRegion);
197  outputriskedgesPtr->SetLargestPossibleRegion(largestRegion);
198 }
199 
200 template <class TImage, class TMask>
201 void
204 {
205  // call the superclass' implementation of this method
206  Superclass::GenerateInputRequestedRegion();
207 
208  // get pointers to the input and output
209  TImage * canny_edges = const_cast< TImage * >( this->GetInput());
210  TImage * old_disparityPtr = const_cast< TImage * >( this->GetMedianDisparityInput());
211  TMask * old_maskPtr = const_cast< TMask * >( this->GetMedianMaskInput());
212  TImage * canny_disparity = const_cast< TImage * >(this->GetEdgesDisparityInput());
213  TMask * subpixelmaskPtr = const_cast< TMask * >(this->GetSubPixelMaskInput());
214  TImage * outputPtr = this->GetOutput();
215  TMask * outputmaskPtr = this->GetOutputMask();
216  TImage * outputriskedgesPtr = this->GetOutputRiskEdges();
217 
218  if ( !canny_edges || !old_disparityPtr || !old_maskPtr || !canny_disparity || !subpixelmaskPtr ||
219  !outputPtr || !outputmaskPtr || !outputriskedgesPtr)
220  {
221  return;
222  }
223 
224  // get a copy of the fixed requested region (should equal the output
225  // requested region)
226  ImageRegionType RequestedRegion;
227  RequestedRegion = outputPtr->GetRequestedRegion();
228 
229  SizeType Big_Radius;
230  Big_Radius[0] = m_Radius[0] +2;
231  Big_Radius[1] = m_Radius[1] +2;
232  RequestedRegion.PadByRadius( Big_Radius );
233 
234  // crop the region at the largest possible region
235  if ( RequestedRegion.Crop(canny_edges->GetLargestPossibleRegion()))
236  {
237  canny_edges->SetRequestedRegion( RequestedRegion );
238  }
239  else
240  {
241  // Couldn't crop the region (requested region is outside the largest
242  // possible region). Throw an exception.
243  // store what we tried to request (prior to trying to crop)
244  canny_edges->SetRequestedRegion( RequestedRegion );
245 
246  // build an exception
247  itk::InvalidRequestedRegionError e(__FILE__, __LINE__);
248  std::ostringstream msg;
249  msg << this->GetNameOfClass()
250  << "::GenerateInputRequestedRegion()";
251  e.SetLocation(msg.str());
252  e.SetDescription("Requested region is (at least partially) outside the largest possible region of image 1.");
253  e.SetDataObject(canny_edges);
254  throw e;
255  }
256 
257  // crop the region at the largest possible region
258  if ( RequestedRegion.Crop(old_disparityPtr->GetLargestPossibleRegion()))
259  {
260  old_disparityPtr->SetRequestedRegion( RequestedRegion );
261  }
262  else
263  {
264  // Couldn't crop the region (requested region is outside the largest
265  // possible region). Throw an exception.
266  // store what we tried to request (prior to trying to crop)
267  old_disparityPtr->SetRequestedRegion( RequestedRegion );
268 
269  // build an exception
270  itk::InvalidRequestedRegionError e(__FILE__, __LINE__);
271  std::ostringstream msg;
272  msg << this->GetNameOfClass()
273  << "::GenerateInputRequestedRegion()";
274  e.SetLocation(msg.str());
275  e.SetDescription("Requested region is (at least partially) outside the largest possible region of image 1.");
276  e.SetDataObject(old_disparityPtr);
277  throw e;
278  }
279 
280  // crop the region at the largest possible region
281  if ( RequestedRegion.Crop(old_maskPtr->GetLargestPossibleRegion()))
282  {
283  old_maskPtr->SetRequestedRegion( RequestedRegion );
284  }
285  else
286  {
287  // Couldn't crop the region (requested region is outside the largest
288  // possible region). Throw an exception.
289  // store what we tried to request (prior to trying to crop)
290  old_maskPtr->SetRequestedRegion( RequestedRegion );
291 
292  // build an exception
293  itk::InvalidRequestedRegionError e(__FILE__, __LINE__);
294  std::ostringstream msg;
295  msg << this->GetNameOfClass()
296  << "::GenerateInputRequestedRegion()";
297  e.SetLocation(msg.str());
298  e.SetDescription("Requested region is (at least partially) outside the largest possible region of image 1.");
299  e.SetDataObject(old_maskPtr);
300  throw e;
301  }
302 
303  // crop the region at the largest possible region
304  if ( RequestedRegion.Crop(canny_disparity->GetLargestPossibleRegion()))
305  {
306  canny_disparity->SetRequestedRegion( RequestedRegion );
307  }
308  else
309  {
310  // Couldn't crop the region (requested region is outside the largest
311  // possible region). Throw an exception.
312  // store what we tried to request (prior to trying to crop)
313  canny_disparity->SetRequestedRegion( RequestedRegion );
314 
315  // build an exception
316  itk::InvalidRequestedRegionError e(__FILE__, __LINE__);
317  std::ostringstream msg;
318  msg << this->GetNameOfClass()
319  << "::GenerateInputRequestedRegion()";
320  e.SetLocation(msg.str());
321  e.SetDescription("Requested region is (at least partially) outside the largest possible region of image 1.");
322  e.SetDataObject(canny_disparity);
323  throw e;
324  }
325 
326  // crop the region at the largest possible region
327  if ( RequestedRegion.Crop(subpixelmaskPtr->GetLargestPossibleRegion()))
328  {
329  subpixelmaskPtr->SetRequestedRegion( RequestedRegion );
330  }
331  else
332  {
333  // Couldn't crop the region (requested region is outside the largest
334  // possible region). Throw an exception.
335  // store what we tried to request (prior to trying to crop)
336  subpixelmaskPtr->SetRequestedRegion( RequestedRegion );
337 
338  // build an exception
339  itk::InvalidRequestedRegionError e(__FILE__, __LINE__);
340  std::ostringstream msg;
341  msg << this->GetNameOfClass()
342  << "::GenerateInputRequestedRegion()";
343  e.SetLocation(msg.str());
344  e.SetDescription("Requested region is (at least partially) outside the largest possible region of image 1.");
345  e.SetDataObject(subpixelmaskPtr);
346  throw e;
347  }
348 
349  return;
350 }
351 
352 template <class TImage, class TMask>
353 void
356 {
357  // Allocate outputs
358  this->AllocateOutputs();
359 
360  // get pointers to the input and output
361  TImage * canny_edges = const_cast< TImage * >( this->GetInput());
362  TImage * old_disparityPtr = const_cast< TImage * >( this->GetMedianDisparityInput());
363  TMask * old_maskPtr = const_cast< TMask * >( this->GetMedianMaskInput());
364  TImage * canny_disparity = const_cast< TImage * >(this->GetEdgesDisparityInput());
365  TMask * subpixelmaskPtr = const_cast< TMask * >(this->GetSubPixelMaskInput());
366  TImage * outputPtr = this->GetOutput();
367  TMask * outputmaskPtr = this->GetOutputMask();
368  TImage * outputriskedgesPtr = this->GetOutputRiskEdges();
369 
370  outputriskedgesPtr->FillBuffer(0.0);
371 
372  int win = m_Radius[0]+1; // should be also equal to m_Radius[1]
373  int patch_side = 2*win+1;
374  int patch_side_small = 2*(win-1)+1;
375  int big_dist = 3*win;
376  int dif, new_step;
377  /* positions around a pixel*/
378  IntVectorType ring;
379  IntVectorType pix;
380  ring.push_back(-1-outputPtr->GetRequestedRegion().GetSize()[0] - outputPtr->GetRequestedRegion().GetIndex()[0]);
381  ring.push_back(0-outputPtr->GetRequestedRegion().GetSize()[0] - outputPtr->GetRequestedRegion().GetIndex()[0]);
382  ring.push_back(1-outputPtr->GetRequestedRegion().GetSize()[0] - outputPtr->GetRequestedRegion().GetIndex()[0]);
383  ring.push_back(1);
384  ring.push_back(1+outputPtr->GetRequestedRegion().GetSize()[0] + outputPtr->GetRequestedRegion().GetIndex()[0]);
385  ring.push_back(outputPtr->GetRequestedRegion().GetSize()[0] + outputPtr->GetRequestedRegion().GetIndex()[0]);
386  ring.push_back(-1+outputPtr->GetRequestedRegion().GetSize()[0] + outputPtr->GetRequestedRegion().GetIndex()[0]);
387  ring.push_back(-1);
388 
395 
396  AuxImagePointerType disparity_jump = AuxImageType::New();
397  disparity_jump->SetRegions(old_disparityPtr->GetRequestedRegion());
398  disparity_jump->Allocate();
399  disparity_jump->FillBuffer(0);
400 
401  AuxImagePointerType disparity_jump2 = AuxImageType::New();
402  disparity_jump2->SetRegions(old_disparityPtr->GetRequestedRegion());
403  disparity_jump2->Allocate();
404  disparity_jump2->FillBuffer(0);
405 
406  AuxImagePointerType aux = AuxImageType::New();
407  aux->SetRegions(outputPtr->GetRequestedRegion());
408  aux->Allocate();
409  aux->FillBuffer(0);
410 
412  itk::ImageRegionConstIterator<TImage> old_disparityIt(old_disparityPtr,old_disparityPtr->GetRequestedRegion());
413  itk::ImageRegionConstIterator<TMask> old_maskIt(old_maskPtr,old_maskPtr->GetRequestedRegion());
414  itk::ImageRegionConstIterator<TImage> canny_disparityIt(canny_disparity,canny_disparity->GetRequestedRegion());
415  itk::ImageRegionConstIterator<TImage> canny_edgesIt(canny_edges,canny_edges->GetRequestedRegion());
417 
418  IndexType index, index2, index_pos, index_pos_actual, index_pos_old, index_pos_new, index_pos0;
419 
421  itk::ImageRegionIterator<TImage> new_disparityIt(outputPtr,outputPtr->GetRequestedRegion());
422  itk::ImageRegionIterator<TMask> new_maskIt(outputmaskPtr,outputPtr->GetRequestedRegion());
423  itk::ImageRegionIterator<AuxImageType> disparity_jumpIt(disparity_jump,outputPtr->GetRequestedRegion());
424  itk::ImageRegionIterator<AuxImageType> disparity_jump2It(disparity_jump2,outputPtr->GetRequestedRegion());
425  itk::ImageRegionIterator<TImage> risk_edgesIt(outputriskedgesPtr,outputPtr->GetRequestedRegion());
426  itk::ImageRegionIterator<AuxImageType> auxIt(aux,outputPtr->GetRequestedRegion());
428 
429 
430  new_maskIt.GoToBegin();
431  new_disparityIt.GoToBegin();
432 
434  while (!new_maskIt.IsAtEnd() && !new_disparityIt.IsAtEnd())
435  {
436  old_maskIt.SetIndex(new_maskIt.GetIndex());
437  old_disparityIt.SetIndex(new_disparityIt.GetIndex());
438  new_maskIt.Set(old_maskIt.Get());
439  new_disparityIt.Set(old_disparityIt.Get());
440  ++old_disparityIt;
441  ++new_maskIt;
442  ++new_disparityIt;
443  ++old_maskIt;
444  }
446 
447  new_disparityIt.GoToBegin();
448  while (new_disparityIt.GetIndex()[1]<static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[1]) + outputPtr->GetRequestedRegion().GetIndex()[1])
449  {
450  index_pos=new_disparityIt.GetIndex();
451  if (new_disparityIt.GetIndex()[1] >= outputPtr->GetRequestedRegion().GetIndex()[1] &&
452  new_disparityIt.GetIndex()[1] < static_cast<int>(m_ImageSize[1]) - win)
453  {
454  old_maskIt.SetIndex(index_pos);
455  while (old_maskIt.Get() == 0 &&
456  new_disparityIt.GetIndex()[0]<static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[0]) + outputPtr->GetRequestedRegion().GetIndex()[0])
457  {
458  ++new_disparityIt;
459  old_maskIt.SetIndex(new_disparityIt.GetIndex());
460  }
461  index_pos = new_disparityIt.GetIndex();
462  disparity_jumpIt.SetIndex(index_pos);
463  disparity_jumpIt.Set(-1); // first disparity in the epipolar line
464  int k=0;
465  while (new_disparityIt.GetIndex()[0]<static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[0]) + outputPtr->GetRequestedRegion().GetIndex()[0] - win)
466  {
467  index_pos = new_disparityIt.GetIndex();
468  if (old_maskPtr->GetPixel(index_pos) == 0) // holes in the disparity map
469  {
470  if (k==0)
471  {
472  k++;
473  int i=1;
474  index[0]=index_pos[0]+i;
475  index[1]=index_pos[1];
476  old_maskIt.SetIndex(index);
477  new_disparityIt.SetIndex(index);
478  while(new_disparityIt.GetIndex()[0]<static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[0]) + outputPtr->GetRequestedRegion().GetIndex()[0] &&
479  old_maskIt.Get()==0)
480  {
481  i++;
482  index[0]=index_pos[0]+i;
483  new_disparityIt.SetIndex(index);
484  old_maskIt.SetIndex(index);
485  }
486  if (new_disparityIt.GetIndex()[0] == static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[0]) + outputPtr->GetRequestedRegion().GetIndex()[0] - 1)
487  {
488  disparity_jumpIt.SetIndex(index_pos);
489  disparity_jumpIt.Set(4);
490  }
491  else
492  {
493  index[0]=index_pos[0]-1;
494  index2[0]=index_pos[0]+i;
495  index2[1]=index_pos[1];
496  if (std::abs(old_disparityPtr->GetPixel(index) - old_disparityPtr->GetPixel(index2)) > m_Tolerance)
497  {
498  if (old_disparityPtr->GetPixel(index) < old_disparityPtr->GetPixel(index2))
499  {
500  index2[0] = index_pos[0] + i -1;
501  disparity_jumpIt.SetIndex(index2);
502  disparity_jumpIt.Set(3);
503  if (i>=win)
504  {
505  disparity_jumpIt.SetIndex(index_pos);
506  disparity_jumpIt.Set(4); // big holes
507  }
508  }
509  else
510  {
511  disparity_jumpIt.SetIndex(index_pos);
512  disparity_jumpIt.Set(4);
513  if (i>=win)
514  {
515  index[0]=index_pos[0] + i -1;
516  disparity_jumpIt.SetIndex(index);
517  disparity_jumpIt.Set(3); // big holes
518  }
519  }
520  }
521  }
522  }
523  }
524  else // Disparity map discontinuities
525  {
526  if (canny_disparity->GetPixel(index_pos) > m_DiscontinuityThreshold )
527  {
528  int pp=0;
529 
530  for(k=0; k<8; k++)
531  {
532  index[0]=index_pos[0]+ring[k];
533  index[1]=index_pos[1];
534  if(old_maskPtr->GetPixel(index)==0) pp++;
535  }
536  if(pp==0)
537  {
538  index[0]=index_pos[0]-1;
539  index[1]=index_pos[1];
540  index2[0]=index_pos[0]+1;
541  index2[1]=index_pos[1];
542  if (old_disparityPtr->GetPixel(index) < old_disparityPtr->GetPixel(index2))
543  {
544  disparity_jumpIt.SetIndex(index);
545  disparity_jumpIt.Set(1);
546  }
547  if (old_disparityPtr->GetPixel(index) > old_disparityPtr->GetPixel(index2))
548  {
549  disparity_jumpIt.SetIndex(index2);
550  disparity_jumpIt.Set(2);
551  }
552  }
553  }
554  k=0;
555  }
556  new_disparityIt.SetIndex(index_pos);
557  ++new_disparityIt;
558  }
559  }
560  index[0]=outputPtr->GetRequestedRegion().GetIndex()[0];
561  index[1]=index_pos[1]+1;
562  new_disparityIt.SetIndex(index);
563  }
564 
567  new_disparityIt.GoToBegin();
568 
569  while (new_disparityIt.GetIndex()[1]<static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[1]) + outputPtr->GetRequestedRegion().GetIndex()[1])
570  {
571  index_pos = new_disparityIt.GetIndex();
572  old_maskIt.SetIndex(index_pos);
573  while (old_maskIt.Get() == 0 &&
574  new_disparityIt.GetIndex()[0] < static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[0]) + outputPtr->GetRequestedRegion().GetIndex()[0] - 1)
575  {
576  ++new_disparityIt;
577  old_maskIt.SetIndex(new_disparityIt.GetIndex());
578  }
579  index_pos = new_disparityIt.GetIndex();
580  old_disparityIt.SetIndex(index_pos);
581 // double disp = old_disparityIt.Get();
582  while (new_disparityIt.GetIndex()[0]<static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[0]) + outputPtr->GetRequestedRegion().GetIndex()[0] - 1)
583  {
584  index_pos = new_disparityIt.GetIndex();
585  index = index_pos;
586  index[0] = index_pos[0]+1;
587  old_maskIt.SetIndex(index_pos);
588  if (old_maskIt.Get() != 0 && old_maskPtr->GetPixel(index) != 0)
589  {
590  if (std::abs(old_disparityPtr->GetPixel(index_pos) - old_disparityPtr->GetPixel(index)) > m_Tolerance)
591  {
592  if (old_disparityPtr->GetPixel(index) > old_disparityPtr->GetPixel(index_pos) &&
593  disparity_jump->GetPixel(index_pos) == 0)
594  {
595  disparity_jumpIt.SetIndex(index_pos);
596  disparity_jumpIt.Set(1);
597  }
598  if (old_disparityPtr->GetPixel(index) < old_disparityPtr->GetPixel(index_pos) &&
599  disparity_jump->GetPixel(index) == 0)
600  {
601  disparity_jumpIt.SetIndex(index);
602  disparity_jumpIt.Set(2);
603  }
604  }
605  }
606  new_disparityIt.SetIndex(index_pos);
607  ++new_disparityIt;
608  }
609  index[0]=outputPtr->GetRequestedRegion().GetIndex()[0];
610  index[1]=index_pos[1]+1;
611  new_disparityIt.SetIndex(index);
612  }
613 
618  new_disparityIt.GoToBegin();
619 
620  while (new_disparityIt.GetIndex()[1]<static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[1]) + outputPtr->GetRequestedRegion().GetIndex()[1])
621  {
622  index_pos = new_disparityIt.GetIndex();
623  ++new_disparityIt;
624  while (new_disparityIt.GetIndex()[0]<static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[0]) + outputPtr->GetRequestedRegion().GetIndex()[0] -1)
625  {
626  index_pos = new_disparityIt.GetIndex();
627  disparity_jumpIt.SetIndex(index_pos);
628  if (disparity_jumpIt.Get() == 1 || disparity_jumpIt.Get() == 2 )
629  {
630  for (int k=0; k<8; k++)
631  {
632  index=index_pos;
633  index[0]=index_pos[0]+ring[k];
634  disparity_jumpIt.SetIndex(index);
635  if ((disparity_jumpIt.Get() == 1 || disparity_jumpIt.Get() == 2) &&
636  disparity_jumpIt.Get() != disparity_jump->GetPixel(index_pos))
637  {
638  for (int i=-2*win; i<=2*win; i++)
639  {
640  int l=-2-win;
641  index2[0] = index_pos[0] + i;
642  index2[1] = index_pos[1] + l;
643  while (old_maskPtr->GetBufferedRegion().IsInside(index2) && old_maskPtr->GetPixel(index2) == 0)
644  {
645  l++;
646  index2[1] = index_pos[1] + l;
647  }
648  if (index2[0]<static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[0]) + outputPtr->GetRequestedRegion().GetIndex()[0] &&
649  index2[1]<static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[1]) + outputPtr->GetRequestedRegion().GetIndex()[1]) // add this condition to avoid seg fault
650  {
651  disparity_jump2It.SetIndex(index2);
652  disparity_jump2It.Set(7);
653  }
654  }
655  }
656  }
657  }
658  new_disparityIt.SetIndex(index_pos);
659  ++new_disparityIt;
660  }
661  index[0]=outputPtr->GetRequestedRegion().GetIndex()[0];
662  index[1]=index_pos[1]+1;
663  new_disparityIt.SetIndex(index);
664  }
665 
668  new_disparityIt.GoToBegin();
669 
670  while (new_disparityIt.GetIndex()[1]<static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[1]) + outputPtr->GetRequestedRegion().GetIndex()[1])
671  {
672  index_pos = new_disparityIt.GetIndex();
673  old_maskIt.SetIndex(index_pos);
674  while (old_maskIt.Get() == 0 &&
675  new_disparityIt.GetIndex()[0] < static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[0]) + outputPtr->GetRequestedRegion().GetIndex()[0] - 1)
676  {
677  ++new_disparityIt;
678  old_maskIt.SetIndex(new_disparityIt.GetIndex());
679  }
680  while (new_disparityIt.GetIndex()[0]<static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[0]) + outputPtr->GetRequestedRegion().GetIndex()[0] -1)
681  {
682  index_pos = new_disparityIt.GetIndex();
683  disparity_jumpIt.SetIndex(index_pos);
684  if (disparity_jumpIt.Get() == 1)
685  {
686  int i = 1;
687  index = index_pos;
688  index[0] = index_pos[0] + i;
689  disparity_jumpIt.SetIndex(index);
690  while (disparity_jumpIt.Get() == 1 )
691  {
692  disparity_jumpIt.Set(0);
693  i++;
694  index[0] = index_pos[0] + i;
695  disparity_jumpIt.SetIndex(index);
696  }
697  }
698  disparity_jumpIt.SetIndex(index_pos);
699  if (disparity_jumpIt.Get() == 2)
700  {
701  int i=-1;
702  index = index_pos;
703  index[0] = index_pos[0] + i;
704  disparity_jumpIt.SetIndex(index);
705  while (disparity_jumpIt.Get() == 2 )
706  {
707  disparity_jumpIt.Set(0);
708  i--;
709  index[0] = index_pos[0] + i;
710  disparity_jumpIt.SetIndex(index);
711  }
712  }
713  new_disparityIt.SetIndex(index_pos);
714  ++new_disparityIt;
715  }
716  index[0]=outputPtr->GetRequestedRegion().GetIndex()[0];
717  index[1]=index_pos[1]+1;
718  new_disparityIt.SetIndex(index);
719  }
720 
725  // Exploring the left-right epipolar direction
726  new_disparityIt.GoToBegin();
727  while (new_disparityIt.GetIndex()[1]<static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[1]) + outputPtr->GetRequestedRegion().GetIndex()[1])
728  {
729  index_pos = new_disparityIt.GetIndex();
730  while (new_disparityIt.GetIndex()[0]<static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[0]) + outputPtr->GetRequestedRegion().GetIndex()[0] -1)
731  {
732  index_pos = new_disparityIt.GetIndex();
733  disparity_jumpIt.SetIndex(index_pos);
734  double value_max = m_EdgeThreshold;
735  int index_max = -100; // Canny edges should be larger than m_EdgeThreshold
736  if (disparity_jumpIt.Get() == 1)
737  {
738  int l=1;
739  while (index_pos[0]+l<static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[0]) + outputPtr->GetRequestedRegion().GetIndex()[0] &&
740  l<=big_dist &&
741  index_pos[0]+l<static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[0]) + outputPtr->GetRequestedRegion().GetIndex()[0] &&
742  index_pos[1]<static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[1]) + outputPtr->GetRequestedRegion().GetIndex()[1])
743  {
744  index = index_pos;
745  index[0] = index_pos[0] + l;
746  if (canny_edges->GetPixel(index)>value_max)
747  {
748  value_max = canny_edges->GetPixel(index);
749  index_max = index_pos[0] + l;
750  }
751  l++;
752  }
753  }
754  if (disparity_jumpIt.Get() == 3)
755  {
756  int l=1;
757  while (index_pos[0]+l<static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[0]) + outputPtr->GetRequestedRegion().GetIndex()[0] &&
758  l<=big_dist &&
759  index_pos[0]+l<static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[0]) + outputPtr->GetRequestedRegion().GetIndex()[0] &&
760  index_pos[1]<static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[1]) + outputPtr->GetRequestedRegion().GetIndex()[1] )
761  {
762  index = index_pos;
763  index[0] = index_pos[0] + l;
764  if (canny_edges->GetPixel(index)>value_max)
765  {
766  value_max = canny_edges->GetPixel(index);
767  index_max = index_pos[0] + l;
768  }
769  l++;
770  }
771  }
772  if (disparity_jumpIt.Get() == 2)
773  {
774  int l=-1;
775  while (index_pos[0]+l>=outputPtr->GetRequestedRegion().GetIndex()[0] &&
776  l>=-big_dist &&
777  index_pos[0]+l<static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[0]) + outputPtr->GetRequestedRegion().GetIndex()[0] &&
778  index_pos[1]<static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[1]) + outputPtr->GetRequestedRegion().GetIndex()[1])
779  {
780  index = index_pos;
781  index[0] = index_pos[0] + l;
782  if (canny_edges->GetPixel(index)>value_max)
783  {
784  value_max = canny_edges->GetPixel(index);
785  index_max = index_pos[0] + l;
786  }
787  l--;
788  }
789  }
790  if (disparity_jumpIt.Get() == 4)
791  {
792  int l=-1;
793  while (index_pos[0]+l>=outputPtr->GetRequestedRegion().GetIndex()[0] &&
794  l>=-big_dist &&
795  index_pos[0]+l<static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[0]) + outputPtr->GetRequestedRegion().GetIndex()[0] &&
796  index_pos[1]<static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[1]) + outputPtr->GetRequestedRegion().GetIndex()[1])
797  {
798  index = index_pos;
799  index[0] = index_pos[0] + l;
800  if (canny_edges->GetPixel(index)>value_max)
801  {
802  value_max = canny_edges->GetPixel(index);
803  index_max = index_pos[0] + l;
804  }
805  l--;
806  }
807  }
808  if(index_max !=-100)
809  {
810  index = index_pos;
811  index[0] = index_max;
812  risk_edgesIt.SetIndex(index);
813  risk_edgesIt.Set(1); // flag= 1 for risk edges
814  }
815  new_disparityIt.SetIndex(index_pos);
816  ++new_disparityIt;
817  }
818  index[0]=outputPtr->GetRequestedRegion().GetIndex()[0];
819  index[1]=index_pos[1]+1;
820  new_disparityIt.SetIndex(index);
821  }
822 
825  new_disparityIt.GoToBegin();
826 
827  while (new_disparityIt.GetIndex()[1]<static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[1]) + outputPtr->GetRequestedRegion().GetIndex()[1])
828  {
829  index_pos = new_disparityIt.GetIndex();
830  while (new_disparityIt.GetIndex()[0]<static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[0]) + outputPtr->GetRequestedRegion().GetIndex()[0]-1)
831  {
832  index_pos = new_disparityIt.GetIndex();
833  risk_edgesIt.SetIndex(index_pos);
834  if (risk_edgesIt.Get() == 1)
835  {
836  int pp=0;
837  for (int k=0; k<8; k++)
838  {
839  index = index_pos;
840  index[0] = index_pos[0] + ring[k];
841  risk_edgesIt.SetIndex(index);
842  if(risk_edgesIt.Get() > 0) pp++;
843  }
844  risk_edgesIt.SetIndex(index_pos);
845  if (pp == 0) risk_edgesIt.Set(0); //remove isolate points
846  if (pp == 1) risk_edgesIt.Set(2);
847  if(pp==2)
848  {
849  int l=0;
850  pix.clear();
851  for(int k=0; k<8; k++)
852  {
853  index = index_pos;
854  index[0] = index_pos[0] + ring[k];
855  risk_edgesIt.SetIndex(index);
856  if(risk_edgesIt.Get() > 0)
857  {
858  pix.push_back(k);
859  l++;
860  }
861  }
862  dif = (int) std::abs(pix[0]-pix[1]);
863  risk_edgesIt.SetIndex(index_pos);
864  if (dif==1 || dif==7) risk_edgesIt.Set(2);
865  }
866  }
867  new_disparityIt.SetIndex(index_pos);
868  ++new_disparityIt;
869  }
870  index[0]=outputPtr->GetRequestedRegion().GetIndex()[0];
871  index[1]=index_pos[1]+1;
872  new_disparityIt.SetIndex(index);
873  }
874 
879  new_disparityIt.GoToBegin();
880 
881  while (new_disparityIt.GetIndex()[1]<static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[1]) + outputPtr->GetRequestedRegion().GetIndex()[1] -1)
882  {
883  index_pos = new_disparityIt.GetIndex();
884  ++new_disparityIt;
885  while (new_disparityIt.GetIndex()[0]<static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[0]) + outputPtr->GetRequestedRegion().GetIndex()[0] -1)
886  {
887  index_pos = new_disparityIt.GetIndex();
888  risk_edgesIt.SetIndex(index_pos);
889  if (risk_edgesIt.Get() == 2)
890  {
891  new_step = 1;
892  index_pos_old = index_pos;
893  while (new_step == 1)
894  {
895  new_step = 0;
896  for(int k=0; k<8; k++)
897  {//Ignore merging cases
898  index_pos_actual = index_pos_old;
899  index_pos_actual[0] = index_pos_old[0] +ring[k];
900  double m_max = 0;
901  // if the next pixel is the continuation of the border,we extend the risk edge //
902  // The extend the border, it has to be as prevalent as before //
903  canny_edgesIt.SetIndex(index_pos_actual);
904  if (canny_edgesIt.Get()>m_DiscontinuityHighThreshold &&
905  std::abs(canny_edgesIt.Get() - canny_edges->GetPixel(index_pos_old)) < m_MaxEdgeGap)
906  {
907  if (outputriskedgesPtr->GetPixel(index_pos_actual) ==0 && canny_edges->GetPixel(index_pos_actual) > m_max)
908  {
909  index_pos_new = index_pos_actual;
910  new_step = 1;
911  }
912  }
913  }
914  if (new_step ==1)
915  {
916  risk_edgesIt.SetIndex(index_pos_old);
917  risk_edgesIt.Set(1);
918  risk_edgesIt.SetIndex(index_pos_new);
919  risk_edgesIt.Set(2);
920  auxIt.SetIndex(index_pos_new);
921  auxIt.Set(1);
922  index_pos_old = index_pos_new;
923  //steps++;
924  }
925  }
926  }
927  new_disparityIt.SetIndex(index_pos);
928  ++new_disparityIt;
929  }
930  index[0]=outputPtr->GetRequestedRegion().GetIndex()[0];
931  index[1]=index_pos[1]+1;
932  new_disparityIt.SetIndex(index);
933  }
934 
940  int Count;
941  int big_win = win + 1;
942 // int half_big_win = (2*big_win +1)*(2*big_win +1) /2;
943  double Tol2 = m_Tolerance/2;
944 
945  new_disparityIt.GoToBegin();
946 
947  while (new_disparityIt.GetIndex()[1]<static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[1]) + outputPtr->GetRequestedRegion().GetIndex()[1])
948  {
949  index_pos = new_disparityIt.GetIndex();
950  if (index_pos[1]>=big_win + outputPtr->GetRequestedRegion().GetIndex()[1])
951  {
952  while (new_disparityIt.GetIndex()[0]<static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[0]) + outputPtr->GetRequestedRegion().GetIndex()[0] -1)
953  {
954  index_pos = new_disparityIt.GetIndex();
955  auxIt.SetIndex(index_pos);
956  if( auxIt.Get() !=0 )
957  {
958  double m_max = -10000000.;
959  double m_min = -m_max;
960  Count=0;
961  for(int j= -big_win; j<= big_win; j++)
962  {
963  for(int i= -big_win; i<= big_win; i++)
964  {
965  if (index_pos[0] + i >= old_disparityPtr->GetRequestedRegion().GetIndex()[0] &&
966  index_pos[0] + i < static_cast<int>(old_disparityPtr->GetRequestedRegion().GetSize()[0]) + old_disparityPtr->GetRequestedRegion().GetIndex()[0] &&
967  index_pos[1] + j >= old_disparityPtr->GetRequestedRegion().GetIndex()[1] &&
968  index_pos[1] + j < static_cast<int>(old_disparityPtr->GetRequestedRegion().GetSize()[1]) + old_disparityPtr->GetRequestedRegion().GetIndex()[1])
969  {
970  index_pos0[0] = index_pos[0] + i;
971  index_pos0[1] = index_pos[1] + j;
972  old_maskIt.SetIndex(index_pos0);
973  if (old_maskIt.Get() == 1)
974  {
975  if (old_disparityPtr->GetPixel(index_pos0) > m_max) m_max = old_disparityPtr->GetPixel(index_pos0);
976  if (old_disparityPtr->GetPixel(index_pos0) < m_min) m_min = old_disparityPtr->GetPixel(index_pos0);
977  Count++;
978  }
979  new_disparityIt.SetIndex(index_pos);
980  }
981  }
982  }
984  risk_edgesIt.SetIndex(index_pos);
985  if ((m_max-m_min)<Tol2 && Count>0) risk_edgesIt.Set(0);
986  else
987  {
988  for(int j= -win; j<= win; j++)
989  {
990  for(int i= -win; i<= win; i++)
991  {
992  if (index_pos[0] + i >= outputPtr->GetRequestedRegion().GetIndex()[0] &&
993  index_pos[0] + i < static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[0]) + outputPtr->GetRequestedRegion().GetIndex()[0] &&
994  index_pos[1] + j >= outputPtr->GetRequestedRegion().GetIndex()[1] &&
995  index_pos[1] + j < static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[1]) + outputPtr->GetRequestedRegion().GetIndex()[1])
996  {
997  index_pos0[0] = index_pos[0] + i;
998  index_pos0[1] = index_pos[1] + j;
999  new_disparityIt.SetIndex(index_pos0);
1000  new_maskIt.SetIndex(index_pos0);
1001  new_disparityIt.Set(0);
1002  new_maskIt.Set(0);
1003  }
1004  }
1005  }
1006  }
1007  }
1008  new_disparityIt.SetIndex(index_pos);
1009  ++new_disparityIt;
1010  index_pos = new_disparityIt.GetIndex();
1011  }
1012  }
1013  index[0]=outputPtr->GetRequestedRegion().GetIndex()[0];
1014  index[1]=index_pos[1]+1;
1015  new_disparityIt.SetIndex(index);
1016  }
1017 
1020  new_disparityIt.GoToBegin();
1021 
1022  while (new_disparityIt.GetIndex()[1]<static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[1]) + outputPtr->GetRequestedRegion().GetIndex()[1]- 1)
1023  {
1024  ++new_disparityIt;
1025  while (new_disparityIt.GetIndex()[0]<static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[0]) + outputPtr->GetRequestedRegion().GetIndex()[0]-1)
1026  {
1027  index_pos = new_disparityIt.GetIndex();
1028  risk_edgesIt.SetIndex(index_pos);
1029  if (risk_edgesIt.Get() == 2)
1030  {
1031  int pp=0;
1032  for(int k=0; k<8; k++)
1033  {
1034  index[0]=index_pos[0]+ring[k];
1035  index[1]=index_pos[1];
1036  risk_edgesIt.SetIndex(index);
1037  if (risk_edgesIt.Get() == 2)
1038  {// 2pix edge
1039  risk_edgesIt.Set(0);
1040  risk_edgesIt.SetIndex(index_pos);
1041  risk_edgesIt.Set(0);
1042  }
1043  risk_edgesIt.SetIndex(index);
1044  if (risk_edgesIt.Get() == 0) pp++;
1045  }
1046  risk_edgesIt.SetIndex(index_pos);
1047  if (pp == 8) risk_edgesIt.Set(0); // 1pix edge
1048  }
1049  ++new_disparityIt;
1050  ++disparity_jumpIt;
1051  }
1052  index[0]=outputPtr->GetRequestedRegion().GetIndex()[0];
1053  index[1]=index_pos[1]+1;
1054  new_disparityIt.SetIndex(index);
1055  }
1056 
1059  new_disparityIt.GoToBegin();
1060 
1061  while (new_disparityIt.GetIndex()[1]<static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[1]) + outputPtr->GetRequestedRegion().GetIndex()[1] - 1)
1062  {
1063  index_pos = new_disparityIt.GetIndex();
1064  old_maskIt.SetIndex(index_pos);
1065  while (old_maskIt.Get() == 0 &&
1066  new_disparityIt.GetIndex()[0] < static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[0]) + outputPtr->GetRequestedRegion().GetIndex()[0]- 1)
1067  {
1068  ++new_disparityIt;
1069  old_maskIt.SetIndex(new_disparityIt.GetIndex());
1070  }
1071  index_pos = new_disparityIt.GetIndex();
1072  while (new_disparityIt.GetIndex()[0]<static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[0]) + outputPtr->GetRequestedRegion().GetIndex()[0] - 1)
1073  {
1074  index_pos = new_disparityIt.GetIndex();
1075  int pp=0;
1076  int pp2=0;
1077  if (outputriskedgesPtr->GetPixel(index_pos) != 0)
1078  {// left
1079  int l=-patch_side;
1080  index[0]=index_pos[0]+l;
1081  index[1]=index_pos[1];
1082  while ((new_disparityIt.GetIndex()[0] + l) >= outputPtr->GetRequestedRegion().GetIndex()[0] &&
1083  l<=0 &&
1084  disparity_jump->GetPixel(index) !=1 )
1085  {
1086  l++;
1087  index[0]=index_pos[0]+l;
1088  }
1089  index[0]=index_pos[0]+l;
1090  if (disparity_jump->GetPixel(index) == 1)
1091  {
1092  pp++;
1093  for (int ii=l+1; ii<=0; ii++)
1094  {
1095  index[0]=index_pos[0]+ii;
1096  new_disparityIt.SetIndex(index);
1097  new_disparityIt.Set(0);
1098  new_maskIt.SetIndex(index);
1099  new_maskIt.Set(0);
1100  }
1101  int i=1;
1102  index[0]=index_pos[0]+i;
1103  while (disparity_jump->GetPixel(index) !=1 && i<=win)
1104  {
1105  index[0]=index_pos[0]+i;
1106  new_disparityIt.SetIndex(index);
1107  new_disparityIt.Set(0);
1108  new_maskIt.SetIndex(index);
1109  new_maskIt.Set(0);
1110  i++;
1111  index[0]=index_pos[0]+i;
1112  }
1113  pp2=0;
1114  index[0]=index_pos[0]+i;
1115  index[1]=index_pos[1];
1116  if(disparity_jump->GetPixel(index) == 1)
1117  {//2a adhesion
1118  for(int j=1; j<=win; j++)
1119  {
1120  index2[0]=index_pos[0]+i+j;
1121  index2[1]=index_pos[1];
1122  risk_edgesIt.SetIndex(index2);
1123  if (risk_edgesIt.Get() != 0) pp2++;
1124  }
1125  index[0]=index_pos[0]+i;
1126  disparity_jumpIt.SetIndex(index);
1127  if (pp2==0) disparity_jumpIt.Set(0);
1128  }
1129  index[0]=index_pos[0]+i+1;
1130  disparity_jumpIt.SetIndex(index);
1131  if(disparity_jumpIt.Get() == 1)
1132  {
1133  for(int j=1; j<=win; j++)
1134  {
1135  index2[0]=index_pos[0]+i+1+j;
1136  index2[1]=index_pos[1];
1137  risk_edgesIt.SetIndex(index2);
1138  if (risk_edgesIt.Get() != 0) pp2++;
1139  }
1140  index[0]=index_pos[0]+i+1;
1141  disparity_jumpIt.SetIndex(index);
1142  if (pp2==0) disparity_jumpIt.Set(0);
1143  }
1144  }
1145  l=-big_dist;
1146  index[0]=index_pos[0]+l;
1147  index[1]=index_pos[1];
1148  while ((new_disparityIt.GetIndex()[0] + l) >= outputPtr->GetRequestedRegion().GetIndex()[0] &&
1149  l<=0 &&
1150  disparity_jump->GetPixel(index) != 3)
1151  {
1152  l++;
1153  index[0]=index_pos[0]+l;
1154  }
1155  index[0]=index_pos[0]+l;
1156  if(disparity_jump->GetPixel(index) == 3)
1157  {
1158  pp++;
1159  for(int ii=l+1; ii<=0; ii++)
1160  {
1161  index[0]=index_pos[0]+ii;
1162  new_disparityIt.SetIndex(index);
1163  new_disparityIt.Set(0);
1164  new_maskIt.SetIndex(index);
1165  new_maskIt.Set(0);
1166  }
1167  int i=1;
1168  index[0]=index_pos[0]+i;
1169  while (disparity_jump->GetPixel(index) !=1 && i<=win)
1170  {
1171  index[0]=index_pos[0]+i;
1172  new_disparityIt.SetIndex(index);
1173  new_disparityIt.Set(0);
1174  new_maskIt.SetIndex(index);
1175  new_maskIt.Set(0);
1176  i++;
1177  index[0]=index_pos[0]+i;
1178  }
1179  pp2=0;
1180  index[0]=index_pos[0]+i;
1181  if (disparity_jump->GetPixel(index)==1)
1182  {//2a adhesion
1183  for (int j=1; j<=win; j++)
1184  {
1185  index2[0]=index_pos[0]+i+j;
1186  index2[1]=index_pos[1];
1187  if(outputriskedgesPtr->GetPixel(index2) != 0) pp2++;
1188  }
1189  index[0]=index_pos[0]+i;
1190  disparity_jumpIt.SetIndex(index);
1191  if (pp2 == 0) disparity_jumpIt.Set(0);
1192  }
1193  index[0]=index_pos[0]+i+1;
1194  if (disparity_jump->GetPixel(index)==1)
1195  {
1196  for (int j=1; j<=win; j++)
1197  {
1198  index2[0]=index_pos[0]+i+1+j;
1199  index2[1]=index_pos[1];
1200  if(outputriskedgesPtr->GetPixel(index2) != 0) pp2++;
1201  }
1202  index[0]=index_pos[0]+i+1;
1203  disparity_jumpIt.SetIndex(index);
1204  if (pp2 == 0) disparity_jumpIt.Set(0);
1205  }
1206  }
1207  // right
1208  l=patch_side;
1209  index[0]=index_pos[0]+l;
1210  index[1]=index_pos[1];
1211  while ((new_disparityIt.GetIndex()[0] + l) < static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[0]) + outputPtr->GetRequestedRegion().GetIndex()[0]- 1 &&
1212  l>=0 &&
1213  disparity_jump->GetPixel(index) != 2)
1214  {
1215  l--;
1216  index[0]=index_pos[0]+l;
1217  }
1218  index[0]=index_pos[0]+l;
1219  if(disparity_jump->GetPixel(index)==2)
1220  {
1221  pp++;
1222  for (int ii=l-1; ii>=0; ii--)
1223  {
1224  index[0]=index_pos[0]+ii;
1225  new_disparityIt.SetIndex(index);
1226  new_disparityIt.Set(0);
1227  new_maskIt.SetIndex(index);
1228  new_maskIt.Set(0);
1229  }
1230  int i=-1;
1231  index[0]=index_pos[0]+i;
1232  while (disparity_jump->GetPixel(index) != 2 && i>=-win)
1233  {
1234  index[0]=index_pos[0]+i;
1235  new_disparityIt.SetIndex(index);
1236  new_disparityIt.Set(0);
1237  new_maskIt.SetIndex(index);
1238  new_maskIt.Set(0);
1239  i--;
1240  index[0]=index_pos[0]+i;
1241  }
1242  pp2 = 0;
1243  index[0]=index_pos[0]+i;
1244  if (disparity_jump->GetPixel(index) == 2)
1245  {//2a adhesion
1246  for (int j=-1; j>=-win; j--)
1247  {
1248  index2[0]=index_pos[0]+i+j;
1249  index2[1]=index_pos[1];
1250  if (outputriskedgesPtr->GetPixel(index2) !=0 ) pp2++;
1251  }
1252  index[0]=index_pos[0]+i;
1253  disparity_jumpIt.SetIndex(index);
1254  if (pp2==0) disparity_jumpIt.Set(0);
1255  }
1256  index[0]=index_pos[0]+i-1;
1257  if (disparity_jump->GetPixel(index) == 2)
1258  {
1259  for (int j=-1; j>=-win; j--)
1260  {
1261  index2[0]=index_pos[0]+i-1+j;
1262  index2[1]=index_pos[1];
1263  if (outputriskedgesPtr->GetPixel(index2) !=0 ) pp2++;
1264  }
1265  index[0]=index_pos[0]+i-1;
1266  disparity_jumpIt.SetIndex(index);
1267  if (pp2==0) disparity_jumpIt.Set(0);
1268  }
1269  }
1270  l=big_dist;
1271  index[0]=index_pos[0]+l;
1272  index[1]=index_pos[1];
1273  while ((new_disparityIt.GetIndex()[0] + l) < static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[0]) + outputPtr->GetRequestedRegion().GetIndex()[0]- 1 &&
1274  l>=0 &&
1275  disparity_jump->GetPixel(index) != 4)
1276  {
1277  l--;
1278  index[0]=index_pos[0]+l;
1279  }
1280  index[0]=index_pos[0]+l;
1281  if (disparity_jump->GetPixel(index) == 4)
1282  {
1283  pp++;
1284  for (int ii=l-1; ii>=0; ii--)
1285  {
1286  index[0]=index_pos[0]+ii;
1287  new_disparityIt.SetIndex(index);
1288  new_disparityIt.Set(0);
1289  new_maskIt.SetIndex(index);
1290  new_maskIt.Set(0);
1291  }
1292  int i=-1;
1293  index[0]=index_pos[0]+i;
1294  while (disparity_jump->GetPixel(index) != 2 && i>=-win)
1295  {
1296  index[0]=index_pos[0]+i;
1297  new_disparityIt.SetIndex(index);
1298  new_disparityIt.Set(0);
1299  new_maskIt.SetIndex(index);
1300  new_maskIt.Set(0);
1301  i--;
1302  index[0]=index_pos[0]+i;
1303  }
1304  pp2=0;
1305  index[0]=index_pos[0]+i;
1306  if (disparity_jump->GetPixel(index) == 2)
1307  {//2a adhesion
1308  for (int j=-1; j>=-win; j--)
1309  {
1310  index2[0]=index_pos[0]+i+j;
1311  index2[1]=index_pos[1];
1312  if (outputriskedgesPtr->GetPixel(index2) !=0 ) pp2++;
1313  }
1314  index[0]=index_pos[0]+i;
1315  disparity_jumpIt.SetIndex(index);
1316  if (pp2==0) disparity_jumpIt.Set(0);
1317  }
1318  index[0]=index_pos[0]+i-1;
1319  if (disparity_jump->GetPixel(index) == 2)
1320  {
1321  for (int j=-1; j>=-win; j--)
1322  {
1323  index2[0]=index_pos[0]+i-1+j;
1324  index2[1]=index_pos[1];
1325  if (outputriskedgesPtr->GetPixel(index2) !=0 ) pp2++;
1326  }
1327  index[0]=index_pos[0]+i-1;
1328  disparity_jumpIt.SetIndex(index);
1329  if (pp2==0) disparity_jumpIt.Set(0);
1330  }
1331  }
1332  // if(pp==0) /// remove around the risk_edge if no disparity jump have been found
1333  // unique difference between new_adhesion and new_adhesion_2
1334  // the version 2 commented the previous line
1335  for (int i=-win+1; i<=win-1; i++)
1336  {
1337  for (int k=-win+1; k<=win-1; k++)
1338  {
1339  index2[0]=index_pos[0]+i;
1340  index2[1]=index_pos[1]+k;
1341  if (index2[0]>=outputPtr->GetRequestedRegion().GetIndex()[0] &&
1342  index2[1]>=outputPtr->GetRequestedRegion().GetIndex()[1] &&
1343  index2[0]<static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[0]) + outputPtr->GetRequestedRegion().GetIndex()[0] &&
1344  index2[1]<static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[1]) + outputPtr->GetRequestedRegion().GetIndex()[1])
1345  {
1346  new_disparityIt.SetIndex(index2);
1347  new_maskIt.SetIndex(index2);
1348  new_disparityIt.Set(0);
1349  new_maskIt.Set(0);
1350  }
1351  }
1352  }
1353  }
1354  new_disparityIt.SetIndex(index_pos);
1355  ++new_disparityIt;
1356  }
1357  index[0]=outputPtr->GetRequestedRegion().GetIndex()[0];
1358  index[1]=index_pos[1]+1;
1359  new_disparityIt.SetIndex(index);
1360  }
1361 
1364  new_disparityIt.GoToBegin();
1365 
1366  while (new_disparityIt.GetIndex()[1]<static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[1]) + outputPtr->GetRequestedRegion().GetIndex()[1])
1367  {
1368  index_pos = new_disparityIt.GetIndex();
1369  old_maskIt.SetIndex(index_pos);
1370  while (old_maskIt.Get() == 0 &&
1371  new_disparityIt.GetIndex()[0] < static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[0]) + outputPtr->GetRequestedRegion().GetIndex()[0] - 1)
1372  {
1373  ++new_disparityIt;
1374  old_maskIt.SetIndex(new_disparityIt.GetIndex());
1375  }
1376  while (new_disparityIt.GetIndex()[0]<static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[0]) + outputPtr->GetRequestedRegion().GetIndex()[0] - 1)
1377  {
1378  index_pos = new_disparityIt.GetIndex();
1379  index[0]=index_pos[0]+1;
1380  index[1]=index_pos[1];
1381  new_maskIt.SetIndex(index);
1382  risk_edgesIt.SetIndex(index);
1383  if ((disparity_jump->GetPixel(index_pos)==1 || disparity_jump->GetPixel(index_pos)==3) &&
1384  new_maskIt.Get() !=0 &&
1385  risk_edgesIt.Get() ==0 )
1386  {
1387  int i=1;
1388  index[0]=index_pos[0]+i;
1389  disparity_jumpIt.SetIndex(index);
1390  while (i<=patch_side_small &&
1391  disparity_jumpIt.GetIndex()[0]<static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[0]) + outputPtr->GetRequestedRegion().GetIndex()[0] - 1 &&
1392  disparity_jumpIt.Get()==0)
1393  {
1394  new_disparityIt.SetIndex(index);
1395  new_maskIt.SetIndex(index);
1396  new_disparityIt.Set(0);
1397  new_maskIt.Set(0);
1398  i++;
1399  index[0]=index_pos[0]+i;
1400  disparity_jumpIt.SetIndex(index);
1401  }
1402  }
1403  index[0]=index_pos[0]-1;
1404  index[1]=index_pos[1];
1405  new_maskIt.SetIndex(index);
1406  risk_edgesIt.SetIndex(index);
1407  if ((disparity_jump->GetPixel(index_pos)==2 || disparity_jump->GetPixel(index_pos)==4) &&
1408  new_maskIt.Get() !=0 &&
1409  risk_edgesIt.Get() ==0 )
1410  {
1411  int i=-1;
1412  index[0]=index_pos[0]+i;
1413  disparity_jumpIt.SetIndex(index);
1414  while (i>=-patch_side_small &&
1415  disparity_jumpIt.GetIndex()[0]<static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[0]) + outputPtr->GetRequestedRegion().GetIndex()[0] - 1 &&
1416  disparity_jumpIt.Get()==0 )
1417  {
1418  new_disparityIt.SetIndex(index);
1419  new_maskIt.SetIndex(index);
1420  new_disparityIt.Set(0);
1421  new_maskIt.Set(0);
1422  i--;
1423  index[0]=index_pos[0]+i;
1424  disparity_jumpIt.SetIndex(index);
1425  }
1426  }
1427  new_disparityIt.SetIndex(index_pos);
1428  ++new_disparityIt;
1429  }
1430  index[0]=outputPtr->GetRequestedRegion().GetIndex()[0];
1431  index[1]=index_pos[1]+1;
1432  new_disparityIt.SetIndex(index);
1433  }
1434 
1445  new_disparityIt.GoToBegin();
1446 
1447  while (new_disparityIt.GetIndex()[0]<static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[0]) + outputPtr->GetRequestedRegion().GetIndex()[0] - 1)
1448  {
1449  index2 = new_disparityIt.GetIndex();
1450  index=index2;
1451  old_maskIt.SetIndex(index2);
1452  while (old_maskIt.Get() == 0 &&
1453  new_disparityIt.GetIndex()[1] < static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[1]) + outputPtr->GetRequestedRegion().GetIndex()[1] - 1)
1454  {
1455  index[1]=index[1]+1;
1456  old_maskIt.SetIndex(index);
1457  new_disparityIt.SetIndex(index);
1458  }
1459  double disp=old_disparityPtr->GetPixel(index);
1460  int k=0;
1461  while (new_disparityIt.GetIndex()[1]<static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[1]) + outputPtr->GetRequestedRegion().GetIndex()[1] -1)
1462  {
1463  index_pos = new_disparityIt.GetIndex();
1464  old_maskIt.SetIndex(index_pos);
1465  if (old_maskIt.Get() == 0) k++;
1466  else
1467  {
1468  if (std::abs(old_disparityPtr->GetPixel(index_pos)-disp)>m_Tolerance && k<=win)
1469  {//only small holes
1470  disparity_jump2It.SetIndex(index_pos);
1471  if (old_disparityPtr->GetPixel(index_pos)>disp) disparity_jump2It.Set(5);
1472  index[0]=index_pos[0]-1;
1473  index[1]=index_pos[1];
1474  disparity_jump2It.SetIndex(index);
1475  if (old_disparityPtr->GetPixel(index_pos)<disp) disparity_jump2It.Set(6);
1476  }
1477  k=0;
1478  disp=old_disparityPtr->GetPixel(index_pos);
1479  }
1480  index[0]=index_pos[0];
1481  index[1]=index_pos[1]+1;
1482  new_disparityIt.SetIndex(index);
1483  }
1484  new_disparityIt.SetIndex(index2);
1485  ++new_disparityIt;
1486  }
1487 
1490  new_disparityIt.GoToBegin();
1491 
1492  while (new_disparityIt.GetIndex()[0]<static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[0]) + outputPtr->GetRequestedRegion().GetIndex()[0] -1)
1493  {
1494  int k=0;
1495  index2 = new_disparityIt.GetIndex();
1496  index=index2;
1497  while (new_disparityIt.GetIndex()[1]<static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[1]) + outputPtr->GetRequestedRegion().GetIndex()[1] - 1)
1498  {
1499  index_pos = new_disparityIt.GetIndex();
1500  if (disparity_jump2->GetPixel(index_pos) == 7)
1501  {
1502  double disp=old_disparityPtr->GetPixel(index_pos);
1503  for (int i=0; i<=big_dist; i++)
1504  {
1505  if (index_pos[1]+i < static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[1]) + outputPtr->GetRequestedRegion().GetIndex()[1])
1506  {
1507  index_pos0[0]=index_pos[0];
1508  index_pos0[1]=index_pos[1]+i;
1509  if (old_maskPtr->GetPixel(index_pos0)==0) k++;
1510  else
1511  {
1512  if (std::abs(old_disparityPtr->GetPixel(index_pos0)-disp)>m_Tolerance/2 && k<=win)
1513  {//only small holes
1514  disparity_jump2It.SetIndex(index_pos0);
1515  if (old_disparityPtr->GetPixel(index_pos0)>disp) disparity_jump2It.Set(8);
1516  index[0]=index_pos0[0]-1;
1517  index[1]=index_pos0[1];
1518  disparity_jump2It.SetIndex(index);
1519  if (old_disparityPtr->GetPixel(index_pos0)<disp) disparity_jump2It.Set(9);
1520  }
1521  k=0;
1522  disp=old_disparityPtr->GetPixel(index_pos0);
1523  }
1524  }
1525  }
1526  }
1527  index[0]=index_pos[0];
1528  index[1]=index_pos[1]+1;
1529  new_disparityIt.SetIndex(index);
1530  }
1531  new_disparityIt.SetIndex(index2);
1532  ++new_disparityIt;
1533  }
1534 
1537  new_disparityIt.GoToBegin();
1538 
1539  while (new_disparityIt.GetIndex()[1]<static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[1]) + outputPtr->GetRequestedRegion().GetIndex()[1]-1)
1540  {
1541  index_pos = new_disparityIt.GetIndex();
1542  old_maskIt.SetIndex(index_pos);
1543  while (old_maskIt.Get() == 0 &&
1544  new_disparityIt.GetIndex()[0] < static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[0]) + outputPtr->GetRequestedRegion().GetIndex()[0] - 1)
1545  {
1546  ++new_disparityIt;
1547  old_maskIt.SetIndex(new_disparityIt.GetIndex());
1548  }
1549  index_pos = new_disparityIt.GetIndex();
1550  for (int l=patch_side; l>0; l--)
1551  {
1552  index[0]=index_pos[0]+l;
1553  index[1]=index_pos[1];
1554  if (disparity_jump->GetPixel(index) != 0 || disparity_jump2->GetPixel(index) != 0 || outputriskedgesPtr->GetPixel(index) != 0)
1555  {
1556  for (int i=-win; i<=win; i++)
1557  {
1558  for (int k=-win; k<=win; k++)
1559  {
1560  index2[0]=index_pos[0]+l+i;
1561  index2[1]=index_pos[1]+k;
1562  if (index2[0]>=outputPtr->GetRequestedRegion().GetIndex()[0] &&
1563  index2[1]>=outputPtr->GetRequestedRegion().GetIndex()[1] &&
1564  index2[0]<static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[0]) + outputPtr->GetRequestedRegion().GetIndex()[0] &&
1565  index2[1]<static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[1]) + outputPtr->GetRequestedRegion().GetIndex()[1])
1566  {
1567  new_disparityIt.SetIndex(index2);
1568  new_maskIt.SetIndex(index2);
1569  new_disparityIt.Set(0);
1570  new_maskIt.Set(0);
1571  }
1572  }
1573  }
1574  }
1575  }
1576  index[0]=outputPtr->GetRequestedRegion().GetIndex()[0];
1577  index[1]=index_pos[1]+1;
1578  new_disparityIt.SetIndex(index);
1579  }
1580 
1583  new_disparityIt.GoToBegin();
1584  while (new_disparityIt.GetIndex()[0]<static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[0]) + outputPtr->GetRequestedRegion().GetIndex()[0] -1)
1585  {
1586  index2 = new_disparityIt.GetIndex();
1587  while (new_disparityIt.GetIndex()[1]<static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[1]) + outputPtr->GetRequestedRegion().GetIndex()[1] - 1)
1588  {
1589  index_pos = new_disparityIt.GetIndex();
1590  if (outputriskedgesPtr->GetPixel(index_pos) != 0)
1591  {
1592  int l = 0 - std::min(big_dist,static_cast<int>(index_pos[1])); //out of bound checking
1593  index[0] = index_pos[0];
1594  index[1] = index_pos[1] + l;
1595 
1596  while(l<=0 && disparity_jump2->GetPixel(index) != 5)
1597  {
1598  l++;
1599  index[1]=index_pos[1]+l;
1600  }
1601 
1602 
1603  index[1] = index_pos[1] + l;
1604  disparity_jump2It.SetIndex(index);
1605  if (disparity_jump2It.Get() == 5 && l != 0) disparity_jump2It.Set(0);
1606  for (int i = l; i <= 0; i++)
1607  {
1608  index[1] = index_pos[1] + i;
1609  new_disparityIt.SetIndex(index);
1610  new_maskIt.SetIndex(index);
1611  new_disparityIt.Set(0);
1612  new_maskIt.Set(0);
1613  }
1614 
1615  int maxSize=static_cast<int>(disparity_jump2->GetRequestedRegion().GetSize()[1]);
1616  l = std::min(static_cast<int>((maxSize-1)- index_pos[1]),big_dist); //out of bound checking
1617  index[0] = index_pos[0];
1618  index[1] = index_pos[1] + l;
1619  while (l >= 0 && disparity_jump2->GetPixel(index) != 6)
1620  {
1621  l--;
1622  index[1] = index_pos[1] + l;
1623  }
1624  index[1] = index_pos[1] + l;
1625  disparity_jump2It.SetIndex(index);
1626  if (disparity_jump2It.Get() == 6 && l != 0) disparity_jump2It.Set(0);
1627  for (int i = l; i >= 0; i--)
1628  {
1629  index[1] = index_pos[1] + i;
1630  new_disparityIt.SetIndex(index);
1631  new_maskIt.SetIndex(index);
1632  new_disparityIt.Set(0);
1633  new_maskIt.Set(0);
1634  }
1635  l = 0 - std::min(big_dist,static_cast<int>(index_pos[1]));
1636 
1637  index[0] = index_pos[0];
1638  index[1] = index_pos[1]+l;
1639 
1640  while (l <= 0 && disparity_jump2->GetPixel(index) != 8)
1641  {
1642  l++;
1643  index[1] = index_pos[1] + l;
1644  }
1645  index[1] = index_pos[1] + l;
1646  disparity_jump2It.SetIndex(index);
1647  if (disparity_jump2It.Get() == 8 && l != 0) disparity_jump2It.Set(0);
1648  for (int i = l; i <= 0; i++)
1649  {
1650  index[1] = index_pos[1] + i;
1651  new_disparityIt.SetIndex(index);
1652  new_maskIt.SetIndex(index);
1653  new_disparityIt.Set(0);
1654  new_maskIt.Set(0);
1655  }
1656 
1657  l = std::min(static_cast<int>((maxSize-1)- index_pos[1]),big_dist);
1658 
1659  index[0] = index_pos[0];
1660  index[1] = index_pos[1] + l;
1661  while (l >= 0 && disparity_jump2->GetPixel(index) != 9)
1662  {
1663  l--;
1664  index[1] = index_pos[1] + l;
1665  }
1666  index[1] = index_pos[1] + l;
1667  disparity_jump2It.SetIndex(index);
1668  if (disparity_jump2It.Get() == 9 && l != 0) disparity_jump2It.Set(0);
1669  for (int i = l; i >= 0; i--)
1670  {
1671  index[1] = index_pos[1] + i;
1672  new_disparityIt.SetIndex(index);
1673  new_maskIt.SetIndex(index);
1674  new_disparityIt.Set(0);
1675  new_maskIt.Set(0);
1676  }
1677  }
1678  index[0]=index_pos[0];
1679  index[1]=index_pos[1]+1;
1680  new_disparityIt.SetIndex(index);
1681  }
1682  new_disparityIt.SetIndex(index2);
1683  ++new_disparityIt;
1684  }
1685 
1688  new_disparityIt.GoToBegin();
1689  while (new_disparityIt.GetIndex()[0]<static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[0]) + outputPtr->GetRequestedRegion().GetIndex()[0] -1)
1690  {
1691  index2 = new_disparityIt.GetIndex();
1692  while (new_disparityIt.GetIndex()[1]<static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[1]) + outputPtr->GetRequestedRegion().GetIndex()[1] - 1)
1693  {
1694  index_pos = new_disparityIt.GetIndex();
1695  if (disparity_jump2->GetPixel(index_pos) == 5 || disparity_jump2->GetPixel(index_pos) == 8)
1696  {
1697  int l=0;
1698  index[0]=index_pos[0];
1699  index[1]=index_pos[1]+l;
1700  while (l<=patch_side_small &&
1701  index_pos[1]+l<static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[1]) + outputPtr->GetRequestedRegion().GetIndex()[1] -1 &&
1702  disparity_jump2->GetPixel(index) != 6)
1703  {
1704  new_disparityIt.SetIndex(index);
1705  new_maskIt.SetIndex(index);
1706  new_disparityIt.Set(0);
1707  new_maskIt.Set(0);
1708  l++;
1709  index[1]=index_pos[1]+l;
1710  }
1711  }
1712  if (disparity_jump2->GetPixel(index_pos) == 6 || disparity_jump2->GetPixel(index_pos) == 9)
1713  {
1714  int l=0;
1715  index[0]=index_pos[0];
1716  index[1]=index_pos[1]+l;
1717  while (l>=-patch_side_small &&
1718  index_pos[1]+l>=outputPtr->GetRequestedRegion().GetIndex()[1] &&
1719  disparity_jump2->GetPixel(index) != 5)
1720  {
1721  new_disparityIt.SetIndex(index);
1722  new_maskIt.SetIndex(index);
1723  new_disparityIt.Set(0);
1724  new_maskIt.Set(0);
1725  l--;
1726  index[1]=index_pos[1]+l;
1727  }
1728  }
1729  index[0]=index_pos[0];
1730  index[1]=index_pos[1]+1;
1731  new_disparityIt.SetIndex(index);
1732  }
1733  new_disparityIt.SetIndex(index2);
1734  ++new_disparityIt;
1735  }
1736 
1741  int nb_disp =3;
1742  new_disparityIt.GoToBegin();
1743 
1744  while (new_disparityIt.GetIndex()[1]<static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[1]) + outputPtr->GetRequestedRegion().GetIndex()[1] -1)
1745  {
1746  index_pos = new_disparityIt.GetIndex();
1747  while (new_disparityIt.GetIndex()[0] <static_cast<int>(outputPtr->GetRequestedRegion().GetSize()[0]) + outputPtr->GetRequestedRegion().GetIndex()[0] - 1)
1748  {
1749  index_pos = new_disparityIt.GetIndex();
1750  new_maskIt.SetIndex(index_pos);
1751  if (new_maskIt.Get() != 0 && subpixelmaskPtr->GetPixel(index_pos) != 0)
1752  {
1753  nb_disp = 0;
1754  for (int j= -win+1; j<= win-1; j++)
1755  {
1756  for (int i= -win+1; i<= win-1; i++)
1757  {
1758  index_pos0[0]=index_pos[0]+i;
1759  index_pos0[1]=index_pos[1]+j;
1760  new_maskIt.SetIndex(index_pos0);
1761  if(new_maskIt.Get() != 0 && subpixelmaskPtr->GetPixel(index_pos0) != 0) nb_disp++;
1762  }
1763  }
1764  }
1765  if(nb_disp<=2)
1766  {
1767  new_maskIt.SetIndex(index_pos);
1768  new_disparityIt.SetIndex(index_pos);
1769  new_maskIt.Set(0);
1770  new_disparityIt.Set(0);
1771  }
1772  ++new_disparityIt;
1773  }
1774  index[0]=outputPtr->GetRequestedRegion().GetIndex()[0];
1775  index[1]=index_pos[1]+1;
1776  new_disparityIt.SetIndex(index);
1777  }
1778 
1779 }
1780 
1781 } // end namespace otb
1782 
1783 #endif
void SetDataObject(DataObject *dobj)
void SetIndex(const IndexType &ind) override
void SetSubPixelMaskInput(const TMask *subpixelmask)
virtual void SetDescription(const std::string &s)
virtual void SetLocation(const std::string &s)
const IndexType GetIndex() const
void SetMedianMaskInput(const TMask *medianmask)
Compute the density of a neighboorhood centerred in a pixel.
void SetMedianDisparityInput(const TImage *medianmap)
DataObject * GetInput(const DataObjectIdentifierType &key)
void SetEdgesDisparityInput(const TImage *cannymedianmap)
DataObject * GetOutput(const DataObjectIdentifierType &key)