]> Creatis software - clitk.git/blob - itk/itkBinaryThinningImageFilter3D.h
7b82278ba6d2b285bfa68eae1a0394655d00c8f9
[clitk.git] / itk / itkBinaryThinningImageFilter3D.h
1 #ifndef __itkBinaryThinningImageFilter3D_h\r
2 #define __itkBinaryThinningImageFilter3D_h\r
3 \r
4 #include <itkNeighborhoodIterator.h>\r
5 #include <itkImageToImageFilter.h>\r
6 #include <itkImageRegionIteratorWithIndex.h>\r
7 #include <itkConstantBoundaryCondition.h>\r
8 \r
9 namespace itk\r
10 {\r
11 /** \class BinaryThinningImageFilter3D\r
12 *\r
13 * \brief This filter computes one-pixel-wide skeleton of a 3D input image.\r
14 *\r
15 * This class is parametrized over the type of the input image\r
16 * and the type of the output image.\r
17\r
18 * The input is assumed to be a binary image. All non-zero valued voxels\r
19 * are set to 1 internally to simplify the computation. The filter will\r
20 * produce a skeleton of the object.  The output background values are 0,\r
21 * and the foreground values are 1.\r
22\r
23 * A 26-neighbourhood configuration is used for the foreground and a\r
24 * 6-neighbourhood configuration for the background. Thinning is performed\r
25 * symmetrically in order to guarantee that the skeleton lies medial within\r
26 * the object.\r
27 *\r
28 * This filter is a parallel thinning algorithm and is an implementation\r
29 * of the algorithm described in:\r
30\r
31 * T.C. Lee, R.L. Kashyap, and C.N. Chu.\r
32 * Building skeleton models via 3-D medial surface/axis thinning algorithms.\r
33 * Computer Vision, Graphics, and Image Processing, 56(6):462--478, 1994.\r
34\r
35 * To do: Make use of multi-threading.\r
36 *\r
37 * \author Hanno Homann, Oxford University, Wolfson Medical Vision Lab, UK.\r
38\r
39 * \sa MorphologyImageFilter\r
40 * \ingroup ImageEnhancement MathematicalMorphologyImageFilters\r
41 */\r
42 \r
43 template <class TInputImage,class TOutputImage>\r
44 class BinaryThinningImageFilter3D :\r
45     public ImageToImageFilter<TInputImage,TOutputImage>\r
46 {\r
47 public:\r
48   /** Standard class typedefs. */\r
49   typedef BinaryThinningImageFilter3D    Self;\r
50   typedef ImageToImageFilter<TInputImage,TOutputImage> Superclass;\r
51   typedef SmartPointer<Self> Pointer;\r
52   typedef SmartPointer<const Self> ConstPointer;\r
53 \r
54   /** Method for creation through the object factory */\r
55   itkNewMacro(Self);\r
56 \r
57   /** Run-time type information (and related methods). */\r
58   itkTypeMacro( BinaryThinningImageFilter3D, ImageToImageFilter );\r
59 \r
60   /** Type for input image. */\r
61   typedef   TInputImage       InputImageType;\r
62 \r
63   /** Type for output image: Skelenton of the object.  */\r
64   typedef   TOutputImage      OutputImageType;\r
65 \r
66   /** Type for the region of the input image. */\r
67   typedef typename InputImageType::RegionType RegionType;\r
68 \r
69   /** Type for the index of the input image. */\r
70   typedef typename RegionType::IndexType  IndexType;\r
71 \r
72   /** Type for the pixel type of the input image. */\r
73   typedef typename InputImageType::PixelType InputImagePixelType ;\r
74 \r
75   /** Type for the pixel type of the input image. */\r
76   typedef typename OutputImageType::PixelType OutputImagePixelType ;\r
77 \r
78   /** Type for the size of the input image. */\r
79   typedef typename RegionType::SizeType SizeType;\r
80 \r
81   /** Pointer Type for input image. */\r
82   typedef typename InputImageType::ConstPointer InputImagePointer;\r
83 \r
84   /** Pointer Type for the output image. */\r
85   typedef typename OutputImageType::Pointer OutputImagePointer;\r
86   \r
87   /** Boundary condition type for the neighborhood iterator */\r
88   typedef ConstantBoundaryCondition< TInputImage > ConstBoundaryConditionType;\r
89   \r
90   /** Neighborhood iterator type */\r
91   typedef NeighborhoodIterator<TInputImage, ConstBoundaryConditionType> NeighborhoodIteratorType;\r
92   \r
93   /** Neighborhood type */\r
94   typedef typename NeighborhoodIteratorType::NeighborhoodType NeighborhoodType;\r
95 \r
96   /** Get Skelenton by thinning image. */\r
97   OutputImageType * GetThinning(void);\r
98 \r
99   /** ImageDimension enumeration   */\r
100   itkStaticConstMacro(InputImageDimension, unsigned int,\r
101                       TInputImage::ImageDimension );\r
102   itkStaticConstMacro(OutputImageDimension, unsigned int,\r
103                       TOutputImage::ImageDimension );\r
104 \r
105 #ifdef ITK_USE_CONCEPT_CHECKING\r
106   /** Begin concept checking */\r
107   itkConceptMacro(SameDimensionCheck,\r
108     (Concept::SameDimension<InputImageDimension, 3>));\r
109   itkConceptMacro(SameTypeCheck,\r
110     (Concept::SameType<InputImagePixelType, OutputImagePixelType>));\r
111   itkConceptMacro(InputAdditiveOperatorsCheck,\r
112     (Concept::AdditiveOperators<InputImagePixelType>));\r
113   itkConceptMacro(InputConvertibleToIntCheck,\r
114     (Concept::Convertible<InputImagePixelType, int>));\r
115   itkConceptMacro(IntConvertibleToInputCheck,\r
116     (Concept::Convertible<int, InputImagePixelType>));\r
117   itkConceptMacro(InputIntComparableCheck,\r
118     (Concept::Comparable<InputImagePixelType, int>));\r
119   /** End concept checking */\r
120 #endif\r
121 \r
122 protected:\r
123   BinaryThinningImageFilter3D();\r
124   virtual ~BinaryThinningImageFilter3D() {};\r
125   void PrintSelf(std::ostream& os, Indent indent) const;\r
126 \r
127   /** Compute thinning Image. */\r
128   void GenerateData();\r
129 \r
130   /** Prepare data. */\r
131   void PrepareData();\r
132 \r
133   /**  Compute thinning Image. */\r
134   void ComputeThinImage();\r
135   \r
136   /**  isEulerInvariant [Lee94] */\r
137   bool isEulerInvariant(NeighborhoodType neighbors, int *LUT);\r
138   void fillEulerLUT(int *LUT);  \r
139   /**  isSimplePoint [Lee94] */\r
140   bool isSimplePoint(NeighborhoodType neighbors);\r
141   /**  Octree_labeling [Lee94] */\r
142   void Octree_labeling(int octant, int label, int *cube);\r
143 \r
144 \r
145 private:   \r
146   BinaryThinningImageFilter3D(const Self&); //purposely not implemented\r
147   void operator=(const Self&); //purposely not implemented\r
148 \r
149 }; // end of BinaryThinningImageFilter3D class\r
150 \r
151 } //end namespace itk\r
152 \r
153 #ifndef ITK_MANUAL_INSTANTIATION\r
154 #include "itkBinaryThinningImageFilter3D.txx"\r
155 #endif\r
156 \r
157 #endif\r