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"
24 #include "clitkSegmentationUtils.h"
28 //--------------------------------------------------------------------
30 Try to extract the Patient part of a thorax CT.
32 Prefer high resolution input and resample (NN) output at the end
33 (like). Input is binarized using initial thresholds, connected
34 components are labeled (firstLabel). The air label (1) is
35 removed. The remaining is binarized and relabeled, patient should
36 now be the principal label (secondLabel). Two mechanismes are
37 provided to influence the label images. Crop to reduce
38 connectivity (image is restored to original size), eg for
39 SBF. Decomposition through ersion and reconstruction through
40 dilation (slow), eg for Pulmo bellows. Choose which labels to keep
41 from second Label image. Final mask is cleaned by opening and
45 //--------------------------------------------------------------------
47 template <class TInputImageType>
48 class ITK_EXPORT ExtractPatientFilter:
49 public virtual clitk::FilterBase,
50 public clitk::FilterWithAnatomicalFeatureDatabaseManagement,
51 public itk::ImageToImageFilter<TInputImageType,
52 itk::Image<uchar, TInputImageType::ImageDimension> >
55 /** Standard class typedefs. */
56 typedef itk::Image<uchar, TInputImageType::ImageDimension> MaskImageType;
57 typedef ExtractPatientFilter Self;
58 typedef itk::ImageToImageFilter<TInputImageType, MaskImageType> Superclass;
59 typedef itk::SmartPointer<Self> Pointer;
60 typedef itk::SmartPointer<const Self> ConstPointer;
62 /** Method for creation through the object factory. */
65 /** Run-time type information (and related methods). */
66 itkTypeMacro(ExtractPatientFilter, ImageToImageFilter);
69 /** Some convenient typedefs. */
70 typedef TInputImageType InputImageType;
71 typedef typename InputImageType::ConstPointer InputImageConstPointer;
72 typedef typename InputImageType::Pointer InputImagePointer;
73 typedef typename InputImageType::RegionType InputImageRegionType;
74 typedef typename InputImageType::PixelType InputImagePixelType;
75 typedef typename InputImageType::SizeType InputImageSizeType;
76 typedef typename InputImageType::IndexType InputImageIndexType;
78 typedef typename MaskImageType::ConstPointer MaskImageConstPointer;
79 typedef typename MaskImageType::Pointer MaskImagePointer;
80 typedef typename MaskImageType::RegionType MaskImageRegionType;
81 typedef typename MaskImageType::PixelType MaskImagePixelType;
82 typedef typename MaskImageType::SizeType MaskImageSizeType;
83 typedef typename MaskImageType::IndexType MaskImageIndexType;
85 itkStaticConstMacro(ImageDimension, unsigned int, InputImageType::ImageDimension);
86 typedef int InternalPixelType;
87 typedef itk::Image<InternalPixelType, ImageDimension> InternalImageType;
88 typedef typename InternalImageType::SizeType InternalImageSizeType;
91 void SetInput(const TInputImageType * image);
92 itkSetMacro(OutputPatientFilename, std::string);
93 itkGetMacro(OutputPatientFilename, std::string);
96 itkSetMacro(UpperThreshold, InputImagePixelType);
97 itkGetMacro(UpperThreshold, InputImagePixelType);
99 itkSetMacro(LowerThreshold, InputImagePixelType);
100 itkGetMacro(LowerThreshold, InputImagePixelType);
101 itkSetMacro(UseLowerThreshold, bool);
102 itkGetMacro(PrimaryOpeningRadius, unsigned int);
103 itkSetMacro(PrimaryOpeningRadius, unsigned int);
104 itkGetConstMacro(UseLowerThreshold, bool);
105 itkBooleanMacro(UseLowerThreshold);
108 itkSetMacro(DecomposeAndReconstructDuringFirstStep, bool);
109 itkGetConstMacro(DecomposeAndReconstructDuringFirstStep, bool);
110 itkBooleanMacro(DecomposeAndReconstructDuringFirstStep);
112 itkSetMacro(Radius1, InternalImageSizeType);
113 itkGetConstMacro(Radius1, InternalImageSizeType);
115 itkSetMacro(MaximumNumberOfLabels1, int);
116 itkGetConstMacro(MaximumNumberOfLabels1, int);
118 itkSetMacro(NumberOfNewLabels1, int);
119 itkGetConstMacro(NumberOfNewLabels1, int);
122 itkSetMacro(DecomposeAndReconstructDuringSecondStep, bool);
123 itkGetConstMacro(DecomposeAndReconstructDuringSecondStep, bool);
124 itkBooleanMacro(DecomposeAndReconstructDuringSecondStep);
126 itkSetMacro(Radius2, InternalImageSizeType);
127 itkGetConstMacro(Radius2, InternalImageSizeType);
129 itkSetMacro(MaximumNumberOfLabels2, int);
130 itkGetConstMacro(MaximumNumberOfLabels2, int);
132 itkSetMacro(NumberOfNewLabels2, int);
133 itkGetConstMacro(NumberOfNewLabels2, int);
136 itkSetMacro(FirstKeep, int);
137 itkGetConstMacro(FirstKeep, int);
139 itkSetMacro(LastKeep, int);
140 itkGetConstMacro(LastKeep, int);
143 itkSetMacro(FinalOpenClose, bool);
144 itkGetConstMacro(FinalOpenClose, bool);
145 itkBooleanMacro(FinalOpenClose);
148 itkSetMacro(AutoCrop, bool);
149 itkGetConstMacro(AutoCrop, bool);
150 itkBooleanMacro(AutoCrop);
153 ExtractPatientFilter();
154 virtual ~ExtractPatientFilter() {}
156 itkSetMacro(BackgroundValue, MaskImagePixelType);
157 itkSetMacro(ForegroundValue, MaskImagePixelType);
158 itkGetConstMacro(BackgroundValue, MaskImagePixelType);
159 itkGetConstMacro(ForegroundValue, MaskImagePixelType);
160 MaskImagePixelType m_BackgroundValue;
161 MaskImagePixelType m_ForegroundValue;
163 std::string m_OutputPatientFilename;
164 InputImagePixelType m_UpperThreshold;
165 InputImagePixelType m_LowerThreshold;
166 bool m_UseLowerThreshold;
167 bool m_DecomposeAndReconstructDuringFirstStep;
168 bool m_DecomposeAndReconstructDuringSecondStep;
169 bool m_FinalOpenClose;
170 unsigned m_PrimaryOpeningRadius;
171 InternalImageSizeType m_Radius1;
172 InternalImageSizeType m_Radius2;
173 int m_MaximumNumberOfLabels1;
174 int m_MaximumNumberOfLabels2;
175 int m_NumberOfNewLabels1;
176 int m_NumberOfNewLabels2;
181 virtual void GenerateOutputInformation();
182 virtual void GenerateData();
184 InputImageConstPointer input;
185 MaskImagePointer output;
186 typename InternalImageType::Pointer working_image;
189 ExtractPatientFilter(const Self&); //purposely not implemented
190 void operator=(const Self&); //purposely not implemented
193 //--------------------------------------------------------------------
195 } // end namespace clitk
196 //--------------------------------------------------------------------
198 #ifndef ITK_MANUAL_INSTANTIATION
199 #include "clitkExtractPatientFilter.txx"