Orfeo Toolbox  3.16
itkSignedDanielssonDistanceMapImageFilter.txx
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Insight Segmentation & Registration Toolkit
4  Module: $RCSfile: itkSignedDanielssonDistanceMapImageFilter.txx,v $
5  Language: C++
6  Date: $Date: 2009-03-10 14:26:16 $
7  Version: $Revision: 1.10 $
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 __itkSignedDanielssonDistanceMapImageFilter_txx
18 #define __itkSignedDanielssonDistanceMapImageFilter_txx
19 
21 #include "itkProgressAccumulator.h"
25 
26 namespace itk
27 {
28 
32 template <class TInputImage,class TOutputImage>
35 {
36  this->SetNumberOfRequiredOutputs( 3 );
37 
38  OutputImagePointer voronoiMap = OutputImageType::New();
39  this->SetNthOutput( 1, voronoiMap.GetPointer() );
40 
41  VectorImagePointer distanceVectors = VectorImageType::New();
42  this->SetNthOutput( 2, distanceVectors.GetPointer() );
43 
44  //Default values
45  this->m_SquaredDistance = false; //Should we remove this ?
46  //doesn't make sense in a SignedDaniel
47  this->m_UseImageSpacing = false;
48  this->m_InsideIsPositive = false;
49 }
50 
52 template <class TInputImage,class TOutputImage>
54  TInputImage,TOutputImage>::DataObjectPointer
56 ::MakeOutput(unsigned int idx)
57 {
58  if (idx == 2)
59  {
60  return static_cast<DataObject*>(VectorImageType::New().GetPointer());
61  }
62  return Superclass::MakeOutput(idx);
63 }
64 
68 template <class TInputImage,class TOutputImage>
70  TInputImage,TOutputImage>::OutputImageType *
73 {
74  return dynamic_cast< OutputImageType * >(
75  this->ProcessObject::GetOutput(0) );
76 }
77 
78 
82 template <class TInputImage,class TOutputImage>
83 typename
87 {
88  return dynamic_cast< OutputImageType * >(
89  this->ProcessObject::GetOutput(1) );
90 }
91 
92 
96 template <class TInputImage,class TOutputImage>
98  TInputImage,TOutputImage>::VectorImageType *
101 {
102  return dynamic_cast< VectorImageType * >(
103  this->ProcessObject::GetOutput(2) );
104 }
105 
106 
111 template <class TInputImage,class TOutputImage>
114 {
115  //Set up mini pipeline filter
117  progress->SetMiniPipelineFilter(this);
118 
121  typename FilterType::Pointer filter1= FilterType::New();
122  typename FilterType::Pointer filter2= FilterType::New();
123 
124  filter1->SetInputIsBinary( true ); // Force signed distance map to work on
125  filter2->SetInputIsBinary( true ); // binary images
126  filter1->SetUseImageSpacing( m_UseImageSpacing );
127  filter2->SetUseImageSpacing( m_UseImageSpacing );
128  filter1->SetSquaredDistance( m_SquaredDistance );
129  filter2->SetSquaredDistance( m_SquaredDistance );
130 
131  //Invert input image for second Danielsson filter
132  typedef typename InputImageType::PixelType InputPixelType;
134  typedef UnaryFunctorImageFilter< InputImageType,
135  InputImageType,
136  FunctorType > InverterType;
137 
138  typename InverterType::Pointer inverter = InverterType::New();
139 
140  inverter->SetInput(this->GetInput());
141 
142  //Dilate the inverted image by 1 pixel to give it the same boundary
143  //as the univerted input.
144 
146  InputPixelType,
147  InputImageDimension > StructuringElementType;
148 
149  typedef BinaryDilateImageFilter<
150  InputImageType,
151  InputImageType,
152  StructuringElementType > DilatorType;
153 
154  typename DilatorType::Pointer dilator = DilatorType::New();
155 
156  StructuringElementType structuringElement;
157  structuringElement.SetRadius( 1 ); // 3x3 structuring element
158  structuringElement.CreateStructuringElement();
159  dilator->SetKernel( structuringElement );
160  dilator->SetDilateValue(1);
161 
162  filter1->SetInput( this->GetInput() );
163  dilator->SetInput( inverter->GetOutput() );
164  filter2->SetInput( dilator->GetOutput() );
165 
166  //Subtract Distance maps results of the two Danielsson filters
167  typedef SubtractImageFilter< OutputImageType, OutputImageType,
168  OutputImageType > SubtracterType;
169 
170  typename SubtracterType::Pointer subtracter = SubtracterType::New();
171 
172  if ( m_InsideIsPositive )
173  {
174  subtracter->SetInput1(filter2->GetDistanceMap());
175  subtracter->SetInput2(filter1->GetDistanceMap());
176  }
177  else
178  {
179  subtracter->SetInput2(filter2->GetDistanceMap());
180  subtracter->SetInput1(filter1->GetDistanceMap());
181  }
182 
183  subtracter->Update();
184  filter1->Update();
185  filter2->Update();
186 
187  // Register progress
188  progress->RegisterInternalFilter(filter1,.5f);
189 
190  // Graft outputs
191  this->GraftNthOutput( 0, subtracter->GetOutput() );
192 
193  // we must use not use this->GetOutput method because the
194  // output's are of different types then ImageSource
195  this->GraftNthOutput( 1, filter1->GetVoronoiMap() );
196  this->GraftNthOutput( 2, filter1->GetVectorDistanceMap() );
197 
198 }
199 // end GenerateData()
200 
204 template <class TInputImage,class TOutputImage>
206 ::PrintSelf(std::ostream& os, Indent indent) const
207 {
208  Superclass::PrintSelf(os,indent);
209  os << indent << "Signed Danielson Distance: " << std::endl;
210  os << indent << "Use Image Spacing : " << m_UseImageSpacing << std::endl;
211  os << indent << "Squared Distance : " << m_SquaredDistance << std::endl;
212  os << indent << "Inside is positive : " << m_InsideIsPositive << std::endl;
213 }
214 
215 
216 } // end namespace itk
217 
218 #endif

Generated at Sun Feb 3 2013 00:07:00 for Orfeo Toolbox with doxygen 1.8.1.1