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"
23 #include "clitkFilterWithAnatomicalFeatureDatabaseManagement.h"
27 //--------------------------------------------------------------------
29 Try to extract the Patient part of a thorax CT.
31 Prefer high resolution input and resample (NN) output at the end
32 (like). Input is binarized using initial thresholds, connected
33 components are labeled (firstLabel). The air label (1) is
34 removed. The remaining is binarized and relabeled, patient should
35 now be the principal label (secondLabel). Two mechanismes are
36 provided to influence the label images. Crop to reduce
37 connectivity (image is restored to original size), eg for
38 SBF. Decomposition through ersion and reconstruction through
39 dilation (slow), eg for Pulmo bellows. Choose which labels to keep
40 from second Label image. Final mask is cleaned by opening and
44 //--------------------------------------------------------------------
46 template <class TInputImageType>
47 class ITK_EXPORT ExtractPatientFilter:
48 public virtual clitk::FilterBase,
49 public clitk::FilterWithAnatomicalFeatureDatabaseManagement,
50 public itk::ImageToImageFilter<TInputImageType,
51 itk::Image<uchar, TInputImageType::ImageDimension> >
54 /** Standard class typedefs. */
55 typedef itk::Image<uchar, TInputImageType::ImageDimension> MaskImageType;
56 typedef ExtractPatientFilter Self;
57 typedef itk::ImageToImageFilter<TInputImageType, MaskImageType> Superclass;
58 typedef itk::SmartPointer<Self> Pointer;
59 typedef itk::SmartPointer<const Self> ConstPointer;
61 /** Method for creation through the object factory. */
64 /** Run-time type information (and related methods). */
65 itkTypeMacro(ExtractPatientFilter, ImageToImageFilter);
68 /** Some convenient typedefs. */
69 typedef TInputImageType InputImageType;
70 typedef typename InputImageType::ConstPointer InputImageConstPointer;
71 typedef typename InputImageType::Pointer InputImagePointer;
72 typedef typename InputImageType::RegionType InputImageRegionType;
73 typedef typename InputImageType::PixelType InputImagePixelType;
74 typedef typename InputImageType::SizeType InputImageSizeType;
75 typedef typename InputImageType::IndexType InputImageIndexType;
77 typedef typename MaskImageType::ConstPointer MaskImageConstPointer;
78 typedef typename MaskImageType::Pointer MaskImagePointer;
79 typedef typename MaskImageType::RegionType MaskImageRegionType;
80 typedef typename MaskImageType::PixelType MaskImagePixelType;
81 typedef typename MaskImageType::SizeType MaskImageSizeType;
82 typedef typename MaskImageType::IndexType MaskImageIndexType;
84 itkStaticConstMacro(ImageDimension, unsigned int, InputImageType::ImageDimension);
85 typedef int InternalPixelType;
86 typedef itk::Image<InternalPixelType, ImageDimension> InternalImageType;
87 typedef typename InternalImageType::SizeType InternalImageSizeType;
90 void SetInput(const TInputImageType * image);
91 itkSetMacro(OutputPatientFilename, std::string);
92 itkGetMacro(OutputPatientFilename, std::string);
93 GGO_DefineOption(output, SetOutputPatientFilename, std::string);
95 // Set all options at a time
96 template<class ArgsInfoType>
97 void SetArgsInfo(ArgsInfoType arg);
100 itkSetMacro(UpperThreshold, InputImagePixelType);
101 itkGetMacro(UpperThreshold, InputImagePixelType);
102 GGO_DefineOption(upper, SetUpperThreshold, InputImagePixelType);
104 itkSetMacro(LowerThreshold, InputImagePixelType);
105 itkGetMacro(LowerThreshold, InputImagePixelType);
106 itkSetMacro(UseLowerThreshold, bool);
107 itkGetConstMacro(UseLowerThreshold, bool);
108 itkBooleanMacro(UseLowerThreshold);
109 GGO_DefineOption_WithTest(lower, SetLowerThreshold, InputImagePixelType, UseLowerThreshold);
112 itkSetMacro(DecomposeAndReconstructDuringFirstStep, bool);
113 itkGetConstMacro(DecomposeAndReconstructDuringFirstStep, bool);
114 itkBooleanMacro(DecomposeAndReconstructDuringFirstStep);
115 GGO_DefineOption_Flag(erode1, SetDecomposeAndReconstructDuringFirstStep);
117 itkSetMacro(Radius1, InternalImageSizeType);
118 itkGetConstMacro(Radius1, InternalImageSizeType);
119 GGO_DefineOption_Vector(radius1, SetRadius1, InternalImageSizeType, ImageDimension, true);
121 itkSetMacro(MaximumNumberOfLabels1, int);
122 itkGetConstMacro(MaximumNumberOfLabels1, int);
123 GGO_DefineOption(max1, SetMaximumNumberOfLabels1, int);
125 itkSetMacro(NumberOfNewLabels1, int);
126 itkGetConstMacro(NumberOfNewLabels1, int);
127 GGO_DefineOption(new1, SetNumberOfNewLabels1, int);
130 itkSetMacro(DecomposeAndReconstructDuringSecondStep, bool);
131 itkGetConstMacro(DecomposeAndReconstructDuringSecondStep, bool);
132 itkBooleanMacro(DecomposeAndReconstructDuringSecondStep);
133 GGO_DefineOption_Flag(erode2, SetDecomposeAndReconstructDuringSecondStep);
135 itkSetMacro(Radius2, InternalImageSizeType);
136 itkGetConstMacro(Radius2, InternalImageSizeType);
137 GGO_DefineOption_Vector(radius2, SetRadius2, InternalImageSizeType, ImageDimension, true)
139 itkSetMacro(MaximumNumberOfLabels2, int);
140 itkGetConstMacro(MaximumNumberOfLabels2, int);
141 GGO_DefineOption(max2, SetMaximumNumberOfLabels2, int);
143 itkSetMacro(NumberOfNewLabels2, int);
144 itkGetConstMacro(NumberOfNewLabels2, int);
145 GGO_DefineOption(new2, SetNumberOfNewLabels2, int);
148 itkSetMacro(FirstKeep, int);
149 itkGetConstMacro(FirstKeep, int);
150 GGO_DefineOption(firstKeep, SetFirstKeep, int);
152 itkSetMacro(LastKeep, int);
153 itkGetConstMacro(LastKeep, int);
154 GGO_DefineOption(lastKeep, SetLastKeep, int);
157 itkSetMacro(FinalOpenClose, bool);
158 itkGetConstMacro(FinalOpenClose, bool);
159 itkBooleanMacro(FinalOpenClose);
160 GGO_DefineOption_Flag(openClose, SetFinalOpenClose);
163 itkSetMacro(AutoCrop, bool);
164 itkGetConstMacro(AutoCrop, bool);
165 itkBooleanMacro(AutoCrop);
166 GGO_DefineOption_Flag(noAutoCrop, SetAutoCrop);
169 ExtractPatientFilter();
170 virtual ~ExtractPatientFilter() {}
172 itkSetMacro(BackgroundValue, MaskImagePixelType);
173 itkSetMacro(ForegroundValue, MaskImagePixelType);
174 itkGetConstMacro(BackgroundValue, MaskImagePixelType);
175 itkGetConstMacro(ForegroundValue, MaskImagePixelType);
176 MaskImagePixelType m_BackgroundValue;
177 MaskImagePixelType m_ForegroundValue;
179 std::string m_OutputPatientFilename;
180 InputImagePixelType m_UpperThreshold;
181 InputImagePixelType m_LowerThreshold;
182 bool m_UseLowerThreshold;
183 bool m_DecomposeAndReconstructDuringFirstStep;
184 bool m_DecomposeAndReconstructDuringSecondStep;
185 bool m_FinalOpenClose;
186 InternalImageSizeType m_Radius1;
187 InternalImageSizeType m_Radius2;
188 int m_MaximumNumberOfLabels1;
189 int m_MaximumNumberOfLabels2;
190 int m_NumberOfNewLabels1;
191 int m_NumberOfNewLabels2;
196 virtual void GenerateOutputInformation();
197 virtual void GenerateData();
199 InputImageConstPointer input;
200 MaskImagePointer output;
201 typename InternalImageType::Pointer working_image;
204 ExtractPatientFilter(const Self&); //purposely not implemented
205 void operator=(const Self&); //purposely not implemented
208 //--------------------------------------------------------------------
210 } // end namespace clitk
211 //--------------------------------------------------------------------
213 #ifndef ITK_MANUAL_INSTANTIATION
214 #include "clitkExtractPatientFilter.txx"