]> Creatis software - clitk.git/blob - segmentation/clitkExtractBonesFilter.h
Merge branch 'master' into ITKv5
[clitk.git] / segmentation / clitkExtractBonesFilter.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
19 #ifndef CLITKEXTRACTBONESSFILTER_H
20 #define CLITKEXTRACTBONESSFILTER_H
21
22 // clitk 
23 #include "clitkFilterBase.h"
24 #include "clitkDecomposeAndReconstructImageFilter.h"
25 #include "clitkExplosionControlledThresholdConnectedImageFilter.h"
26 #include "clitkSegmentationUtils.h"
27 #include "clitkFilterWithAnatomicalFeatureDatabaseManagement.h"
28
29 // itk
30 #include "itkStatisticsImageFilter.h"
31
32 namespace clitk {
33   
34   //--------------------------------------------------------------------
35   /*
36     Extract bony anatomy through thresholding and connected component
37     labelling.
38   */
39   //--------------------------------------------------------------------
40   
41   template <class TInputImageType>
42   class ITK_EXPORT ExtractBonesFilter: 
43     public virtual clitk::FilterBase, 
44     public clitk::FilterWithAnatomicalFeatureDatabaseManagement,
45     public itk::ImageToImageFilter<TInputImageType, 
46                                    itk::Image<uchar, TInputImageType::ImageDimension> > 
47   {
48     
49   public:
50     /** Standard class typedefs. */
51     typedef itk::Image<uchar, TInputImageType::ImageDimension>      MaskImageType;
52     typedef ExtractBonesFilter                                      Self;
53     typedef itk::ImageToImageFilter<TInputImageType, MaskImageType> Superclass;
54     typedef itk::SmartPointer<Self>                                 Pointer;
55     typedef itk::SmartPointer<const Self>                           ConstPointer;
56     
57     /** Method for creation through the object factory. */
58     itkNewMacro(Self);  
59     
60     /** Run-time type information (and related methods). */
61     itkTypeMacro(ExtractBonesFilter, ImageToImageFilter);
62     FILTERBASE_INIT;
63
64     /** Some convenient typedefs */
65     typedef TInputImageType                       InputImageType;
66     typedef typename InputImageType::ConstPointer InputImageConstPointer;
67     typedef typename InputImageType::Pointer      InputImagePointer;
68     typedef typename InputImageType::RegionType   InputImageRegionType; 
69     typedef typename InputImageType::PixelType    InputImagePixelType; 
70     typedef typename InputImageType::SizeType     InputImageSizeType; 
71     typedef typename InputImageType::IndexType    InputImageIndexType; 
72         
73     typedef typename MaskImageType::ConstPointer MaskImageConstPointer;
74     typedef typename MaskImageType::Pointer      MaskImagePointer;
75     typedef typename MaskImageType::RegionType   MaskImageRegionType; 
76     typedef typename MaskImageType::PixelType    MaskImagePixelType; 
77     typedef typename MaskImageType::SizeType     MaskImageSizeType; 
78     typedef typename MaskImageType::IndexType    MaskImageIndexType; 
79
80     itkStaticConstMacro(ImageDimension, unsigned int, InputImageType::ImageDimension);
81     typedef int InternalPixelType;
82     typedef itk::Image<InternalPixelType, InputImageType::ImageDimension> InternalImageType;
83     typedef typename InternalImageType::Pointer                           InternalImagePointer;
84     typedef typename InternalImageType::IndexType                         InternalIndexType;
85     typedef LabelizeParameters<InternalPixelType>                         LabelParamType;
86     
87     /** Connect inputs */
88     void SetInput(const InputImageType * image);
89  
90     // Background / Foreground
91     itkGetConstMacro(BackgroundValue, MaskImagePixelType);
92     itkGetConstMacro(ForegroundValue, MaskImagePixelType);
93
94     itkSetMacro(MinimalComponentSize, int);
95     itkGetConstMacro(MinimalComponentSize, int);
96     
97     // Output filename  (for AFBD)
98     itkSetMacro(OutputBonesFilename, std::string);
99     itkGetMacro(OutputBonesFilename, std::string);
100
101     // Step 0
102     itkBooleanMacro(InitialSmoothing);
103     itkSetMacro(InitialSmoothing, bool);
104     itkGetMacro(InitialSmoothing, bool);
105
106     itkSetMacro(SmoothingConductanceParameter, double);
107     itkGetConstMacro(SmoothingConductanceParameter, double);
108     
109     itkSetMacro(SmoothingNumberOfIterations, int);
110     itkGetConstMacro(SmoothingNumberOfIterations, int);
111
112     itkSetMacro(SmoothingTimeStep, double);
113     itkGetConstMacro(SmoothingTimeStep, double);
114
115     itkSetMacro(SmoothingUseImageSpacing, bool);
116     itkGetConstMacro(SmoothingUseImageSpacing, bool);
117     itkBooleanMacro(SmoothingUseImageSpacing);
118
119     // Step 1 
120     itkSetMacro(UpperThreshold1, InputImagePixelType);
121     itkGetMacro(UpperThreshold1, InputImagePixelType);
122
123     itkSetMacro(LowerThreshold1, InputImagePixelType);
124     itkGetMacro(LowerThreshold1, InputImagePixelType);
125
126     itkSetMacro(FullConnectivity, bool);
127     itkGetConstMacro(FullConnectivity, bool);
128     itkBooleanMacro(FullConnectivity);
129
130     // Step 2 
131     itkSetMacro(UpperThreshold2, InputImagePixelType);
132     itkGetMacro(UpperThreshold2, InputImagePixelType);
133
134     itkSetMacro(LowerThreshold2, InputImagePixelType);
135     itkGetMacro(LowerThreshold2, InputImagePixelType);
136
137     itkSetMacro(Radius2, InputImageSizeType);
138     itkGetConstMacro(Radius2, InputImageSizeType);
139
140     itkSetMacro(SampleRate2, int);
141     itkGetConstMacro(SampleRate2, int);
142
143     // Step fill holes
144     itkSetMacro(FillHoles, bool);
145     itkGetConstMacro(FillHoles, bool);
146     itkBooleanMacro(FillHoles);
147
148     // Step Auto Crop
149     itkSetMacro(AutoCrop, bool);
150     itkGetConstMacro(AutoCrop, bool);
151     itkBooleanMacro(AutoCrop);
152
153   protected:
154     ExtractBonesFilter();
155     virtual ~ExtractBonesFilter() {}
156     
157     // Global options
158     itkSetMacro(BackgroundValue, MaskImagePixelType);
159     itkSetMacro(ForegroundValue, MaskImagePixelType);
160     MaskImagePixelType m_BackgroundValue;
161     MaskImagePixelType m_ForegroundValue;
162     bool m_AutoCrop;
163
164     // Step 0 : Initial Filtering
165     bool m_InitialSmoothing;
166     double m_SmoothingConductanceParameter;
167     int m_SmoothingNumberOfIterations;
168     double m_SmoothingTimeStep; 
169     bool m_SmoothingUseImageSpacing;
170
171     // Step 1
172     InputImagePixelType m_UpperThreshold1;
173     InputImagePixelType m_LowerThreshold1;
174     int m_MinimalComponentSize;
175     bool m_FullConnectivity;
176
177     // Step 2
178     InputImagePixelType m_UpperThreshold2;
179     InputImagePixelType m_LowerThreshold2;
180     InputImageSizeType m_Radius2;
181     int m_SampleRate2;
182     
183     // Step 
184     bool m_FillHoles;    
185     InputImageSizeType m_FillHolesDirections;
186
187     virtual void GenerateOutputInformation();
188     virtual void GenerateData();
189
190     // Steps
191     void RemoveAir();
192     void FindTrachea();
193     void ExtractBones();
194     void RemoveTrachea();
195     void BonesSeparation();
196     std::string m_OutputBonesFilename;
197     InputImageConstPointer input;
198     InputImagePointer filtered_input;
199     MaskImageConstPointer patient;
200     InputImagePointer working_input;
201     typename InternalImageType::Pointer working_image;  
202     typename InternalImageType::Pointer trachea;
203     typename InternalImageType::Pointer output;
204         
205   private:
206     ExtractBonesFilter(const Self&); //purposely not implemented
207     void operator=(const Self&); //purposely not implemented
208     
209   }; // end class
210   //--------------------------------------------------------------------
211
212 } // end namespace clitk
213 //--------------------------------------------------------------------
214
215 #ifndef ITK_MANUAL_INSTANTIATION
216 #include "clitkExtractBonesFilter.txx"
217 #endif
218
219 #endif