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 CLITKEXTRACTPATIENTFILTER_H
20 #define CLITKEXTRACTPATIENTFILTER_H
22 #include "clitkFilterBase.h"
26 //--------------------------------------------------------------------
28 Try to extract the Patient part of a thorax CT.
30 Prefer high resolution input and resample (NN) output at the end
31 (like). Input is binarized using initial thresholds, connected
32 components are labeled (firstLabel). The air label (1) is
33 removed. The remaining is binarized and relabeled, patient should
34 now be the principal label (secondLabel). Two mechanismes are
35 provided to influence the label images. Crop to reduce
36 connectivity (image is restored to original size), eg for
37 SBF. Decomposition through ersion and reconstruction through
38 dilation (slow), eg for Pulmo bellows. Choose which labels to keep
39 from second Label image. Final mask is cleaned by opening and
43 //--------------------------------------------------------------------
45 template <class TInputImageType, class TOutputImageType>
46 class ITK_EXPORT ExtractPatientFilter:
47 public clitk::FilterBase,
48 public itk::ImageToImageFilter<TInputImageType, TOutputImageType>
51 /** Standard class typedefs. */
52 typedef ExtractPatientFilter Self;
53 typedef itk::ImageToImageFilter<TInputImageType, TOutputImageType> Superclass;
54 typedef itk::SmartPointer<Self> Pointer;
55 typedef itk::SmartPointer<const Self> ConstPointer;
57 /** Method for creation through the object factory. */
60 /** Run-time type information (and related methods). */
61 itkTypeMacro(ExtractPatientFilter, ImageToImageFilter);
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;
73 typedef TOutputImageType OutputImageType;
74 typedef typename OutputImageType::ConstPointer OutputImageConstPointer;
75 typedef typename OutputImageType::Pointer OutputImagePointer;
76 typedef typename OutputImageType::RegionType OutputImageRegionType;
77 typedef typename OutputImageType::PixelType OutputImagePixelType;
78 typedef typename OutputImageType::SizeType OutputImageSizeType;
79 typedef typename OutputImageType::IndexType OutputImageIndexType;
81 itkStaticConstMacro(ImageDimension, unsigned int, InputImageType::ImageDimension);
82 typedef int InternalPixelType;
83 typedef itk::Image<InternalPixelType, ImageDimension> InternalImageType;
84 typedef typename InternalImageType::SizeType InternalImageSizeType;
87 void SetInput(const TInputImageType * image);
89 // Set all options at a time
90 template<class ArgsInfoType>
91 void SetArgsInfo(ArgsInfoType arg);
94 itkSetMacro(UpperThreshold, InputImagePixelType);
95 itkGetMacro(UpperThreshold, InputImagePixelType);
96 GGO_DefineOption(upper, SetUpperThreshold, InputImagePixelType);
98 itkSetMacro(LowerThreshold, InputImagePixelType);
99 itkGetMacro(LowerThreshold, InputImagePixelType);
100 itkSetMacro(UseLowerThreshold, bool);
101 itkGetConstMacro(UseLowerThreshold, bool);
102 itkBooleanMacro(UseLowerThreshold);
103 GGO_DefineOption_WithTest(lower, SetLowerThreshold, InputImagePixelType, UseLowerThreshold);
106 itkSetMacro(DecomposeAndReconstructDuringFirstStep, bool);
107 itkGetConstMacro(DecomposeAndReconstructDuringFirstStep, bool);
108 itkBooleanMacro(DecomposeAndReconstructDuringFirstStep);
109 GGO_DefineOption_Flag(erode1, SetDecomposeAndReconstructDuringFirstStep);
111 itkSetMacro(Radius1, InternalImageSizeType);
112 itkGetConstMacro(Radius1, InternalImageSizeType);
113 GGO_DefineOption_Vector(radius1, SetRadius1, InternalImageSizeType, ImageDimension, true);
115 itkSetMacro(MaximumNumberOfLabels1, int);
116 itkGetConstMacro(MaximumNumberOfLabels1, int);
117 GGO_DefineOption(max1, SetMaximumNumberOfLabels1, int);
119 itkSetMacro(NumberOfNewLabels1, int);
120 itkGetConstMacro(NumberOfNewLabels1, int);
121 GGO_DefineOption(new1, SetNumberOfNewLabels1, int);
124 itkSetMacro(DecomposeAndReconstructDuringSecondStep, bool);
125 itkGetConstMacro(DecomposeAndReconstructDuringSecondStep, bool);
126 itkBooleanMacro(DecomposeAndReconstructDuringSecondStep);
127 GGO_DefineOption_Flag(erode2, SetDecomposeAndReconstructDuringSecondStep);
129 itkSetMacro(Radius2, InternalImageSizeType);
130 itkGetConstMacro(Radius2, InternalImageSizeType);
131 GGO_DefineOption_Vector(radius2, SetRadius2, InternalImageSizeType, ImageDimension, true)
133 itkSetMacro(MaximumNumberOfLabels2, int);
134 itkGetConstMacro(MaximumNumberOfLabels2, int);
135 GGO_DefineOption(max2, SetMaximumNumberOfLabels2, int);
137 itkSetMacro(NumberOfNewLabels2, int);
138 itkGetConstMacro(NumberOfNewLabels2, int);
139 GGO_DefineOption(new2, SetNumberOfNewLabels2, int);
142 itkSetMacro(FirstKeep, int);
143 itkGetConstMacro(FirstKeep, int);
144 GGO_DefineOption(firstKeep, SetFirstKeep, int);
146 itkSetMacro(LastKeep, int);
147 itkGetConstMacro(LastKeep, int);
148 GGO_DefineOption(lastKeep, SetLastKeep, int);
151 itkSetMacro(FinalOpenClose, bool);
152 itkGetConstMacro(FinalOpenClose, bool);
153 itkBooleanMacro(FinalOpenClose);
154 GGO_DefineOption_Flag(openClose, SetFinalOpenClose);
157 itkSetMacro(AutoCrop, bool);
158 itkGetConstMacro(AutoCrop, bool);
159 itkBooleanMacro(AutoCrop);
160 GGO_DefineOption_Flag(autoCrop, SetAutoCrop);
163 ExtractPatientFilter();
164 virtual ~ExtractPatientFilter() {}
166 itkSetMacro(BackgroundValue, OutputImagePixelType);
167 itkSetMacro(ForegroundValue, OutputImagePixelType);
168 itkGetConstMacro(BackgroundValue, OutputImagePixelType);
169 itkGetConstMacro(ForegroundValue, OutputImagePixelType);
170 OutputImagePixelType m_BackgroundValue;
171 OutputImagePixelType m_ForegroundValue;
173 InputImagePixelType m_UpperThreshold;
174 InputImagePixelType m_LowerThreshold;
175 bool m_UseLowerThreshold;
176 bool m_DecomposeAndReconstructDuringFirstStep;
177 bool m_DecomposeAndReconstructDuringSecondStep;
178 bool m_FinalOpenClose;
179 InternalImageSizeType m_Radius1;
180 InternalImageSizeType m_Radius2;
181 int m_MaximumNumberOfLabels1;
182 int m_MaximumNumberOfLabels2;
183 int m_NumberOfNewLabels1;
184 int m_NumberOfNewLabels2;
189 virtual void GenerateOutputInformation();
190 virtual void GenerateData();
192 InputImageConstPointer input;
193 OutputImagePointer output;
194 typename InternalImageType::Pointer working_image;
197 ExtractPatientFilter(const Self&); //purposely not implemented
198 void operator=(const Self&); //purposely not implemented
201 //--------------------------------------------------------------------
203 } // end namespace clitk
204 //--------------------------------------------------------------------
206 #ifndef ITK_MANUAL_INSTANTIATION
207 #include "clitkExtractPatientFilter.txx"