1 /*=========================================================================
2 Program: vv http://www.creatis.insa-lyon.fr/rio/vv
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
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.
13 It is distributed under dual licence
15 - BSD See included LICENSE.txt file
16 - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html
17 ======================================================================-====*/
19 #ifndef CLITKEXTRACTBONESSFILTER_H
20 #define CLITKEXTRACTBONESSFILTER_H
23 #include "clitkFilterBase.h"
24 #include "clitkDecomposeAndReconstructImageFilter.h"
25 #include "clitkExplosionControlledThresholdConnectedImageFilter.h"
26 #include "clitkSegmentationUtils.h"
27 #include "clitkFilterWithAnatomicalFeatureDatabaseManagement.h"
30 #include "itkStatisticsImageFilter.h"
34 //--------------------------------------------------------------------
36 Extract bony anatomy through thresholding and connected component labelling.
38 //--------------------------------------------------------------------
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> >
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;
56 /** Method for creation through the object factory. */
59 /** Run-time type information (and related methods). */
60 itkTypeMacro(ExtractBonesFilter, ImageToImageFilter);
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;
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;
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;
87 void SetInput(const InputImageType * image);
89 // Set all options at a time
90 template<class ArgsInfoType>
91 void SetArgsInfo(ArgsInfoType arg);
93 // Background / Foreground
94 itkGetConstMacro(BackgroundValue, MaskImagePixelType);
95 itkGetConstMacro(ForegroundValue, MaskImagePixelType);
97 itkSetMacro(MinimalComponentSize, int);
98 itkGetConstMacro(MinimalComponentSize, int);
99 GGO_DefineOption(minSize, SetMinimalComponentSize, int);
101 // Output filename (for AFBD)
102 itkSetMacro(OutputBonesFilename, std::string);
103 itkGetMacro(OutputBonesFilename, std::string);
104 GGO_DefineOption(output, SetOutputBonesFilename, std::string);
107 itkBooleanMacro(InitialSmoothing);
108 itkSetMacro(InitialSmoothing, bool);
109 itkGetMacro(InitialSmoothing, bool);
110 GGO_DefineOption_Flag(smooth, SetInitialSmoothing);
112 itkSetMacro(SmoothingConductanceParameter, double);
113 itkGetConstMacro(SmoothingConductanceParameter, double);
114 GGO_DefineOption(cond, SetSmoothingConductanceParameter, double);
116 itkSetMacro(SmoothingNumberOfIterations, int);
117 itkGetConstMacro(SmoothingNumberOfIterations, int);
118 GGO_DefineOption(iter, SetSmoothingNumberOfIterations, int);
120 itkSetMacro(SmoothingTimeStep, double);
121 itkGetConstMacro(SmoothingTimeStep, double);
122 GGO_DefineOption(time, SetSmoothingTimeStep, double);
124 itkSetMacro(SmoothingUseImageSpacing, bool);
125 itkGetConstMacro(SmoothingUseImageSpacing, bool);
126 itkBooleanMacro(SmoothingUseImageSpacing);
127 GGO_DefineOption_Flag(spacing, SetSmoothingUseImageSpacing);
130 itkSetMacro(UpperThreshold1, InputImagePixelType);
131 itkGetMacro(UpperThreshold1, InputImagePixelType);
132 GGO_DefineOption(upper1, SetUpperThreshold1, InputImagePixelType);
134 itkSetMacro(LowerThreshold1, InputImagePixelType);
135 itkGetMacro(LowerThreshold1, InputImagePixelType);
136 GGO_DefineOption(lower1, SetLowerThreshold1, InputImagePixelType);
138 itkSetMacro(FullConnectivity, bool);
139 itkGetConstMacro(FullConnectivity, bool);
140 itkBooleanMacro(FullConnectivity);
141 GGO_DefineOption_Flag(full, SetFullConnectivity);
144 itkSetMacro(UpperThreshold2, InputImagePixelType);
145 itkGetMacro(UpperThreshold2, InputImagePixelType);
146 GGO_DefineOption(upper2, SetUpperThreshold2, InputImagePixelType);
148 itkSetMacro(LowerThreshold2, InputImagePixelType);
149 itkGetMacro(LowerThreshold2, InputImagePixelType);
150 GGO_DefineOption(lower2, SetLowerThreshold2, InputImagePixelType);
152 itkSetMacro(Radius2, InputImageSizeType);
153 itkGetConstMacro(Radius2, InputImageSizeType);
154 GGO_DefineOption_Vector(radius2, SetRadius2, InputImageSizeType, ImageDimension, true);
156 itkSetMacro(SampleRate2, int);
157 itkGetConstMacro(SampleRate2, int);
158 GGO_DefineOption(sampleRate2, SetSampleRate2, int);
161 itkSetMacro(FillHoles, bool);
162 itkGetConstMacro(FillHoles, bool);
163 itkBooleanMacro(FillHoles);
164 GGO_DefineOption_Flag(doNotFillHoles, SetFillHoles);
167 itkSetMacro(AutoCrop, bool);
168 itkGetConstMacro(AutoCrop, bool);
169 itkBooleanMacro(AutoCrop);
170 GGO_DefineOption_Flag(noAutoCrop, SetAutoCrop);
173 ExtractBonesFilter();
174 virtual ~ExtractBonesFilter() {}
177 itkSetMacro(BackgroundValue, MaskImagePixelType);
178 itkSetMacro(ForegroundValue, MaskImagePixelType);
179 MaskImagePixelType m_BackgroundValue;
180 MaskImagePixelType m_ForegroundValue;
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;
191 InputImagePixelType m_UpperThreshold1;
192 InputImagePixelType m_LowerThreshold1;
193 int m_MinimalComponentSize;
194 bool m_FullConnectivity;
197 InputImagePixelType m_UpperThreshold2;
198 InputImagePixelType m_LowerThreshold2;
199 InputImageSizeType m_Radius2;
204 InputImageSizeType m_FillHolesDirections;
206 virtual void GenerateOutputInformation();
207 virtual void GenerateData();
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;
225 ExtractBonesFilter(const Self&); //purposely not implemented
226 void operator=(const Self&); //purposely not implemented
229 //--------------------------------------------------------------------
231 } // end namespace clitk
232 //--------------------------------------------------------------------
234 #ifndef ITK_MANUAL_INSTANTIATION
235 #include "clitkExtractBonesFilter.txx"