File: itkObjectMorphologyImageFilter.h

package info (click to toggle)
insighttoolkit 3.6.0-3
  • links: PTS
  • area: main
  • in suites: lenny
  • size: 94,956 kB
  • ctags: 74,981
  • sloc: cpp: 355,621; ansic: 195,070; fortran: 28,713; python: 3,802; tcl: 1,996; sh: 1,175; java: 583; makefile: 415; csh: 184; perl: 175
file content (245 lines) | stat: -rw-r--r-- 9,909 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
/*=========================================================================

  Program:   Insight Segmentation & Registration Toolkit
  Module:    $RCSfile: itkObjectMorphologyImageFilter.h,v $
  Language:  C++
  Date:      $Date: 2006-03-29 14:43:58 $
  Version:   $Revision: 1.8 $

  Copyright (c) Insight Software Consortium. All rights reserved.
  See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details.

     This software is distributed WITHOUT ANY WARRANTY; without even 
     the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
     PURPOSE.  See the above copyright notices for more information.

=========================================================================*/
#ifndef __itkObjectMorphologyImageFilter_h
#define __itkObjectMorphologyImageFilter_h

#include "itkImageToImageFilter.h"
#include "itkNeighborhoodIterator.h"
#include "itkNeighborhood.h"
#include "itkConstSliceIterator.h"
#include "itkConstantBoundaryCondition.h"
#include "itkImageBoundaryCondition.h"
#include "itkImageRegionIterator.h"

