Orfeo Toolbox  3.16
itkLaplacianRecursiveGaussianImageFilter.txx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Insight Segmentation & Registration Toolkit
4  Module: $RCSfile: itkLaplacianRecursiveGaussianImageFilter.txx,v $
5  Language: C++
6  Date: $Date: 2008-10-16 17:40:08 $
7  Version: $Revision: 1.6 $
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 #ifndef __itkLaplacianRecursiveGaussianImageFilter_txx
18 #define __itkLaplacianRecursiveGaussianImageFilter_txx
19 
22 
23 namespace itk
24 {
25 
29 template <typename TInputImage, typename TOutputImage >
32 {
33 
34  m_NormalizeAcrossScale = false;
35 
36  m_ProgressCommand = CommandType::New();
37  m_ProgressCommand->SetCallbackFunction( this, & Self::ReportProgress );
38  m_Progress = 0.0f;
39 
40  for( unsigned int i = 0; i<ImageDimension-1; i++ )
41  {
42  m_SmoothingFilters[ i ] = GaussianFilterType::New();
43  m_SmoothingFilters[ i ]->SetOrder( GaussianFilterType::ZeroOrder );
44  m_SmoothingFilters[ i ]->SetNormalizeAcrossScale( m_NormalizeAcrossScale );
45  m_SmoothingFilters[ i ]->AddObserver( ProgressEvent(), m_ProgressCommand );
46  m_SmoothingFilters[ i ]->ReleaseDataFlagOn();
47  }
48 
49  m_DerivativeFilter = DerivativeFilterType::New();
50  m_DerivativeFilter->SetOrder( DerivativeFilterType::SecondOrder );
51  m_DerivativeFilter->SetNormalizeAcrossScale( m_NormalizeAcrossScale );
52  m_DerivativeFilter->AddObserver( ProgressEvent(), m_ProgressCommand );
53 
54  m_DerivativeFilter->SetInput( this->GetInput() );
55 
56  m_SmoothingFilters[0]->SetInput( m_DerivativeFilter->GetOutput() );
57 
58  for( unsigned int i = 1; i<ImageDimension-1; i++ )
59  {
60  m_SmoothingFilters[ i ]->SetInput(
61  m_SmoothingFilters[i-1]->GetOutput() );
62  }
63 
64  m_CumulativeImage = CumulativeImageType::New();
65 
66  this->SetSigma( 1.0 );
67 
68 }
69 
73 template <typename TInputImage, typename TOutputImage>
74 void
76 ::ReportProgress(const Object * object, const EventObject & event )
77 {
78  const ProcessObject * internalFilter =
79  dynamic_cast<const ProcessObject *>( object );
80 
81  if( typeid( event ) == typeid( ProgressEvent() ) )
82  {
83  const float filterProgress = internalFilter->GetProgress();
84  const float weightedProgress = filterProgress / ImageDimension;
85  m_Progress += weightedProgress;
86  this->UpdateProgress( m_Progress );
87  }
88 }
89 
93 template <typename TInputImage, typename TOutputImage>
94 void
97 {
98 
99  for( unsigned int i = 0; i<ImageDimension-1; i++ )
100  {
101  m_SmoothingFilters[ i ]->SetSigma( sigma );
102  }
103  m_DerivativeFilter->SetSigma( sigma );
104 
105  this->Modified();
106 
107 }
108 
112 template <typename TInputImage, typename TOutputImage>
113 void
115 ::SetNormalizeAcrossScale( bool normalize )
116 {
117 
118  m_NormalizeAcrossScale = normalize;
119 
120  for( unsigned int i = 0; i<ImageDimension-1; i++ )
121  {
122  m_SmoothingFilters[ i ]->SetNormalizeAcrossScale( normalize );
123  }
124  m_DerivativeFilter->SetNormalizeAcrossScale( normalize );
125 
126  this->Modified();
127 
128 }
129 
130 
131 //
132 //
133 //
134 template <typename TInputImage, typename TOutputImage>
135 void
138 {
139  // call the superclass' implementation of this method. this should
140  // copy the output requested region to the input requested region
141  Superclass::GenerateInputRequestedRegion();
142 
143  // This filter needs all of the input
145  if( image )
146  {
147  image->SetRequestedRegion( this->GetInput()->GetLargestPossibleRegion() );
148  }
149 }
150 
151 
152 //
153 //
154 //
155 template <typename TInputImage, typename TOutputImage>
156 void
159 {
160  TOutputImage *out = dynamic_cast<TOutputImage*>(output);
161 
162  if (out)
163  {
164  out->SetRequestedRegion( out->GetLargestPossibleRegion() );
165  }
166 }
167 
171 template <typename TInputImage, typename TOutputImage >
172 void
175 {
176 
177  itkDebugMacro(<< "LaplacianRecursiveGaussianImageFilter generating data ");
178 
179  m_Progress = 0.0f;
180 
181  const typename TInputImage::ConstPointer inputImage( this->GetInput() );
182 
183  typename TOutputImage::Pointer outputImage( this->GetOutput() );
184 
185  outputImage = this->GetOutput();
186 
187  outputImage->SetRegions( inputImage->GetBufferedRegion() );
188 
189  outputImage->Allocate();
190 
191  m_CumulativeImage->SetRegions( inputImage->GetBufferedRegion() );
192  m_CumulativeImage->Allocate();
193  m_CumulativeImage->FillBuffer( NumericTraits< InternalRealType >::Zero );
194 
195  m_DerivativeFilter->SetInput( inputImage );
196 
197  for( unsigned int dim=0; dim < ImageDimension; dim++ )
198  {
199  unsigned int i=0;
200  unsigned int j=0;
201  while( i< ImageDimension)
202  {
203  if( i == dim )
204  {
205  j++;
206  }
207  m_SmoothingFilters[ i ]->SetDirection( j );
208  i++;
209  j++;
210  }
211  m_DerivativeFilter->SetDirection( dim );
212 
213  GaussianFilterPointer lastFilter = m_SmoothingFilters[ImageDimension-2];
214 
215  lastFilter->Update();
216 
217 
218  // Cummulate the results on the output image
219 
220  typename RealImageType::Pointer derivativeImage = lastFilter->GetOutput();
221 
223  derivativeImage,
224  derivativeImage->GetRequestedRegion() );
225 
227  m_CumulativeImage,
228  m_CumulativeImage->GetRequestedRegion() );
229 
230  const RealType spacing = inputImage->GetSpacing()[ dim ];
231  const RealType spacing2 = spacing*spacing;
232 
233  it.GoToBegin();
234  ot.GoToBegin();
235  while( !it.IsAtEnd() )
236  {
237  const RealType value = it.Get() / spacing2;
238  const RealType cumulated = ot.Get() + value;
239  ot.Set( cumulated );
240  ++it;
241  ++ot;
242  }
243 
244  }
245 
246 
247  // Finally convert the cumulated image to the output
249  outputImage,
250  outputImage->GetRequestedRegion() );
251 
253  m_CumulativeImage,
254  m_CumulativeImage->GetRequestedRegion() );
255 
256  it.GoToBegin();
257  ot.GoToBegin();
258  while( !it.IsAtEnd() )
259  {
260  ot.Set( static_cast<OutputPixelType>( it.Get() ) );
261  ++it;
262  ++ot;
263  }
264 }
265 
266 
267 template <typename TInputImage, typename TOutputImage>
268 void
270 ::PrintSelf(std::ostream& os, Indent indent) const
271 {
272  Superclass::PrintSelf(os,indent);
273  os << "NormalizeAcrossScale: " << m_NormalizeAcrossScale << std::endl;
274 }
275 
276 
277 } // end namespace itk
278 
279 #endif

Generated at Sat Feb 2 2013 23:50:49 for Orfeo Toolbox with doxygen 1.8.1.1