Orfeo Toolbox  3.16
itkContourDirectedMeanDistanceImageFilter.txx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Insight Segmentation & Registration Toolkit
4  Module: $RCSfile: itkContourDirectedMeanDistanceImageFilter.txx,v $
5  Language: C++
6  Date: $Date: 2008-10-13 18:54:27 $
7  Version: $Revision: 1.9 $
8 
9  Copyright (c) Insight Software Consortium. All rights reserved.
10  See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.
11 
12  This software is distributed WITHOUT ANY WARRANTY; without even
13  the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
14  PURPOSE. See the above copyright notices for more information.
15 
16 =========================================================================*/
17 
18 #ifndef __itkContourDirectedMeanDistanceImageFilter_txx
19 #define __itkContourDirectedMeanDistanceImageFilter_txx
20 
22 
27 #include "itkOffset.h"
28 #include "itkImageRegionIterator.h"
30 #include "itkNumericTraits.h"
32 #include "itkProgressReporter.h"
33 
34 namespace itk {
35 
36 
37 template<class TInputImage1, class TInputImage2>
39 ::ContourDirectedMeanDistanceImageFilter(): m_MeanDistance(1),m_Count(1)
40 {
41 
42  // this filter requires two input images
43  this->SetNumberOfRequiredInputs( 2 );
44 
45  m_DistanceMap = NULL;
46  m_ContourDirectedMeanDistance = NumericTraits<RealType>::Zero;
47 }
48 
49 
50 template<class TInputImage1, class TInputImage2>
51 void
53 ::SetInput2( const TInputImage2 * image )
54 {
55  this->SetNthInput(1, const_cast<TInputImage2 *>( image ) );
56 }
57 
58 
59 template<class TInputImage1, class TInputImage2>
61 ::InputImage2Type *
64 {
65  return static_cast< const TInputImage2 * >
66  (this->ProcessObject::GetInput(1));
67 }
68 
69 template<class TInputImage1, class TInputImage2>
70 void
73 {
74  Superclass::GenerateInputRequestedRegion();
75 
76  // this filter requires:
77  // - the largeset possible region of the first image
78  // - the corresponding region of the second image
79  if ( this->GetInput1() )
80  {
81  InputImage1Pointer image1 =
82  const_cast< InputImage1Type * >( this->GetInput1() );
83  image1->SetRequestedRegionToLargestPossibleRegion();
84 
85  if ( this->GetInput2() )
86  {
87  InputImage2Pointer image2 =
88  const_cast< InputImage2Type * >( this->GetInput2() );
89  image2->SetRequestedRegion(
90  this->GetInput1()->GetRequestedRegion() );
91  }
92 
93  }
94 }
95 
96 
97 template<class TInputImage1, class TInputImage2>
98 void
101 {
102  Superclass::EnlargeOutputRequestedRegion(data);
104 }
105 
106 
107 template<class TInputImage1, class TInputImage2>
108 void
111 {
112  // Pass the first input through as the output
113  InputImage1Pointer image =
114  const_cast< TInputImage1 * >( this->GetInput1() );
115  this->GraftOutput( image );
116 }
117 
118 
119 template<class TInputImage1, class TInputImage2>
120 void
123 {
124  int numberOfThreads = this->GetNumberOfThreads();
125 
126  // Resize the thread temporaries
127  m_MeanDistance.SetSize(numberOfThreads);
128  m_Count.SetSize(numberOfThreads);
129 
130  // Initialize the temporaries
131  m_MeanDistance.Fill(NumericTraits<RealType>::Zero);
132  m_Count.Fill(0);
133 
134  // Compute SignedDanielsson distance from non-zero pixels in the second image
136  FilterType;
137 
138  typename FilterType::Pointer filter = FilterType::New();
139 
140  filter->SetInput( this->GetInput2() );
141  filter->Update();
142 
143  m_DistanceMap = filter->GetOutput();
144 
145 }
146 
147 
148 template<class TInputImage1, class TInputImage2>
149 void
152 {
153  int i;
154 
155  int numberOfThreads = this->GetNumberOfThreads();
156 
157  // find mean over all threads
158  int count = 0;
160  for( i = 0; i < numberOfThreads; i++)
161  {
162  sum += m_MeanDistance[i];
163  count += m_Count[i];
164  }
165  if (count != 0)
166  {
167  m_ContourDirectedMeanDistance= sum/static_cast<RealType>(count);
168  }
169  else
170  {
171  m_ContourDirectedMeanDistance = NumericTraits<RealType>::Zero;
172  }
173 }
174 
175 template<class TInputImage1, class TInputImage2>
176 void
178 ::ThreadedGenerateData(const RegionType& outputRegionForThread,
179  int threadId)
180 {
181  unsigned int i;
183 
185 
186  typename InputImage1Type::ConstPointer input = this->GetInput();
187 
188  // Find the data-set boundary "faces"
189  typedef typename InputImage1Type::SizeType InputSizeType;
190  InputSizeType radius;
191  radius.Fill(1);
194  faceList = bC(input, outputRegionForThread, radius);
195 
197 
198  typedef typename InputImage1Type::PixelType InputPixelType;
199 
200  // support progress methods/callbacks
201  ProgressReporter progress(this, threadId, outputRegionForThread.GetNumberOfPixels());
202 
203 
204 
205  // Process each of the boundary faces. These are N-d regions which border
206  // the edge of the buffer.
207  for (fit=faceList.begin(); fit != faceList.end(); ++fit)
208  {
209  ImageRegionConstIterator<DistanceMapType> it2 (m_DistanceMap, *fit);
210  bit = ConstNeighborhoodIterator<InputImage1Type>(radius, input, *fit);
211  unsigned int neighborhoodSize = bit.Size();
212 
213  bit.OverrideBoundaryCondition(&nbc);
214  bit.GoToBegin();
215 
216  bool bIsOnContour;
217 
218  while ( ! bit.IsAtEnd() )
219  {
220 
221  // first test
222  // if current pixel is not on, let's continue
224  {
225 
226  bIsOnContour = false;
227 
228  for (i = 0; i < neighborhoodSize; ++i)
229  {
230  // second test if at least one neighbour pixel is off
231  // the center pixel belongs to contour
233  {
234  bIsOnContour = true;
235  break;
236  }
237  }
238 
239  // set pixel center pixel value whether it is or not on contour
240  if( bIsOnContour )
241  {
242  const RealType value = it2.Get();
243  m_MeanDistance[threadId] += vnl_math_abs( value );
244  m_Count[threadId]++;
245  }
246  }
247  ++bit;
248  ++it2;
249  progress.CompletedPixel();
250  }
251  }
252 }
253 
254 
255 template<class TInputImage1, class TInputImage2>
256 void
258 ::PrintSelf(std::ostream& os, Indent indent) const
259 {
260  Superclass::PrintSelf(os,indent);
261 
262  os << indent << "ContourDirectedMeanDistance: "
263  << m_ContourDirectedMeanDistance << std::endl;
264 }
265 
266 
267 }// end namespace itk
268 #endif

Generated at Sat May 18 2013 23:34:51 for Orfeo Toolbox with doxygen 1.8.3.1