]> Creatis software - clitk.git/blob - segmentation/clitkExtractBonesFilter.h
2205ea32e41bdafb4009e7d099f868568ba97a3d
[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://oncora1.lyon.fnclcc.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 labelling.
37   */
38   //--------------------------------------------------------------------
39   
40   template <class TInputImageType>
41   class ITK_EXPORT ExtractBonesFilter: 
42     public virtual clitk::FilterBase, 
43     public clitk::FilterWithAnatomicalFeatureDatabaseManagement,
44     public itk::ImageToImageFilter<TInputImageType, 
45                                    itk::Image<uchar, TInputImageType::ImageDimension> > 
46   {
47     
48   public:
49     /** Standard class typedefs. */
50     typedef itk::Image<uchar, TInputImageType::ImageDimension>      MaskImageType;
51     typedef ExtractBonesFilter                                      Self;
52     typedef itk::ImageToImageFilter<TInputImageType, MaskImageType> Superclass;
53     typedef itk::SmartPointer<Self>                                 Pointer;
54     typedef itk::SmartPointer<const Self>                           ConstPointer;
55     
56     /** Method for creation through the object factory. */
57     itkNewMacro(Self);  
58     
59     /** Run-time type information (and related methods). */
60     itkTypeMacro(ExtractBonesFilter, ImageToImageFilter);
61     FILTERBASE_INIT;
62
63     /** Some convenient typedefs */
64     typedef TInputImageType                       InputImageType;
65     typedef typename InputImageType::ConstPointer InputImageConstPointer;
66     typedef typename InputImageType::Pointer      InputImagePointer;
67     typedef typename InputImageType::RegionType   InputImageRegionType; 
68     typedef typename InputImageType::PixelType    InputImagePixelType; 
69     typedef typename InputImageType::SizeType     InputImageSizeType; 
70     typedef typename InputImageType::IndexType    InputImageIndexType; 
71         
72     typedef typename MaskImageType::ConstPointer MaskImageConstPointer;
73     typedef typename MaskImageType::Pointer      MaskImagePointer;
74     typedef typename MaskImageType::RegionType   MaskImageRegionType; 
75     typedef typename MaskImageType::PixelType    MaskImagePixelType; 
76     typedef typename MaskImageType::SizeType     MaskImageSizeType; 
77     typedef typename MaskImageType::IndexType    MaskImageIndexType; 
78
79     itkStaticConstMacro(ImageDimension, unsigned int, InputImageType::ImageDimension);
80     typedef int InternalPixelType;
81     typedef itk::Image<InternalPixelType, InputImageType::ImageDimension> InternalImageType;
82     typedef typename InternalImageType::Pointer                           InternalImagePointer;
83     typedef typename InternalImageType::IndexType                         InternalIndexType;
84     typedef LabelizeParameters<InternalPixelType>                         LabelParamType;
85     
86     /** Connect inputs */
87     void SetInput(const InputImageType * image);
88  
89     // Set all options at a time
90     template<class ArgsInfoType>
91       void SetArgsInfo(ArgsInfoType arg);
92
93     // Background / Foreground
94     itkGetConstMacro(BackgroundValue, MaskImagePixelType);
95     itkGetConstMacro(ForegroundValue, MaskImagePixelType);
96
97     itkSetMacro(MinimalComponentSize, int);
98     itkGetConstMacro(MinimalComponentSize, int);
99     GGO_DefineOption(minSize, SetMinimalComponentSize, int);
100     
101     // Output filename  (for AFBD)
102     itkSetMacro(OutputBonesFilename, std::string);
103     itkGetMacro(OutputBonesFilename, std::string);
104     GGO_DefineOption(output, SetOutputBonesFilename, std::string);
105
106     // Step 0
107     itkBooleanMacro(InitialSmoothing);
108     itkSetMacro(InitialSmoothing, bool);
109     itkGetMacro(InitialSmoothing, bool);
110     GGO_DefineOption_Flag(smooth, SetInitialSmoothing);
111
112     itkSetMacro(SmoothingConductanceParameter, double);
113     itkGetConstMacro(SmoothingConductanceParameter, double);
114     GGO_DefineOption(cond, SetSmoothingConductanceParameter, double);
115     
116     itkSetMacro(SmoothingNumberOfIterations, int);
117     itkGetConstMacro(SmoothingNumberOfIterations, int);
118     GGO_DefineOption(iter, SetSmoothingNumberOfIterations, int);
119
120     itkSetMacro(SmoothingTimeStep, double);
121     itkGetConstMacro(SmoothingTimeStep, double);
122     GGO_DefineOption(time, SetSmoothingTimeStep, double);
123
124     itkSetMacro(SmoothingUseImageSpacing, bool);
125     itkGetConstMacro(SmoothingUseImageSpacing, bool);
126     itkBooleanMacro(SmoothingUseImageSpacing);
127     GGO_DefineOption_Flag(spacing, SetSmoothingUseImageSpacing);
128
129     // Step 1 
130     itkSetMacro(UpperThreshold1, InputImagePixelType);
131     itkGetMacro(UpperThreshold1, InputImagePixelType);
132     GGO_DefineOption(upper1, SetUpperThreshold1, InputImagePixelType);
133
134     itkSetMacro(LowerThreshold1, InputImagePixelType);
135     itkGetMacro(LowerThreshold1, InputImagePixelType);
136     GGO_DefineOption(lower1, SetLowerThreshold1, InputImagePixelType);
137
138     itkSetMacro(FullConnectivity, bool);
139     itkGetConstMacro(FullConnectivity, bool);
140     itkBooleanMacro(FullConnectivity);
141     GGO_DefineOption_Flag(full, SetFullConnectivity);
142
143     // Step 2 
144     itkSetMacro(UpperThreshold2, InputImagePixelType);
145     itkGetMacro(UpperThreshold2, InputImagePixelType);
146     GGO_DefineOption(upper2, SetUpperThreshold2, InputImagePixelType);
147
148     itkSetMacro(LowerThreshold2, InputImagePixelType);
149     itkGetMacro(LowerThreshold2, InputImagePixelType);
150     GGO_DefineOption(lower2, SetLowerThreshold2, InputImagePixelType);
151
152     itkSetMacro(Radius2, InputImageSizeType);
153     itkGetConstMacro(Radius2, InputImageSizeType);
154     GGO_DefineOption_Vector(radius2, SetRadius2, InputImageSizeType, ImageDimension, true);
155
156     itkSetMacro(SampleRate2, int);
157     itkGetConstMacro(SampleRate2, int);
158     GGO_DefineOption(sampleRate2, SetSampleRate2, int);
159
160     // Step fill holes
161     itkSetMacro(FillHoles, bool);
162     itkGetConstMacro(FillHoles, bool);
163     itkBooleanMacro(FillHoles);
164     GGO_DefineOption_Flag(doNotFillHoles, SetFillHoles);
165
166     // Step Auto Crop
167     itkSetMacro(AutoCrop, bool);
168     itkGetConstMacro(AutoCrop, bool);
169     itkBooleanMacro(AutoCrop);
170     GGO_DefineOption_Flag(noAutoCrop, SetAutoCrop);
171
172   protected:
173     ExtractBonesFilter();
174     virtual ~ExtractBonesFilter() {}
175     
176     // Global options
177     itkSetMacro(BackgroundValue, MaskImagePixelType);
178     itkSetMacro(ForegroundValue, MaskImagePixelType);
179     MaskImagePixelType m_BackgroundValue;
180     MaskImagePixelType m_ForegroundValue;
181     bool m_AutoCrop;
182
183     // Step 0 : Initial Filtering
184     bool m_InitialSmoothing;
185     double m_SmoothingConductanceParameter;
186     int m_SmoothingNumberOfIterations;
187     double m_SmoothingTimeStep; 
188     bool m_SmoothingUseImageSpacing;
189
190     // Step 1
191     InputImagePixelType m_UpperThreshold1;
192     InputImagePixelType m_LowerThreshold1;
193     int m_MinimalComponentSize;
194     bool m_FullConnectivity;
195
196     // Step 2
197     InputImagePixelType m_UpperThreshold2;
198     InputImagePixelType m_LowerThreshold2;
199     InputImageSizeType m_Radius2;
200     int m_SampleRate2;
201     
202     // Step 
203     bool m_FillHoles;    
204     InputImageSizeType m_FillHolesDirections;
205
206     virtual void GenerateOutputInformation();
207     virtual void GenerateData();
208
209     // Steps
210     void RemoveAir();
211     void FindTrachea();
212     void ExtractBones();
213     void RemoveTrachea();
214     void BonesSeparation();
215     std::string m_OutputBonesFilename;
216     InputImageConstPointer input;
217     InputImagePointer filtered_input;
218     MaskImageConstPointer patient;
219     InputImagePointer working_input;
220     typename InternalImageType::Pointer working_image;  
221     typename InternalImageType::Pointer trachea;
222     typename InternalImageType::Pointer output;
223         
224   private:
225     ExtractBonesFilter(const Self&); //purposely not implemented
226     void operator=(const Self&); //purposely not implemented
227     
228   }; // end class
229   //--------------------------------------------------------------------
230
231 } // end namespace clitk
232 //--------------------------------------------------------------------
233
234 #ifndef ITK_MANUAL_INSTANTIATION
235 #include "clitkExtractBonesFilter.txx"
236 #endif
237
238 #endif