X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=segmentation%2FclitkExtractLymphStation_Supports.txx;h=79abe6a6652b60f20cf5aa2eaf293a12855345fa;hb=b2a7c12437798214cca01b68d61f5b16eb1036a5;hp=1008ff48dfa3b53f16dac112280ca3ae2458a92f;hpb=e1098dccba022441144bfc1c44a2b58db7dde34e;p=clitk.git diff --git a/segmentation/clitkExtractLymphStation_Supports.txx b/segmentation/clitkExtractLymphStation_Supports.txx index 1008ff4..79abe6a 100644 --- a/segmentation/clitkExtractLymphStation_Supports.txx +++ b/segmentation/clitkExtractLymphStation_Supports.txx @@ -8,10 +8,8 @@ void clitk::ExtractLymphStationsFilter:: ExtractStationSupports() { - DD("ExtractStationSupports"); - // Get initial Mediastinum - m_Working_Support = m_Mediastinum = GetAFDB()->template GetImage("Mediastinum", true); + m_Working_Support = m_Mediastinum = this->GetAFDB()->template GetImage("Mediastinum", true); // Consider sup/inf to Carina double m_CarinaZ = FindCarina(); @@ -23,10 +21,10 @@ ExtractStationSupports() m_CarinaZ, true, GetBackgroundValue()); m_ListOfSupports["Support_Superior_to_Carina"] = m_Support_Superior_to_Carina; m_ListOfSupports["Support_Inferior_to_Carina"] = m_Support_Inferior_to_Carina; - writeImage(m_Support_Inferior_to_Carina, "seg/Support_Inf_Carina.mhd"); - GetAFDB()->SetImageFilename("Support_Inf_Carina", "seg/Support_Inf_Carina.mhd"); - writeImage(m_Support_Superior_to_Carina, "seg/Support_Sup_Carina.mhd"); - GetAFDB()->SetImageFilename("Support_Sup_Carina", "seg/Support_Sup_Carina.mhd"); + writeImage(m_Support_Inferior_to_Carina, "seg/Support_Inf_Carina.mha"); + this->GetAFDB()->SetImageFilename("Support_Inf_Carina", "seg/Support_Inf_Carina.mha"); + writeImage(m_Support_Superior_to_Carina, "seg/Support_Sup_Carina.mha"); + this->GetAFDB()->SetImageFilename("Support_Sup_Carina", "seg/Support_Sup_Carina.mha"); // S1RL Support_SupInf_S1RL(); @@ -59,45 +57,45 @@ ExtractStationSupports() m_ListOfSupports["S11"] = clitk::Clone(m_Support_Inferior_to_Carina); // Store image filenames into AFDB - writeImage(m_ListOfSupports["S1R"], "seg/Support_S1R.mhd"); - GetAFDB()->SetImageFilename("Support_S1R", "seg/Support_S1R.mhd"); - writeImage(m_ListOfSupports["S1L"], "seg/Support_S1L.mhd"); - GetAFDB()->SetImageFilename("Support_S1L", "seg/Support_S1L.mhd"); + writeImage(m_ListOfSupports["S1R"], "seg/Support_S1R.mha"); + this->GetAFDB()->SetImageFilename("Support_S1R", "seg/Support_S1R.mha"); + writeImage(m_ListOfSupports["S1L"], "seg/Support_S1L.mha"); + this->GetAFDB()->SetImageFilename("Support_S1L", "seg/Support_S1L.mha"); - writeImage(m_ListOfSupports["S2L"], "seg/Support_S2L.mhd"); - GetAFDB()->SetImageFilename("Support_S2L", "seg/Support_S2L.mhd"); - writeImage(m_ListOfSupports["S2R"], "seg/Support_S2R.mhd"); - GetAFDB()->SetImageFilename("Support_S2R", "seg/Support_S2R.mhd"); + writeImage(m_ListOfSupports["S2L"], "seg/Support_S2L.mha"); + this->GetAFDB()->SetImageFilename("Support_S2L", "seg/Support_S2L.mha"); + writeImage(m_ListOfSupports["S2R"], "seg/Support_S2R.mha"); + this->GetAFDB()->SetImageFilename("Support_S2R", "seg/Support_S2R.mha"); - writeImage(m_ListOfSupports["S3P"], "seg/Support_S3P.mhd"); - GetAFDB()->SetImageFilename("Support_S3P", "seg/Support_S3P.mhd"); - writeImage(m_ListOfSupports["S3A"], "seg/Support_S3A.mhd"); - GetAFDB()->SetImageFilename("Support_S3A", "seg/Support_S3A.mhd"); + writeImage(m_ListOfSupports["S3P"], "seg/Support_S3P.mha"); + this->GetAFDB()->SetImageFilename("Support_S3P", "seg/Support_S3P.mha"); + writeImage(m_ListOfSupports["S3A"], "seg/Support_S3A.mha"); + this->GetAFDB()->SetImageFilename("Support_S3A", "seg/Support_S3A.mha"); - writeImage(m_ListOfSupports["S4L"], "seg/Support_S4L.mhd"); - GetAFDB()->SetImageFilename("Support_S4L", "seg/Support_S4L.mhd"); - writeImage(m_ListOfSupports["S4R"], "seg/Support_S4R.mhd"); - GetAFDB()->SetImageFilename("Support_S4R", "seg/Support_S4R.mhd"); + writeImage(m_ListOfSupports["S4L"], "seg/Support_S4L.mha"); + this->GetAFDB()->SetImageFilename("Support_S4L", "seg/Support_S4L.mha"); + writeImage(m_ListOfSupports["S4R"], "seg/Support_S4R.mha"); + this->GetAFDB()->SetImageFilename("Support_S4R", "seg/Support_S4R.mha"); - writeImage(m_ListOfSupports["S5"], "seg/Support_S5.mhd"); - GetAFDB()->SetImageFilename("Support_S5", "seg/Support_S5.mhd"); - writeImage(m_ListOfSupports["S6"], "seg/Support_S6.mhd"); - GetAFDB()->SetImageFilename("Support_S6", "seg/Support_S6.mhd"); + writeImage(m_ListOfSupports["S5"], "seg/Support_S5.mha"); + this->GetAFDB()->SetImageFilename("Support_S5", "seg/Support_S5.mha"); + writeImage(m_ListOfSupports["S6"], "seg/Support_S6.mha"); + this->GetAFDB()->SetImageFilename("Support_S6", "seg/Support_S6.mha"); - writeImage(m_ListOfSupports["S7"], "seg/Support_S7.mhd"); - GetAFDB()->SetImageFilename("Support_S7", "seg/Support_S7.mhd"); + writeImage(m_ListOfSupports["S7"], "seg/Support_S7.mha"); + this->GetAFDB()->SetImageFilename("Support_S7", "seg/Support_S7.mha"); - writeImage(m_ListOfSupports["S8"], "seg/Support_S8.mhd"); - GetAFDB()->SetImageFilename("Support_S8", "seg/Support_S8.mhd"); + writeImage(m_ListOfSupports["S8"], "seg/Support_S8.mha"); + this->GetAFDB()->SetImageFilename("Support_S8", "seg/Support_S8.mha"); - writeImage(m_ListOfSupports["S9"], "seg/Support_S9.mhd"); - GetAFDB()->SetImageFilename("Support_S9", "seg/Support_S9.mhd"); + writeImage(m_ListOfSupports["S9"], "seg/Support_S9.mha"); + this->GetAFDB()->SetImageFilename("Support_S9", "seg/Support_S9.mha"); - writeImage(m_ListOfSupports["S10"], "seg/Support_S10.mhd"); - GetAFDB()->SetImageFilename("Support_S10", "seg/Support_S10.mhd"); + writeImage(m_ListOfSupports["S10"], "seg/Support_S10.mha"); + this->GetAFDB()->SetImageFilename("Support_S10", "seg/Support_S10.mha"); - writeImage(m_ListOfSupports["S11"], "seg/Support_S11.mhd"); - GetAFDB()->SetImageFilename("Support_S11", "seg/Support_S11.mhd"); + writeImage(m_ListOfSupports["S11"], "seg/Support_S11.mha"); + this->GetAFDB()->SetImageFilename("Support_S11", "seg/Support_S11.mha"); WriteAFDB(); } //-------------------------------------------------------------------- @@ -121,10 +119,12 @@ Support_SupInf_S1RL() => apex / manubrium = up Sternum */ m_Working_Support = m_ListOfSupports["Support_Superior_to_Carina"]; - MaskImagePointer Sternum = GetAFDB()->template GetImage ("Sternum"); + MaskImagePointer Sternum = this->GetAFDB()->template GetImage ("Sternum"); MaskImagePointType p; p[0] = p[1] = p[2] = 0.0; // to avoid warning clitk::FindExtremaPointInAGivenDirection(Sternum, GetBackgroundValue(), 2, false, p); + // DD(p); + p[2] += Sternum->GetSpacing()[2]; // add one slice: start just superiorly MaskImagePointer S1RL = clitk::CropImageRemoveLowerThan(m_Working_Support, 2, p[2], true, GetBackgroundValue()); @@ -147,7 +147,7 @@ Support_LeftRight_S1R_S1L() std::vector A; std::vector B; // Search for centroid positions of trachea - MaskImagePointer Trachea = GetAFDB()->template GetImage ("Trachea"); + MaskImagePointer Trachea = this->GetAFDB()->template GetImage ("Trachea"); MaskImagePointer S1RL = m_ListOfSupports["S1RL"]; Trachea = clitk::ResizeImageLike(Trachea, S1RL, GetBackgroundValue()); std::vector slices; @@ -172,13 +172,13 @@ Support_LeftRight_S1R_S1L() // Right part clitk::SliceBySliceSetBackgroundFromLineSeparation(S1R, A, B, - GetBackgroundValue(), 0, 10); + GetBackgroundValue(), 0, -10); S1R = clitk::AutoCrop(S1R, GetBackgroundValue()); m_ListOfSupports["S1R"] = S1R; // Left part clitk::SliceBySliceSetBackgroundFromLineSeparation(S1L, A, B, - GetBackgroundValue(), 0, -10); + GetBackgroundValue(), 0, 10); S1L = clitk::AutoCrop(S1L, GetBackgroundValue()); m_ListOfSupports["S1L"] = S1L; } @@ -201,36 +201,73 @@ Support_SupInf_S2R_S2L() m_Working_Support = m_ListOfSupports["Support_Superior_to_Carina"]; // S2R Caudal Margin Of Left BrachiocephalicVein - MaskImagePointer BrachioCephalicVein = GetAFDB()->template GetImage("BrachioCephalicVein"); + MaskImagePointer BrachioCephalicVein = this->GetAFDB()->template GetImage("BrachioCephalicVein"); MaskImagePointType p; clitk::FindExtremaPointInAGivenDirection(BrachioCephalicVein, GetBackgroundValue(), 2, true, p); - // I add slightly more than a slice - double CaudalMarginOfLeftBrachiocephalicVeinZ=p[2]+ 1.1*m_Working_Support->GetSpacing()[2]; - GetAFDB()->SetDouble("CaudalMarginOfLeftBrachiocephalicVeinZ", CaudalMarginOfLeftBrachiocephalicVeinZ); + + // I add slightly more than a slice --> NO !! + double CaudalMarginOfLeftBrachiocephalicVeinZ=p[2];//+ 1.1*m_Working_Support->GetSpacing()[2]; + + this->GetAFDB()->SetDouble("CaudalMarginOfLeftBrachiocephalicVeinZ", CaudalMarginOfLeftBrachiocephalicVeinZ); MaskImagePointer S2R = clitk::CropImageRemoveLowerThan(m_Working_Support, 2, CaudalMarginOfLeftBrachiocephalicVeinZ, true, GetBackgroundValue()); - m_ListOfSupports["S2R"] = S2R; - // S2L : Top Of Aortic Arch - MaskImagePointer Aorta = GetAFDB()->template GetImage("Aorta"); + MaskImagePointer Aorta = this->GetAFDB()->template GetImage("Aorta"); clitk::FindExtremaPointInAGivenDirection(Aorta, GetBackgroundValue(), 2, false, p); - // I add slightly more than a slice - double TopOfAorticArchZ=p[2]+ 1.1*m_Working_Support->GetSpacing()[2]; - GetAFDB()->SetDouble("TopOfAorticArchZ", TopOfAorticArchZ); + + // Save the TopOfAorticArchZ + this->GetAFDB()->SetDouble("TopOfAorticArchZ", p[2]); + + // I substract slightly more than a slice to respect delineation + double TopOfAorticArchZ=p[2]- 1.1*m_Working_Support->GetSpacing()[2]; + // this->GetAFDB()->SetDouble("TopOfAorticArchZ", TopOfAorticArchZ); MaskImagePointer S2L = clitk::CropImageRemoveLowerThan(m_Working_Support, 2, TopOfAorticArchZ, true, GetBackgroundValue()); + + /* + // S2RL: Superior support, I use inferior part of S1RL + MaskImagePointer S1L = m_ListOfSupports["S1L"]; + clitk::FindExtremaPointInAGivenDirection(S1L, GetBackgroundValue(), 2, true, p); + DD(p); + S2L = + clitk::CropImageRemoveGreaterThan(S2L, 2, + p[2], true, + GetBackgroundValue()); + + MaskImagePointer S1R = m_ListOfSupports["S1R"]; + clitk::FindExtremaPointInAGivenDirection(S1R, GetBackgroundValue(), 2, true, p); + DD(p); + S2R = + clitk::CropImageRemoveGreaterThan(S2R, 2, + p[2], true, + GetBackgroundValue()); + */ + + // Superior limits, use Sternum (but not strictly inf to S1RL + MaskImagePointer Sternum = this->GetAFDB()->template GetImage ("Sternum"); + clitk::FindExtremaPointInAGivenDirection(Sternum, GetBackgroundValue(), 2, false, p); + // Add one slice + p[2] = p[2] + m_Working_Support->GetSpacing()[2]; + S2L = + clitk::CropImageRemoveGreaterThan(S2L, 2, + p[2], true, GetBackgroundValue()); + S2R = + clitk::CropImageRemoveGreaterThan(S2R, 2, + p[2], true, GetBackgroundValue()); + + // The is the end m_ListOfSupports["S2L"] = S2L; + m_ListOfSupports["S2R"] = S2R; } //-------------------------------------------------------------------- - //-------------------------------------------------------------------- template void @@ -251,7 +288,7 @@ Support_LeftRight_S2R_S2L() S2L = LimitsWithTrachea(S2L, 0, 1, 10); m_ListOfSupports["S2R"] = S2R; m_ListOfSupports["S2L"] = S2L; - GetAFDB()->template ReleaseImage("Trachea"); + this->GetAFDB()->template ReleaseImage("Trachea"); } //-------------------------------------------------------------------- @@ -277,24 +314,32 @@ Support_SupInf_S4R_S4L() */ StartNewStep("[Support] Sup-Inf limits of 4R/4L"); - // Start from the support, remove 2R and 2L + // Start from the support MaskImagePointer S4RL = clitk::Clone(m_Working_Support); + MaskImagePointer S4R = clitk::Clone(S4RL); + MaskImagePointer S4L = clitk::Clone(S4RL); + + // Keep only what is lower than S2 MaskImagePointer S2R = m_ListOfSupports["S2R"]; MaskImagePointer S2L = m_ListOfSupports["S2L"]; - clitk::AndNot(S4RL, S2R, GetBackgroundValue()); - clitk::AndNot(S4RL, S2L, GetBackgroundValue()); - S4RL = clitk::AutoCrop(S4RL, GetBackgroundValue()); + MaskImagePointType p; + // Right part + clitk::FindExtremaPointInAGivenDirection(S2R, GetBackgroundValue(), + 2, true, p); + S4R = clitk::CropImageRemoveGreaterThan(S4R, 2, + p[2], true, GetBackgroundValue()); + // Left part + clitk::FindExtremaPointInAGivenDirection(S2L, GetBackgroundValue(), + 2, true, p); + S4L = clitk::CropImageRemoveGreaterThan(S4L, 2, + p[2], true, GetBackgroundValue()); - // Copy, stop 4R at AzygousVein and 4L at LeftPulmonaryArtery - MaskImagePointer S4R = clitk::Clone(S4RL); - MaskImagePointer S4L = clitk::Clone(S4RL); - // Get AzygousVein and limit according to LowerBorderAzygousVein MaskImagePointer LowerBorderAzygousVein - = GetAFDB()->template GetImage("LowerBorderAzygousVein"); + = this->GetAFDB()->template GetImage("LowerBorderAzygousVein"); std::vector c; clitk::ComputeCentroids(LowerBorderAzygousVein, GetBackgroundValue(), c); - S4R = clitk::CropImageRemoveLowerThan(S4RL, 2, + S4R = clitk::CropImageRemoveLowerThan(S4R, 2, c[1][2], true, GetBackgroundValue()); S4R = clitk::AutoCrop(S4R, GetBackgroundValue()); m_ListOfSupports["S4R"] = S4R; @@ -302,11 +347,10 @@ Support_SupInf_S4R_S4L() // Limit according to LeftPulmonaryArtery MaskImagePointer LeftPulmonaryArtery - = GetAFDB()->template GetImage("LeftPulmonaryArtery"); - MaskImagePointType p; + = this->GetAFDB()->template GetImage("LeftPulmonaryArtery"); clitk::FindExtremaPointInAGivenDirection(LeftPulmonaryArtery, GetBackgroundValue(), 2, false, p); - S4L = clitk::CropImageRemoveLowerThan(S4RL, 2, + S4L = clitk::CropImageRemoveLowerThan(S4L, 2, p[2], true, GetBackgroundValue()); S4L = clitk::AutoCrop(S4L, GetBackgroundValue()); m_ListOfSupports["S4L"] = S4L; @@ -366,7 +410,7 @@ LimitsWithTrachea(MaskImageType * input, int extremaDirection, int lineDirection the offset */ // Read the trachea - MaskImagePointer Trachea = GetAFDB()->template GetImage("Trachea"); + MaskImagePointer Trachea = this->GetAFDB()->template GetImage("Trachea"); // Find extrema post positions std::vector tracheaLeftPositionsA; @@ -387,7 +431,7 @@ LimitsWithTrachea(MaskImageType * input, int extremaDirection, int lineDirection GetBackgroundValue(), 2, extremaDirection, false, // Left lineDirection, // Vertical line - 1, // margins + -1, // margins tracheaLeftPositionsA, tracheaLeftPositionsB); // Do not consider trachea above the limit @@ -479,11 +523,11 @@ Support_S3A() //double m_ApexOfTheChest = FindApexOfTheChest(); - MaskImagePointer Sternum = GetAFDB()->template GetImage ("Sternum"); + MaskImagePointer Sternum = this->GetAFDB()->template GetImage ("Sternum"); MaskImagePointType p; p[0] = p[1] = p[2] = 0.0; // to avoid warning clitk::FindExtremaPointInAGivenDirection(Sternum, GetBackgroundValue(), 2, false, p); - + p[2] += Sternum->GetSpacing()[2]; // we add one slice to stop 3A at the same slice than Sternum stop S3A = clitk::CropImageRemoveGreaterThan(S3A, 2, //m_ApexOfTheChest @@ -502,20 +546,22 @@ void clitk::ExtractLymphStationsFilter:: Support_S5() { - StartNewStep("[Support] Sup-Inf limits S5 with aorta"); + StartNewStep("[Support] Sup-Inf limits S5 with Aorta and MainPulmonaryArtery"); // Initial S5 support - MaskImagePointer S5 = clitk::Clone(GetAFDB()->template GetImage("Mediastinum", true)); + MaskImagePointer S5 = + clitk::Clone(this->GetAFDB()->template GetImage("Mediastinum", true)); // Sup limits with Aorta double sup = FindInferiorBorderOfAorticArch(); // Inf limits with "upper rim of the left main pulmonary artery" // For the moment only, it will change. - MaskImagePointer PulmonaryTrunk = GetAFDB()->template GetImage("PulmonaryTrunk"); + MaskImagePointer MainPulmonaryArtery = this->GetAFDB()->template GetImage("MainPulmonaryArtery"); MaskImagePointType p; p[0] = p[1] = p[2] = 0.0; // to avoid warning - clitk::FindExtremaPointInAGivenDirection(PulmonaryTrunk, GetBackgroundValue(), 2, false, p); + clitk::FindExtremaPointInAGivenDirection(MainPulmonaryArtery, GetBackgroundValue(), 2, false, p); + p[2] += MainPulmonaryArtery->GetSpacing()[2]; // Cut Sup/Inf S5 = clitk::CropImageAlongOneAxis(S5, 2, p[2], sup, true, GetBackgroundValue());