ITK  4.9.0
Insight Segmentation and Registration Toolkit
itkLocalStructureImageFilter.h
Go to the documentation of this file.
1 /*=========================================================================
2 
3  Program: Insight Segmentation & Registration Toolkit
4  Module: itkLocalStructureImageFilter.h
5  Language: C++
6  Date: $Date$
7  Version: $Revision$
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 itkLocalStructureImageFilter_h
18 #define itkLocalStructureImageFilter_h
19 
21 #include "vnl/vnl_math.h"
22 
23 namespace itk
24 {
25 
47 namespace Function {
48 
49 template< class TInput, class TOutput>
51 {
52 public:
54  {
55  m_Alpha = 0.25; // suggested value in the paper
56  m_Gamma = 0.50; // suggested value in the paper;
57  }
59  bool operator!=( const LocalStructure & ) const
60  {
61  return false;
62  }
63  bool operator==( const LocalStructure & other ) const
64  {
65  return !(*this != other);
66  }
67  inline TOutput operator()( const TInput & A )
68  {
69  double a1 = static_cast<double>( A[0] );
70  double a2 = static_cast<double>( A[1] );
71  double a3 = static_cast<double>( A[2] );
72 
73  double l1 = vnl_math_abs( a1 );
74  double l2 = vnl_math_abs( a2 );
75  double l3 = vnl_math_abs( a3 );
76 
77  //
78  // Sort the values by their absolute value.
79  //
80  if( l2 > l3 )
81  {
82  double tmpl = l3;
83  l3 = l2;
84  l2 = tmpl;
85  double tmpa = a3;
86  a3 = a2;
87  a2 = tmpa;
88  }
89 
90  if( l1 > l2 )
91  {
92  double tmp = l1;
93  l1 = l2;
94  l2 = tmp;
95  double tmpa = a1;
96  a1 = a2;
97  a2 = tmpa;
98  }
99 
100  if( l2 > l3 )
101  {
102  double tmp = l3;
103  l3 = l2;
104  l2 = tmp;
105  double tmpa = a3;
106  a3 = a2;
107  a2 = tmpa;
108  }
109 
110  //
111  // Avoid divisions by zero.
112  //
113  if( l3 < vnl_math::eps )
114  {
115  return 0.0;
116  }
117 
118  const double L3 = vnl_math_abs( static_cast<double>( a3 ) );
119  const double W = WeightFunctionOmega( a2, a3 );
120  const double F = WeightFunctionOmega( a1, a3 );
121 
122  const double sheetness = L3 * W * F;
123 
124  return static_cast<TOutput>( sheetness );
125  }
126  inline double WeightFunctionOmega( double ls, double lt ) const
127  {
128  if( ls <= 0.0 && lt <= ls )
129  {
130  return ( 1 + vcl_pow( ls / vnl_math_abs( lt ), m_Gamma ) );
131  }
132  const double abslt = vnl_math_abs( lt );
133  if( ls > 0.0 && abslt / m_Gamma > ls )
134  {
135  return vcl_pow( 1 - m_Alpha * ls / vnl_math_abs( lt ), m_Gamma );
136  }
137  return 0.0;
138  }
139  inline double WeightFunctionPhi( double ls, double lt ) const
140  {
141  if( ls < 0.0 && lt <= ls )
142  {
143  return vcl_pow( ( ls / lt ), m_Gamma );
144  }
145  return 0.0;
146  }
147 
148  void SetAlpha( double value )
149  {
150  this->m_Alpha = value;
151  }
152 
153  void SetGamma( double value )
154  {
155  this->m_Gamma = value;
156  }
157 
158 private:
159  double m_Alpha;
160  double m_Gamma;
161 };
162 }
163 
164 template <class TInputImage, class TOutputImage>
165 class ITK_EXPORT LocalStructureImageFilter :
166  public
167 UnaryFunctorImageFilter<TInputImage,TOutputImage,
168  Function::LocalStructure< typename TInputImage::PixelType,
169  typename TOutputImage::PixelType> >
170 {
171 public:
174  typedef UnaryFunctorImageFilter<
175  TInputImage,TOutputImage,
177  typename TInputImage::PixelType,
178  typename TOutputImage::PixelType> > Superclass;
181 
183  itkNewMacro(Self);
184 
186  itkTypeMacro(LocalStructureImageFilter,
188 
190  void SetAlpha( double value )
191  {
192  this->GetFunctor().SetAlpha( value );
193  }
194 
196  void SetGamma( double value )
197  {
198  this->GetFunctor().SetGamma( value );
199  }
200 
201 
202 #ifdef ITK_USE_CONCEPT_CHECKING
203 
204  typedef typename TInputImage::PixelType InputPixelType;
205  itkConceptMacro(BracketOperatorsCheck,
207  itkConceptMacro(DoubleConvertibleToOutputCheck,
209 
211 #endif
212 
213 protected:
216 
217 private:
218  LocalStructureImageFilter(const Self&); //purposely not implemented
219  void operator=(const Self&); //purposely not implemented
220 
221 };
222 
223 } // end namespace itk
224 
225 
226 #endif
bool operator==(const LocalStructure &other) const
double WeightFunctionOmega(double ls, double lt) const
Base class for all process objects that output image data.
double WeightFunctionPhi(double ls, double lt) const
Implements pixel-wise generic operation on one image.
#define itkConceptMacro(name, concept)
Computes local similarity to geometrical structures using second derivative operations.
UnaryFunctorImageFilter< TInputImage, TOutputImage, Function::LocalStructure< typename TInputImage::PixelType, typename TOutputImage::PixelType > > Superclass
bool operator!=(const LocalStructure &) const