]> Creatis software - clitk.git/blob - segmentation/clitkExtractLymphStation_3P.txx
motion masks with and without bands
[clitk.git] / segmentation / clitkExtractLymphStation_3P.txx
1
2 //--------------------------------------------------------------------
3 template <class ImageType>
4 void 
5 clitk::ExtractLymphStationsFilter<ImageType>::
6 ExtractStation_3P_SetDefaultValues()
7 {
8 }
9 //--------------------------------------------------------------------
10
11
12 //--------------------------------------------------------------------
13 template <class TImageType>
14 void 
15 clitk::ExtractLymphStationsFilter<TImageType>::
16 ExtractStation_3P()
17 {
18   if (!CheckForStation("3P")) return;
19
20   StartNewStep("Station 3P");
21   StartSubStep();  
22
23   // Get the current support 
24   StartNewStep("[Station 3P] Get the current 3P suppport");
25   m_Working_Support = m_ListOfSupports["S3P"];
26   m_ListOfStations["3P"] = m_Working_Support;
27   StopCurrentStep<MaskImageType>(m_Working_Support);
28
29   // Generic RelativePosition processes
30   m_ListOfStations["3P"] = this->ApplyRelativePositionList("Station_3P", m_ListOfStations["3P"]);
31   m_Working_Support = m_ListOfStations["3P"];
32   ExtractStation_8_Single_CCL_Limits(); // YES 8 !
33   ExtractStation_3P_Remove_Structures(); // after CCL
34   m_ListOfStations["3P"] = m_Working_Support;
35
36   // Old stuff
37   // LR limits superiorly => not here for the moment because not clear in the def
38   // ExtractStation_3P_LR_sup_Limits_2(); //TODO
39   // ExtractStation_3P_LR_sup_Limits();   // old version to change
40   // ExtractStation_3P_LR_inf_Limits();  // <-- done in RelPosList 
41
42   // Store image filenames into AFDB 
43   writeImage<MaskImageType>(m_ListOfStations["3P"], "seg/Station3P.mhd");
44   GetAFDB()->SetImageFilename("Station3P", "seg/Station3P.mhd"); 
45   WriteAFDB();   
46   StopSubStep();
47 }
48 //--------------------------------------------------------------------
49
50
51 //--------------------------------------------------------------------
52 template <class ImageType>
53 void 
54 clitk::ExtractLymphStationsFilter<ImageType>::
55 ExtractStation_3P_Remove_Structures() 
56 {
57   StartNewStep("[Station 3P] Remove some structures.");
58   Remove_Structures("3P", "Esophagus");
59   Remove_Structures("3P", "Thyroid");
60   Remove_Structures("3P", "VertebralArtery"); // (inside the station)
61   StopCurrentStep<MaskImageType>(m_Working_Support);
62   m_ListOfStations["3P"] = m_Working_Support;
63 }
64 //--------------------------------------------------------------------
65
66
67 //--------------------------------------------------------------------
68 template <class ImageType>
69 void 
70 clitk::ExtractLymphStationsFilter<ImageType>::
71 ExtractStation_3P_LR_sup_Limits() 
72 {
73   /*
74     "On the right side, the limit is defined by the air–soft-tissue
75     interface. On the left side, it is defined by the air–tissue
76     interface superiorly (Fig. 2A–C) and the aorta inferiorly
77     (Figs. 2D–I and 3A–C)."
78
79     sup : 
80     Resizelike support : Trachea, SubclavianArtery
81     Trachea, slice by slice, get centroid trachea
82     SubclavianArtery, slice by slice, CCL
83     prendre la 1ère à L et R, not at Left
84     
85   */
86   StartNewStep("[Station 3P] Left/Right limits (superior part) ");
87
88   // Load structures
89   MaskImagePointer Trachea = GetAFDB()->template GetImage<MaskImageType>("Trachea");
90   MaskImagePointer SubclavianArtery = GetAFDB()->template GetImage<MaskImageType>("SubclavianArtery");
91   
92   // Crop like current support
93   Trachea = clitk::ResizeImageLike<MaskImageType>(Trachea, m_Working_Support, GetBackgroundValue());
94   SubclavianArtery = clitk::ResizeImageLike<MaskImageType>(SubclavianArtery, m_Working_Support, GetBackgroundValue());
95   
96   // writeImage<MaskImageType>(Trachea, "tr.mhd");
97   // writeImage<MaskImageType>(SubclavianArtery, "sca.mhd");
98   
99   // Get list of slices
100   std::vector<MaskSlicePointer> slices_support;
101   std::vector<MaskSlicePointer> slices_trachea;
102   std::vector<MaskSlicePointer> slices_subclavianartery;
103   clitk::ExtractSlices<MaskImageType>(m_Working_Support, 2, slices_support);
104   clitk::ExtractSlices<MaskImageType>(Trachea, 2, slices_trachea);
105   clitk::ExtractSlices<MaskImageType>(SubclavianArtery, 2, slices_subclavianartery);
106
107   // Loop on slices
108   std::vector<MaskImagePointType> points;
109   MaskImagePointType p;
110   for(uint i=0; i<slices_support.size(); i++) {
111     // Get Trachea centroid
112     std::vector<typename MaskSliceType::PointType> centroids;
113     typename MaskSliceType::PointType c;
114     ComputeCentroids<MaskSliceType>(slices_trachea[i], GetBackgroundValue(), centroids);
115     c = centroids[1];
116
117     // [debug] Store point
118     clitk::PointsUtils<MaskImageType>::Convert2DTo3D(centroids[1], Trachea, i, p);
119     points.push_back(p);
120     
121     // Get Right and Left CCL in SubclavianArtery
122     slices_subclavianartery[i] = Labelize<MaskSliceType>(slices_subclavianartery[i], 0, true, 10);
123     ComputeCentroids<MaskSliceType>(slices_subclavianartery[i], GetBackgroundValue(), centroids);
124
125     if (centroids.size() > 1) {
126       // Determine the one at Right/Left -> first after Trachea
127       // centroid 
128       typename MaskSliceType::PointType right;
129       typename MaskSliceType::PointType left;
130       int label_right=-1;
131       int label_left=-1;
132       right[0] = c[0]-100;
133       left[0] = c[0]+100;
134       for(uint j=1; j<centroids.size(); j++) {
135         if (centroids[j][0] < c[0]) { // At Right of Trachea centroid
136           if (centroids[j][0] >= right[0]) {
137             right = centroids[j];
138             label_right = j;
139           }
140         }
141         if (centroids[j][0] > c[0]) { // At Left of Trachea centroid
142           if (centroids[j][0] <= left[0]) {
143             left = centroids[j];
144             label_left = j;
145           }
146         }
147       }
148
149       if (label_right != -1) {
150     
151         // Debug points
152         clitk::PointsUtils<MaskImageType>::Convert2DTo3D(centroids[label_right], SubclavianArtery, i, p);
153         points.push_back(p);
154
155         // Set Background and ForegroundValue according to label_right
156         MaskSlicePointer object = 
157           clitk::Binarize<MaskSliceType>(slices_subclavianartery[i], label_right, label_right, 
158                                          GetBackgroundValue(), GetForegroundValue());
159       
160         // Relative Position : not at Right
161         typedef clitk::AddRelativePositionConstraintToLabelImageFilter<MaskSliceType> RelPosFilterType;
162         typename RelPosFilterType::Pointer relPosFilter = RelPosFilterType::New();
163         relPosFilter->VerboseStepFlagOff();
164         relPosFilter->WriteStepFlagOff();
165         relPosFilter->SetBackgroundValue(GetBackgroundValue());
166         relPosFilter->SetInput(slices_support[i]); 
167         relPosFilter->SetInputObject(object); 
168         relPosFilter->AddOrientationTypeString("RightTo");
169         relPosFilter->SetInverseOrientationFlag(true);
170         //      relPosFilter->SetIntermediateSpacing(3);
171         relPosFilter->SetIntermediateSpacingFlag(false);
172         relPosFilter->SetFuzzyThreshold(0.7);
173         relPosFilter->AutoCropFlagOff(); // important ! because we join the slices after this loop
174         relPosFilter->Update();
175         slices_support[i] = relPosFilter->GetOutput();
176
177         // Relative Position : not Anterior
178         relPosFilter = RelPosFilterType::New();
179         relPosFilter->VerboseStepFlagOff();
180         relPosFilter->WriteStepFlagOff();
181         relPosFilter->SetBackgroundValue(GetBackgroundValue());
182         relPosFilter->SetInput(slices_support[i]); 
183         relPosFilter->SetInputObject(object); 
184         relPosFilter->AddOrientationTypeString("AntTo");
185         relPosFilter->SetInverseOrientationFlag(true);
186         //      relPosFilter->SetIntermediateSpacing(3);
187         relPosFilter->SetIntermediateSpacingFlag(false);
188         relPosFilter->SetFuzzyThreshold(0.7);
189         relPosFilter->AutoCropFlagOff(); // important ! because we join the slices after this loop
190         relPosFilter->Update();
191         slices_support[i] = relPosFilter->GetOutput();
192
193       } // End RelativePosition for Right
194
195
196       if (label_left != -1) {
197     
198         // Debug points
199         clitk::PointsUtils<MaskImageType>::Convert2DTo3D(centroids[label_left], SubclavianArtery, i, p);
200         points.push_back(p);
201
202         // Set Background and ForegroundValue according to label_right
203         MaskSlicePointer object = 
204           clitk::Binarize<MaskSliceType>(slices_subclavianartery[i], label_left, label_left, 
205                                          GetBackgroundValue(), GetForegroundValue());
206       
207         // Relative Position : not at Right
208         typedef clitk::AddRelativePositionConstraintToLabelImageFilter<MaskSliceType> RelPosFilterType;
209         typename RelPosFilterType::Pointer relPosFilter = RelPosFilterType::New();
210         relPosFilter->VerboseStepFlagOff();
211         relPosFilter->WriteStepFlagOff();
212         relPosFilter->SetBackgroundValue(GetBackgroundValue());
213         relPosFilter->SetInput(slices_support[i]); 
214         relPosFilter->SetInputObject(object); 
215         relPosFilter->AddOrientationTypeString("L");
216         relPosFilter->SetInverseOrientationFlag(true);
217         //      relPosFilter->SetIntermediateSpacing(3);
218         relPosFilter->SetIntermediateSpacingFlag(false);
219         relPosFilter->SetFuzzyThreshold(0.7);
220         relPosFilter->AutoCropFlagOff(); // important ! because we join the slices after this loop
221         relPosFilter->Update();
222         slices_support[i] = relPosFilter->GetOutput();
223
224         // Relative Position : not Anterior
225         relPosFilter = RelPosFilterType::New();
226         relPosFilter->VerboseStepFlagOff();
227         relPosFilter->WriteStepFlagOff();
228         relPosFilter->SetBackgroundValue(GetBackgroundValue());
229         relPosFilter->SetInput(slices_support[i]); 
230         relPosFilter->SetInputObject(object); 
231         relPosFilter->AddOrientationTypeString("A");
232         relPosFilter->SetInverseOrientationFlag(true);
233         //      relPosFilter->SetIntermediateSpacing(3);
234         relPosFilter->SetIntermediateSpacingFlag(false);
235         relPosFilter->SetFuzzyThreshold(0.7);
236         relPosFilter->AutoCropFlagOff(); // important ! because we join the slices after this loop
237         relPosFilter->Update();
238         slices_support[i] = relPosFilter->GetOutput();
239
240       }
241
242     
243     } // if centroids.size > 1
244   } // End loop slices
245
246   // Joint slices
247   m_Working_Support = clitk::JoinSlices<MaskImageType>(slices_support, m_Working_Support, 2);
248
249   // Save list points
250   clitk::WriteListOfLandmarks<MaskImageType>(points, "subcl-lr.txt");
251
252
253   StopCurrentStep<MaskImageType>(m_Working_Support);
254   m_ListOfStations["3P"] = m_Working_Support;
255 }
256 //--------------------------------------------------------------------
257
258 //--------------------------------------------------------------------
259 template <class ImageType>
260 void 
261 clitk::ExtractLymphStationsFilter<ImageType>::
262 ExtractStation_3P_LR_sup_Limits_2() 
263 {
264   /*
265     "On the right side, the limit is defined by the air–soft-tissue
266     interface. On the left side, it is defined by the air–tissue
267     interface superiorly (Fig. 2A–C) and the aorta inferiorly
268     (Figs. 2D–I and 3A–C)."
269
270     sup : 
271     Resizelike support : Trachea, SubclavianArtery
272     Trachea, slice by slice, get centroid trachea
273     SubclavianArtery, slice by slice, CCL
274     prendre la 1ère à L et R, not at Left
275     
276   */
277   //  StartNewStep("[Station 3P] Left/Right limits (superior part) ");
278   
279
280 }
281 //--------------------------------------------------------------------
282