namespace itk {

/** \class ObjectMorphologyImageFilter 
 * \brief Base class for the morphological operations 
 * being applied to isolated objects in an image.
 *
 * This class provides the infrastructure to support of
 * morphological operations being applied to images in which
 * the foreground and background intensities are fixed. This filter
 * operates significantly faster than itkBinaryMorhologicalImageFilters;
 * however itkBinaryMorhologicalImageFilters preserve
 * background pixels based on values of neighboring background 
 * pixels - potentially important during erosion.
 *
 * The "kernel" specified represents a morphology structuring element.
 * The structuring element is a small Neighborhood with values
 * indicating an element is "on" (value > 0) or "off" (value <=0).
 * Morphological operations are defined by placing the structuring
 * element over a pixel, and calculating a nonlinear function (min,
 * max) over the pixels of the image that are under pixels in the
 * structuring element that are "on". The result of this calculation
 * is the value of the pixel in the output image.  Under most
 * circumstances, the "center pixel" of the structuring element -- or
 * structuring element pixel over the input pixel under consideration
 * -- is prescribed to be "on". This is not a strict requirement but
 * the subclasses of this filter are not guarenteed to produce the
 * correct result if the "center pixel" is not part of the structuring
 * element.
 *
 * Subclasses of this class can define their own operations by simply
 * providing their own Evaluate() protected member functions - one
 * that operates using a smart neighborhood operator for edge faces and
 * one that operates using a standard neighboorhood operator..
 *
 * \sa ErodeObjectMorphologicalImageFilter
 * \sa DilateObjectMorphologicalImageFilter
 * \sa BinaryErodeImageFilter
 * \sa BinaryDilateImageFilter
 * \sa GrayScaleErodeImageFilter
 * \sa GrayScaleDilateImageFilter
 * \sa NeighborhoodIterator
 * \sa Neighborhood
 * \ingroup ImageEnhancement  MathematicalMorphologyImageFilters
 */
template<class TInputImage, class TOutputImage, class TKernel>
class ITK_EXPORT ObjectMorphologyImageFilter : 
    public ImageToImageFilter<TInputImage, TOutputImage>
{
public:
  /** Standard Self typedef */
  typedef ObjectMorphologyImageFilter Self;
  typedef ImageToImageFilter<TInputImage,TOutputImage>  Superclass;
  typedef SmartPointer<Self>        Pointer;
  typedef SmartPointer<const Self>  ConstPointer;
  
  /** Runtime information support. */
  itkTypeMacro(ObjectMorphologyImageFilter, ImageToImageFilter);
  
  /** Image related typedefs. */
  typedef TInputImage InputImageType;
  typedef TOutputImage OutputImageType;
  typedef typename TInputImage::RegionType RegionType ;
  typedef typename TInputImage::SizeType SizeType ;
  typedef typename TInputImage::IndexType IndexType ;
  typedef typename TInputImage::PixelType PixelType ;
  typedef typename Superclass::OutputImageRegionType OutputImageRegionType;

  typedef ImageBoundaryCondition<InputImageType> * 
               ImageBoundaryConditionPointerType;
  typedef ImageBoundaryCondition<InputImageType> const * 
               ImageBoundaryConditionConstPointerType;
  typedef ConstantBoundaryCondition<InputImageType> 
               DefaultBoundaryConditionType;
  
  /** Image related typedefs. */
  itkStaticConstMacro(ImageDimension, unsigned int,
                      TInputImage::ImageDimension);
  itkStaticConstMacro(OutputImageDimension, unsigned int,
                      TOutputImage::ImageDimension );
  itkStaticConstMacro(KernelDimension, unsigned int,
                      TKernel::NeighborhoodDimension);  

  /** Neighborhood iterator type. */
  typedef ConstNeighborhoodIterator<TInputImage> 
  InputNeighborhoodIteratorType ;

  typedef NeighborhoodIterator<TOutputImage> 
  OutputNeighborhoodIteratorType ;

  /** Kernel typedef. */
  typedef TKernel KernelType;
  
  /** Kernel (structuring element) iterator. */
  typedef typename KernelType::ConstIterator KernelIteratorType ;
  
  /** n-dimensional Kernel radius. */
  typedef typename KernelType::SizeType RadiusType ;

  /** Set kernel (structuring element). */
  itkSetMacro(Kernel, KernelType);

  /** Get the kernel (structuring element). */
  itkGetConstReferenceMacro(Kernel, KernelType);

  /** Get the pixel value being used to identify the object of interest */
  itkGetMacro(ObjectValue, PixelType);

  /** Set the pixel value being used to identify the object of interest */
  itkSetMacro(ObjectValue, PixelType);
  
  /** ObjectMorphologyImageFilters need to make sure they request enough of an
   * input image to account for the structuring element size.  The input
   * requested region is expanded by the radius of the structuring element.
   * If the request extends past the LargestPossibleRegion for the input,
   * the request is cropped by the LargestPossibleRegion. */
  void GenerateInputRequestedRegion() ;

  /** Allows a user to override the internal boundary condition. Care should be
   * be taken to ensure that the overriding boundary condition is a persistent
   * object during the time it is referenced.  The overriding condition
   * can be of a different type than the default type as long as it is
   * a subclass of ImageBoundaryCondition. 
   * NOTE: Don't foget to set UseBoundaryCondition to true! */
  void OverrideBoundaryCondition(const ImageBoundaryConditionPointerType i)
    { m_BoundaryCondition = i; }

  /** Rest the boundary condition to the default */
  void ResetBoundaryCondition()
    { m_BoundaryCondition = &m_DefaultBoundaryCondition; }
  
  /** Get the current boundary condition. */
  itkGetMacro(BoundaryCondition, ImageBoundaryConditionPointerType);

  /** Enable/disable the use of boundary condition.  Defaults to false.
   * if false, a neighborhood operator extends outside an image, it does
   * not consider that outside extent when determining if a pixel is on
   * an object's boundary. */
  itkSetMacro(UseBoundaryCondition, bool);

  /** Enable/disable the use of boundary condition.  Defaults to false.
   * if false, a neighborhood operator extends outside an image, it does
   * not consider that outside extent when determining if a pixel is on
   * an object's boundary. */
  itkGetMacro(UseBoundaryCondition, bool);

#ifdef ITK_USE_CONCEPT_CHECKING
  /** Begin concept checking */
  itkConceptMacro(SameDimensionCheck1,
    (Concept::SameDimension<ImageDimension, OutputImageDimension>));
  itkConceptMacro(SameDimensionCheck2,
    (Concept::SameDimension<ImageDimension, KernelDimension>));
  itkConceptMacro(OutputInputEqualityComparableCheck,
    (Concept::EqualityComparable<typename TOutputImage::PixelType,
                                 PixelType>));
  itkConceptMacro(InputConvertibleToOutputCheck,
    (Concept::Convertible<PixelType, typename TOutputImage::PixelType>));
  itkConceptMacro(IntConvertibleToOutputCheck,
    (Concept::Convertible<int, typename TOutputImage::PixelType>));
  itkConceptMacro(InputEqualityComparable,
    (Concept::EqualityComparable<PixelType>));
  itkConceptMacro(InputOStreamWritableCheck,
    (Concept::OStreamWritable<PixelType>));
  /** End concept checking */
#endif

protected:
  ObjectMorphologyImageFilter();
  ~ObjectMorphologyImageFilter() {};
  void PrintSelf(std::ostream& os, Indent indent) const;

  /** Multi-thread version GenerateData. */
  void  ThreadedGenerateData (const OutputImageRegionType& 
                              outputRegionForThread,
                              int threadId) ;

  /** Evaluate image neighborhood with kernel to find the new value 
   * for the center pixel value. */
  virtual void Evaluate(OutputNeighborhoodIteratorType &nit,
                        const KernelType &kernel)=0;

  /** Evaluate a pixel (assumed to have a value of ObjectValue) to 
   * determine if one of its neighboring pixels (8-neigh in 2d, etc) is a 
   * non-ObjectValue pixel. */
  bool IsObjectPixelOnBoundary(const InputNeighborhoodIteratorType &nit);

  /** Pointer to a persistent boundary condition object used
   * for the image iterator. */
  ImageBoundaryConditionPointerType m_BoundaryCondition;

  /** Default boundary condition */
  DefaultBoundaryConditionType m_DefaultBoundaryCondition;

  /** Defaults to false */
  bool m_UseBoundaryCondition;

  /** kernel or structuring element to use. */
  KernelType m_Kernel ;

  /** Pixel value that indicates the object be operated upon */
  PixelType m_ObjectValue;

  void BeforeThreadedGenerateData();

private:
  ObjectMorphologyImageFilter(const Self&); //purposely not implemented
  void operator=(const Self&); //purposely not implemented

  

} ; // end of class

} // end namespace itk
  
#ifndef ITK_MANUAL_INSTANTIATION
#include "itkObjectMorphologyImageFilter.txx"
#endif

#endif