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 CLITKEXTRACTMEDIASTINUMFILTER_TXX
20 #define CLITKEXTRACTMEDIASTINUMFILTER_TXX
23 #include "clitkCommon.h"
24 #include "clitkExtractMediastinumFilter.h"
25 #include "clitkAddRelativePositionConstraintToLabelImageFilter.h"
26 #include "clitkSegmentationUtils.h"
30 #include "itkStatisticsLabelMapFilter.h"
31 #include "itkLabelImageToStatisticsLabelMapFilter.h"
32 #include "itkRegionOfInterestImageFilter.h"
33 #include "itkBinaryThresholdImageFilter.h"
36 #include "RelativePositionPropImageFilter.h"
38 //--------------------------------------------------------------------
39 template <class TImageType>
40 clitk::ExtractMediastinumFilter<TImageType>::
41 ExtractMediastinumFilter():
43 itk::ImageToImageFilter<TImageType, TImageType>()
45 this->SetNumberOfRequiredInputs(3);
47 SetBackgroundValuePatient(0);
48 SetBackgroundValueLung(0);
49 SetBackgroundValueBones(0);
50 SetForegroundValueLeftLung(1);
51 SetForegroundValueRightLung(2);
52 SetBackgroundValue(0);
53 SetForegroundValue(1);
55 SetIntermediateSpacing(6);
56 SetFuzzyThreshold1(0.6);
57 SetFuzzyThreshold2(0.7);
59 //--------------------------------------------------------------------
62 //--------------------------------------------------------------------
63 template <class TImageType>
65 clitk::ExtractMediastinumFilter<TImageType>::
66 SetInputPatientLabelImage(const TImageType * image, ImagePixelType bg) {
67 this->SetNthInput(0, const_cast<TImageType *>(image));
68 m_BackgroundValuePatient = bg;
70 //--------------------------------------------------------------------
73 //--------------------------------------------------------------------
74 template <class TImageType>
76 clitk::ExtractMediastinumFilter<TImageType>::
77 SetInputLungLabelImage(const TImageType * image, ImagePixelType bg,
78 ImagePixelType fgLeft, ImagePixelType fgRight) {
79 this->SetNthInput(1, const_cast<TImageType *>(image));
80 m_BackgroundValueLung = bg;
81 m_ForegroundValueLeftLung = fgLeft;
82 m_ForegroundValueRightLung = fgRight;
84 //--------------------------------------------------------------------
87 //--------------------------------------------------------------------
88 template <class TImageType>
90 clitk::ExtractMediastinumFilter<TImageType>::
91 SetInputBonesLabelImage(const TImageType * image, ImagePixelType bg) {
92 this->SetNthInput(2, const_cast<TImageType *>(image));
93 m_BackgroundValueBones = bg;
95 //--------------------------------------------------------------------
98 //--------------------------------------------------------------------
99 template <class TImageType>
100 template<class ArgsInfoType>
102 clitk::ExtractMediastinumFilter<TImageType>::
103 SetArgsInfo(ArgsInfoType mArgsInfo)
105 SetVerboseOption_GGO(mArgsInfo);
106 SetVerboseStep_GGO(mArgsInfo);
107 SetWriteStep_GGO(mArgsInfo);
108 SetVerboseWarningOff_GGO(mArgsInfo);
110 SetBackgroundValuePatient_GGO(mArgsInfo);
111 SetBackgroundValueLung_GGO(mArgsInfo);
112 SetBackgroundValueBones_GGO(mArgsInfo);
114 SetForegroundValueLeftLung_GGO(mArgsInfo);
115 SetForegroundValueRightLung_GGO(mArgsInfo);
117 SetIntermediateSpacing_GGO(mArgsInfo);
118 SetFuzzyThreshold1_GGO(mArgsInfo);
119 SetFuzzyThreshold2_GGO(mArgsInfo);
121 //--------------------------------------------------------------------
124 //--------------------------------------------------------------------
125 template <class TImageType>
127 clitk::ExtractMediastinumFilter<TImageType>::
128 GenerateOutputInformation() {
129 ImagePointer input = dynamic_cast<TImageType*>(itk::ProcessObject::GetInput(0));
130 ImagePointer outputImage = this->GetOutput(0);
131 outputImage->SetRegions(outputImage->GetLargestPossibleRegion());
133 //--------------------------------------------------------------------
136 //--------------------------------------------------------------------
137 template <class TImageType>
139 clitk::ExtractMediastinumFilter<TImageType>::
140 GenerateInputRequestedRegion() {
142 Superclass::GenerateInputRequestedRegion();
143 // Get input pointers
144 ImagePointer patient = dynamic_cast<TImageType*>(itk::ProcessObject::GetInput(0));
145 ImagePointer lung = dynamic_cast<TImageType*>(itk::ProcessObject::GetInput(1));
146 ImagePointer bones = dynamic_cast<TImageType*>(itk::ProcessObject::GetInput(2));
148 patient->SetRequestedRegion(patient->GetLargestPossibleRegion());
149 lung->SetRequestedRegion(lung->GetLargestPossibleRegion());
150 bones->SetRequestedRegion(bones->GetLargestPossibleRegion());
152 //--------------------------------------------------------------------
155 //--------------------------------------------------------------------
156 template <class TImageType>
158 clitk::ExtractMediastinumFilter<TImageType>::
160 // Get input pointers
161 ImageConstPointer patient = dynamic_cast<const TImageType*>(itk::ProcessObject::GetInput(0));
162 ImageConstPointer lung = dynamic_cast<const TImageType*>(itk::ProcessObject::GetInput(1));
163 ImageConstPointer bones = dynamic_cast<const TImageType*>(itk::ProcessObject::GetInput(2));
165 // Get output pointer
168 // Step 1: patient minus lungs, minus bones
169 StartNewStep("Patient contours minus lungs and minus bones");
170 typedef clitk::BooleanOperatorLabelImageFilter<ImageType> BoolFilterType;
171 typename BoolFilterType::Pointer boolFilter = BoolFilterType::New();
172 boolFilter->InPlaceOn();
173 boolFilter->SetInput1(patient);
174 boolFilter->SetInput2(lung);
175 boolFilter->SetOperationType(BoolFilterType::AndNot);
176 boolFilter->Update();
177 boolFilter->SetInput1(boolFilter->GetOutput());
178 boolFilter->SetInput2(bones);
179 boolFilter->SetOperationType(BoolFilterType::AndNot);
180 boolFilter->Update();
181 output = boolFilter->GetOutput();
183 output = clitk::AutoCrop<ImageType>(output, GetBackgroundValue());
184 ////autoCropFilter->GetOutput(); typedef clitk::AutoCropFilter<ImageType> CropFilterType;
185 //typename CropFilterType::Pointer cropFilter = CropFilterType::New();
186 //cropFilter->SetInput(output);
187 //cropFilter->Update();
188 //output = cropFilter->GetOutput();
190 this->template StopCurrentStep<TImageType>(output);
192 // Step 2: LR limits from lung (need separate lung ?)
193 StartNewStep("Left/Right limits with lungs");
194 typedef clitk::AddRelativePositionConstraintToLabelImageFilter<TImageType> RelPosFilterType;
195 typename RelPosFilterType::Pointer relPosFilter = RelPosFilterType::New();
196 relPosFilter->SetCurrentStepBaseId(this->GetCurrentStepId());
197 relPosFilter->VerboseStepOff();
198 relPosFilter->WriteStepOff();
199 relPosFilter->SetInput(output);
200 relPosFilter->SetInputObject(lung);
201 relPosFilter->SetOrientationType(RelPosFilterType::LeftTo);
202 relPosFilter->SetIntermediateSpacing(GetIntermediateSpacing());
203 relPosFilter->SetFuzzyThreshold(GetFuzzyThreshold1());
204 relPosFilter->Update();
205 output = relPosFilter->GetOutput();
207 relPosFilter->SetInput(output);
208 relPosFilter->SetCurrentStepBaseId(this->GetCurrentStepId());
209 relPosFilter->VerboseStepOff();
210 relPosFilter->WriteStepOff();
211 relPosFilter->SetInputObject(lung);
212 relPosFilter->SetOrientationType(RelPosFilterType::RightTo);
213 relPosFilter->SetIntermediateSpacing(GetIntermediateSpacing());
214 relPosFilter->SetFuzzyThreshold(GetFuzzyThreshold1());
215 relPosFilter->Update();
216 output = relPosFilter->GetOutput();
217 this->template StopCurrentStep<TImageType>(output);
219 // Step 3: AP limits from bones
220 StartNewStep("Ant/Post limits with bones");
221 relPosFilter->SetCurrentStepNumber(0);
222 relPosFilter->ResetPipeline();// = RelPosFilterType::New();
223 relPosFilter->SetCurrentStepBaseId(this->GetCurrentStepId());
224 relPosFilter->VerboseStepOff();
225 relPosFilter->WriteStepOff();
226 relPosFilter->SetInput(output);
227 relPosFilter->SetInputObject(bones);
228 relPosFilter->SetOrientationType(RelPosFilterType::AntTo);
229 relPosFilter->SetIntermediateSpacing(GetIntermediateSpacing());
230 relPosFilter->SetFuzzyThreshold(GetFuzzyThreshold2());
231 relPosFilter->Update();
233 relPosFilter->SetInput(relPosFilter->GetOutput());
234 relPosFilter->SetCurrentStepBaseId(this->GetCurrentStepId());
235 relPosFilter->VerboseStepOff();
236 relPosFilter->WriteStepOff();
237 relPosFilter->SetInputObject(bones);
238 relPosFilter->SetOrientationType(RelPosFilterType::PostTo);
239 relPosFilter->SetIntermediateSpacing(GetIntermediateSpacing());
240 relPosFilter->SetFuzzyThreshold(GetFuzzyThreshold2());
241 relPosFilter->Update();
242 output = relPosFilter->GetOutput();
243 this->template StopCurrentStep<TImageType>(output);
246 output = clitk::Labelize<TImageType>(output, GetBackgroundValue(), true, 100);
247 // output = RemoveLabels<TImageType>(output, BG, param->GetLabelsToRemove());
248 output = clitk::KeepLabels<TImageType>(output, GetBackgroundValue(),
249 GetForegroundValue(), 1, 1, 0);
251 output = clitk::AutoCrop<ImageType>(output, GetBackgroundValue());
252 // cropFilter = CropFilterType::New();
253 //cropFilter->SetInput(output);
254 //cropFilter->Update();
255 //output = cropFilter->GetOutput();
257 // Final Step -> set output
258 this->SetNthOutput(0, output);
260 //--------------------------------------------------------------------
263 #endif //#define CLITKBOOLEANOPERATORLABELIMAGEFILTER_TXX