]> Creatis software - clitk.git/blob - segmentation/clitkExtractLymphStation_3A.txx
Remove VertebralBody
[clitk.git] / segmentation / clitkExtractLymphStation_3A.txx
1
2 //--------------------------------------------------------------------
3 template <class ImageType>
4 void 
5 clitk::ExtractLymphStationsFilter<ImageType>::
6 ExtractStation_3A_SetDefaultValues()
7 {
8 }
9 //--------------------------------------------------------------------
10
11
12 //--------------------------------------------------------------------
13 template <class TImageType>
14 void 
15 clitk::ExtractLymphStationsFilter<TImageType>::
16 ExtractStation_3A()
17 {
18   if (!CheckForStation("3A")) return;
19
20   StartNewStep("Station 3A");
21   StartSubStep();   
22
23   // Get the current support 
24   StartNewStep("[Station 3A] Get the current 3A suppport");
25   m_Working_Support = m_ListOfSupports["S3A"];
26   m_ListOfStations["3A"] = m_Working_Support;
27   StopCurrentStep<MaskImageType>(m_Working_Support);
28   
29   ExtractStation_3A_Post_Left_Limits_With_Aorta_S5_Support();
30   ExtractStation_3A_Post_Limits_With_Dilated_Aorta_S6_Support();
31   ExtractStation_3A_AntPost_Superiorly();
32   ExtractStation_3A_Remove_Structures();
33   
34   // Generic RelativePosition processes
35   m_ListOfStations["3A"] = this->ApplyRelativePositionList("Station_3A", m_ListOfStations["3A"]);
36
37   // Keep a single CCL
38   m_ListOfStations["3A"] = 
39     clitk::SliceBySliceKeepMainCCL<MaskImageType>(m_ListOfStations["3A"], 
40                                                   GetBackgroundValue(), 
41                                                   GetForegroundValue());
42
43   // Store image filenames into AFDB 
44   writeImage<MaskImageType>(m_ListOfStations["3A"], "seg/Station3A.mhd");
45   GetAFDB()->SetImageFilename("Station3A", "seg/Station3A.mhd"); 
46   WriteAFDB(); 
47   StopSubStep();
48 }
49 //--------------------------------------------------------------------
50
51
52
53 //--------------------------------------------------------------------
54 template <class ImageType>
55 void 
56 clitk::ExtractLymphStationsFilter<ImageType>::
57 ExtractStation_3A_Post_Left_Limits_With_Aorta_S5_Support() 
58 {
59   StartNewStep("[Station 3A] Post limits in S5 support according to Aorta");
60
61    // Consider Aorta, remove Left/Post part ; only around S5
62   // Get S5 support and Aorta
63   MaskImagePointer S5 = m_ListOfSupports["S5"];
64   MaskImagePointer Aorta = GetAFDB()->template GetImage <MaskImageType>("Aorta");
65   Aorta = clitk::ResizeImageLike<MaskImageType>(Aorta, S5, GetBackgroundValue());
66   
67   // Inferiorly, Aorta has two CCL that merge into a single one when
68   // S6 appears. Loop on Aorta slices, select the most ant one, detect
69   // the most ant point.
70   std::vector<MaskSlicePointer> slices;
71   clitk::ExtractSlices<MaskImageType>(Aorta, 2, slices);
72   std::vector<MaskImagePointType> points;
73   for(uint i=0; i<slices.size(); i++) {
74     // Select most ant CCL
75     slices[i] = clitk::Labelize<MaskSliceType>(slices[i], GetBackgroundValue(), false, 1);
76     std::vector<MaskSlicePointType> c;
77     clitk::ComputeCentroids<MaskSliceType>(slices[i], GetBackgroundValue(), c);
78     assert(c.size() == 3); // only 2 CCL
79     typename MaskSliceType::PixelType l;
80     if (c[1][1] > c[2][1]) { // We will remove the label=1
81       l = 1;
82     }
83     else {
84       l = 2;// We will remove the label=2
85     }
86     slices[i] = clitk::SetBackground<MaskSliceType, MaskSliceType>(slices[i], slices[i], l, 
87                                                                    GetBackgroundValue(), true);
88     
89     // Detect the most ant point
90     MaskSlicePointType p;
91     MaskImagePointType pA;
92     clitk::FindExtremaPointInAGivenDirection<MaskSliceType>(slices[i], GetBackgroundValue(), 1, true, p);
93     // Set the X coordinate to the X coordinate of the centroid
94     if (l==1) p[0] = c[2][0];
95     else p[0] = c[1][0];
96     
97     // Convert in 3D and store
98     clitk::PointsUtils<MaskImageType>::Convert2DTo3D(p, Aorta, i, pA);
99     points.push_back(pA);
100   }
101   
102   // DEBUG
103   // MaskImagePointer o = clitk::JoinSlices<MaskImageType>(slices, Aorta, 2);
104   // writeImage<MaskImageType>(o, "o.mhd");
105   // clitk::WriteListOfLandmarks<MaskImageType>(points, "Ant-Aorta.txt");
106
107   // Remove Post/Left to this point
108   m_Working_Support = 
109     clitk::SliceBySliceSetBackgroundFromPoints<MaskImageType>(m_Working_Support, 
110                                                               GetBackgroundValue(), 2,
111                                                               points, 
112                                                               true, // Set BG if X greater than point[x], and 
113                                                               true); // if Y greater than point[y]
114   
115   StopCurrentStep<MaskImageType>(m_Working_Support);
116   m_ListOfStations["3A"] = m_Working_Support;
117 }
118 //--------------------------------------------------------------------
119
120
121 //--------------------------------------------------------------------
122 template <class ImageType>
123 void 
124 clitk::ExtractLymphStationsFilter<ImageType>::
125 ExtractStation_3A_Post_Limits_With_Dilated_Aorta_S6_Support() 
126 {
127   StartNewStep("[Station 3A] Post limits with dilated Aorta");
128
129   // Consider Aorta
130   MaskImagePointer Aorta = GetAFDB()->template GetImage <MaskImageType>("Aorta");
131   
132   // Limits the support to S6
133   MaskImagePointer S6 = m_ListOfSupports["S6"];
134   Aorta = clitk::ResizeImageLike<MaskImageType>(Aorta, S6, GetBackgroundValue());
135   
136   // Extend 1cm anteriorly
137   MaskImagePointType radius; // in mm
138   radius[0] = 10;
139   radius[1] = 10;
140   radius[2] = 0; // required
141   Aorta = clitk::Dilate<MaskImageType>(Aorta, radius, GetBackgroundValue(), GetForegroundValue(), false);
142   
143   // Now, insert this image in the AFDB (but do not store on disk)
144   GetAFDB()->template SetImage<MaskImageType>("Aorta_Dilated_Anteriorly", "bidon", 
145                                               Aorta, false);
146   /*
147   // Not Post to
148   m_Working_Support = 
149     clitk::SliceBySliceRelativePosition<MaskImageType>(m_Working_Support, Aorta, 2, 
150                                                        GetFuzzyThreshold("3A", "Aorta"), 
151                                                        "NotPostTo", true, 
152                                                        Aorta->GetSpacing()[0], false, false);
153
154   */
155
156   
157   StopCurrentStep<MaskImageType>(m_Working_Support);
158   m_ListOfStations["3A"] = m_Working_Support;
159 }
160 //--------------------------------------------------------------------
161
162
163 //--------------------------------------------------------------------
164 template <class ImageType>
165 void 
166 clitk::ExtractLymphStationsFilter<ImageType>::
167 ExtractStation_3A_AntPost_Superiorly() 
168 {
169   StartNewStep("[Station 3A] Post limits superiorly");
170   
171   // Get or compute the binary mask that separate Ant/Post part
172   // according to vessels
173   MaskImagePointer binarizedContour = FindAntPostVessels2();
174   binarizedContour = clitk::ResizeImageLike<MaskImageType>(binarizedContour, 
175                                                            m_Working_Support, 
176                                                            GetBackgroundValue());
177
178   // remove from support
179   typedef clitk::BooleanOperatorLabelImageFilter<MaskImageType> BoolFilterType;
180   typename BoolFilterType::Pointer boolFilter = BoolFilterType::New(); 
181   boolFilter->InPlaceOn();
182   boolFilter->SetInput1(m_Working_Support);
183   boolFilter->SetInput2(binarizedContour);
184   boolFilter->SetBackgroundValue1(GetBackgroundValue());
185   boolFilter->SetBackgroundValue2(GetBackgroundValue());
186   boolFilter->SetOperationType(BoolFilterType::AndNot);
187   boolFilter->Update();
188   m_Working_Support = boolFilter->GetOutput();
189   
190   StopCurrentStep<MaskImageType>(m_Working_Support);
191   m_ListOfStations["3A"] = m_Working_Support;
192 }
193 //--------------------------------------------------------------------
194
195
196 //--------------------------------------------------------------------
197 template <class ImageType>
198 void 
199 clitk::ExtractLymphStationsFilter<ImageType>::
200 ExtractStation_3A_Remove_Structures() 
201 {
202   Remove_Structures(" 3A", "Aorta");
203   Remove_Structures(" 3A", "SubclavianArteryLeft");
204   Remove_Structures(" 3A", "SubclavianArteryRight");
205   Remove_Structures(" 3A", "Thyroid");
206   Remove_Structures(" 3A", "CommonCarotidArteryLeft");
207   Remove_Structures(" 3A", "CommonCarotidArteryRight");
208   Remove_Structures(" 3A", "BrachioCephalicArtery");
209   //  Remove_Structures("3A", "Bones"); --> should be in extractmediastinum
210   //  Remove_Structures("3A", "BrachioCephalicVein"); ?
211
212   StartNewStep("[Station 3A] Remove part of BrachioCephalicVein");
213   // resize like support, extract slices
214   // while single CCL -> remove
215   // when two remove only the most post
216   MaskImagePointer BrachioCephalicVein = 
217     GetAFDB()->template GetImage <MaskImageType>("BrachioCephalicVein");
218   BrachioCephalicVein = clitk::ResizeImageLike<MaskImageType>(BrachioCephalicVein, 
219                                                               m_Working_Support, 
220                                                               GetBackgroundValue());
221   std::vector<MaskSlicePointer> slices;
222   std::vector<MaskSlicePointer> slices_BCV;
223   clitk::ExtractSlices<MaskImageType>(m_Working_Support, 2, slices);
224   clitk::ExtractSlices<MaskImageType>(BrachioCephalicVein, 2, slices_BCV);
225   for(uint i=0; i<slices.size(); i++) {
226     // Labelize slices_BCV
227     slices_BCV[i] = Labelize<MaskSliceType>(slices_BCV[i], 0, true, 1);
228
229     // Compute centroids
230     std::vector<typename MaskSliceType::PointType> centroids;
231     ComputeCentroids<MaskSliceType>(slices_BCV[i], GetBackgroundValue(), centroids);
232
233     // If several centroid, select the one most anterior
234     if (centroids.size() > 2) {
235       // Only keep the one most post
236       typename MaskSliceType::PixelType label;
237       if (centroids[1][1] > centroids[2][1]) {
238         label = 2;
239       }
240       else {
241         label = 1;
242       }      
243       // "remove" the CCL 
244       slices_BCV[i] = clitk::SetBackground<MaskSliceType, MaskSliceType>(slices_BCV[i], 
245                                                                          slices_BCV[i], 
246                                                                          label, 
247                                                                          GetBackgroundValue(), 
248                                                                          true);
249     }
250     
251     // Remove from the support
252     clitk::AndNot<MaskSliceType>(slices[i], slices_BCV[i], GetBackgroundValue());
253   }
254   
255   // Joint
256   m_Working_Support = clitk::JoinSlices<MaskImageType>(slices, m_Working_Support, 2);
257
258   StopCurrentStep<MaskImageType>(m_Working_Support);
259   m_ListOfStations["3A"] = m_Working_Support;
260 }
261 //--------------------------------------------------------------------
262
263