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