]> Creatis software - clitk.git/blob - segmentation/clitkExtractBonesFilter.h
add smooth option to extract bones
[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
28 // itk
29 #include "itkStatisticsImageFilter.h"
30
31 namespace clitk {
32   
33   //--------------------------------------------------------------------
34   /*
35     Extract bony anatomy through thresholding and connected component labelling.
36   */
37   //--------------------------------------------------------------------
38   
39   template <class TInputImageType, class TOutputImageType>
40   class ITK_EXPORT ExtractBonesFilter: 
41     public clitk::FilterBase, 
42     public itk::ImageToImageFilter<TInputImageType, TOutputImageType> 
43   {
44     
45   public:
46     /** Standard class typedefs. */
47     typedef ExtractBonesFilter              Self;
48     typedef itk::ImageToImageFilter<TInputImageType, TOutputImageType> Superclass;
49     typedef itk::SmartPointer<Self>         Pointer;
50     typedef itk::SmartPointer<const Self>   ConstPointer;
51     
52     /** Method for creation through the object factory. */
53     itkNewMacro(Self);  
54     
55     /** Run-time type information (and related methods). */
56     itkTypeMacro(ExtractBonesFilter, ImageToImageFilter);
57     FILTERBASE_INIT;
58
59     /** Some convenient typedefs */
60     typedef TInputImageType                       InputImageType;
61     typedef typename InputImageType::ConstPointer InputImageConstPointer;
62     typedef typename InputImageType::Pointer      InputImagePointer;
63     typedef typename InputImageType::RegionType   InputImageRegionType; 
64     typedef typename InputImageType::PixelType    InputImagePixelType; 
65     typedef typename InputImageType::SizeType     InputImageSizeType; 
66     typedef typename InputImageType::IndexType    InputImageIndexType; 
67         
68     typedef TOutputImageType                       OutputImageType;
69     typedef typename OutputImageType::ConstPointer OutputImageConstPointer;
70     typedef typename OutputImageType::Pointer      OutputImagePointer;
71     typedef typename OutputImageType::RegionType   OutputImageRegionType; 
72     typedef typename OutputImageType::PixelType    OutputImagePixelType; 
73     typedef typename OutputImageType::SizeType     OutputImageSizeType; 
74     typedef typename OutputImageType::IndexType    OutputImageIndexType; 
75
76     itkStaticConstMacro(ImageDimension, unsigned int, InputImageType::ImageDimension);
77     typedef int InternalPixelType;
78     typedef itk::Image<InternalPixelType, InputImageType::ImageDimension> InternalImageType;
79     typedef typename InternalImageType::Pointer                           InternalImagePointer;
80     typedef typename InternalImageType::IndexType                         InternalIndexType;
81     typedef LabelizeParameters<InternalPixelType>                         LabelParamType;
82     
83     /** Connect inputs */
84     void SetInput(const InputImageType * image);
85  
86     // Set all options at a time
87     template<class ArgsInfoType>
88       void SetArgsInfo(ArgsInfoType arg);
89
90     // Background / Foreground
91     itkGetConstMacro(BackgroundValue, OutputImagePixelType);
92     itkGetConstMacro(ForegroundValue, OutputImagePixelType);
93
94     itkSetMacro(MinimalComponentSize, int);
95     itkGetConstMacro(MinimalComponentSize, int);
96     GGO_DefineOption(minSize, SetMinimalComponentSize, int);
97
98     // Step 0
99     itkBooleanMacro(InitialSmoothing);
100     itkSetMacro(InitialSmoothing, bool);
101     itkGetMacro(InitialSmoothing, bool);
102     GGO_DefineOption_Flag(smooth, SetInitialSmoothing);
103
104     itkSetMacro(SmoothingConductanceParameter, double);
105     itkGetConstMacro(SmoothingConductanceParameter, double);
106     GGO_DefineOption(cond, SetSmoothingConductanceParameter, double);
107     
108     itkSetMacro(SmoothingNumberOfIterations, int);
109     itkGetConstMacro(SmoothingNumberOfIterations, int);
110     GGO_DefineOption(iter, SetSmoothingNumberOfIterations, int);
111
112     itkSetMacro(SmoothingTimeStep, double);
113     itkGetConstMacro(SmoothingTimeStep, double);
114     GGO_DefineOption(time, SetSmoothingTimeStep, double);
115
116     itkSetMacro(SmoothingUseImageSpacing, bool);
117     itkGetConstMacro(SmoothingUseImageSpacing, bool);
118     itkBooleanMacro(SmoothingUseImageSpacing);
119     GGO_DefineOption_Flag(spacing, SetSmoothingUseImageSpacing);
120
121     // Step 1 
122     itkSetMacro(UpperThreshold1, InputImagePixelType);
123     itkGetMacro(UpperThreshold1, InputImagePixelType);
124     GGO_DefineOption(upper1, SetUpperThreshold1, InputImagePixelType);
125
126     itkSetMacro(LowerThreshold1, InputImagePixelType);
127     itkGetMacro(LowerThreshold1, InputImagePixelType);
128     GGO_DefineOption(lower1, SetLowerThreshold1, InputImagePixelType);
129
130     itkSetMacro(FullConnectivity, bool);
131     itkGetConstMacro(FullConnectivity, bool);
132     itkBooleanMacro(FullConnectivity);
133     GGO_DefineOption_Flag(full, SetFullConnectivity);
134
135     // Step 2 
136     itkSetMacro(UpperThreshold2, InputImagePixelType);
137     itkGetMacro(UpperThreshold2, InputImagePixelType);
138     GGO_DefineOption(upper2, SetUpperThreshold2, InputImagePixelType);
139
140     itkSetMacro(LowerThreshold2, InputImagePixelType);
141     itkGetMacro(LowerThreshold2, InputImagePixelType);
142     GGO_DefineOption(lower2, SetLowerThreshold2, InputImagePixelType);
143
144     itkSetMacro(Radius2, InputImageSizeType);
145     itkGetConstMacro(Radius2, InputImageSizeType);
146     GGO_DefineOption_Vector(radius2, SetRadius2, InputImageSizeType, ImageDimension, true);
147
148     itkSetMacro(SampleRate2, int);
149     itkGetConstMacro(SampleRate2, int);
150     GGO_DefineOption(sampleRate2, SetSampleRate2, int);
151
152     // Final Step
153     itkSetMacro(AutoCrop, bool);
154     itkGetConstMacro(AutoCrop, bool);
155     itkBooleanMacro(AutoCrop);
156     GGO_DefineOption_Flag(autoCrop, SetAutoCrop);
157
158   protected:
159     ExtractBonesFilter();
160     virtual ~ExtractBonesFilter() {}
161     
162     // Global options
163     itkSetMacro(BackgroundValue, OutputImagePixelType);
164     itkSetMacro(ForegroundValue, OutputImagePixelType);
165     OutputImagePixelType m_BackgroundValue;
166     OutputImagePixelType m_ForegroundValue;
167     bool m_AutoCrop;
168
169     // Step 0 : Initial Filtering
170     bool m_InitialSmoothing;
171     double m_SmoothingConductanceParameter;
172     int m_SmoothingNumberOfIterations;
173     double m_SmoothingTimeStep; 
174     bool m_SmoothingUseImageSpacing;
175
176     // Step 1
177     InputImagePixelType m_UpperThreshold1;
178     InputImagePixelType m_LowerThreshold1;
179     int m_MinimalComponentSize;
180     bool m_FullConnectivity;
181
182     // Step 2
183     InputImagePixelType m_UpperThreshold2;
184     InputImagePixelType m_LowerThreshold2;
185     InputImageSizeType m_Radius2;
186     int m_SampleRate2;
187     
188     virtual void GenerateOutputInformation();
189     virtual void GenerateData();
190
191     // Steps
192     void RemoveAir();
193     void FindTrachea();
194     void ExtractBones();
195     void RemoveTrachea();
196     void BonesSeparation();
197     InputImageConstPointer input;
198     InputImagePointer filtered_input;
199     OutputImageConstPointer 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