X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=segmentation%2FclitkExtractLymphStationsFilter.txx;h=b81ae07ab7e5748f0edf12ee673b03cced2d434e;hb=22681675b0ed087fd02fbd94968d5ea5251f5408;hp=0bcb447d2a90804f1643dd28a17e7b418760e698;hpb=e008d74b0ecdc4ca2eaae8c429901a78f9ef5c31;p=clitk.git diff --git a/segmentation/clitkExtractLymphStationsFilter.txx b/segmentation/clitkExtractLymphStationsFilter.txx index 0bcb447..b81ae07 100644 --- a/segmentation/clitkExtractLymphStationsFilter.txx +++ b/segmentation/clitkExtractLymphStationsFilter.txx @@ -23,17 +23,18 @@ #include "clitkCommon.h" #include "clitkExtractLymphStationsFilter.h" #include "clitkAddRelativePositionConstraintToLabelImageFilter.h" -#include "clitkSegmentationFunctions.h" +#include "clitkSegmentationUtils.h" #include "clitkAutoCropFilter.h" -#include "clitkSegmentationFunctions.h" +#include "clitkSegmentationUtils.h" +#include "clitkSliceBySliceRelativePositionFilter.h" // itk -#include #include #include #include #include #include +#include // itk ENST #include "RelativePositionPropImageFilter.h" @@ -43,6 +44,7 @@ template clitk::ExtractLymphStationsFilter:: ExtractLymphStationsFilter(): clitk::FilterBase(), + clitk::FilterWithAnatomicalFeatureDatabaseManagement(), itk::ImageToImageFilter() { this->SetNumberOfRequiredInputs(1); @@ -50,9 +52,9 @@ ExtractLymphStationsFilter(): SetBackgroundValueTrachea(0); SetBackgroundValue(0); SetForegroundValue(1); - SetIntermediateSpacing(6); - SetFuzzyThreshold1(0.6); + SetFuzzyThreshold1(0.6); + m_CarinaZPositionInMMIsSet = false; } //-------------------------------------------------------------------- @@ -63,11 +65,7 @@ void clitk::ExtractLymphStationsFilter:: SetInputMediastinumLabelImage(const TImageType * image, ImagePixelType bg) { this->SetNthInput(0, const_cast(image)); - m_BackgroundValueMediastinum = bg; - SetCarenaZPositionInMM(image->GetOrigin()[2]+image->GetLargestPossibleRegion().GetSize()[2]*image->GetSpacing()[2]); - SetMiddleLobeBronchusZPositionInMM(image->GetOrigin()[2]); - // DD(m_CarenaZPositionInMM); -// DD(m_MiddleLobeBronchusZPositionInMM); + SetBackgroundValueMediastinum(bg); } //-------------------------------------------------------------------- @@ -78,7 +76,7 @@ void clitk::ExtractLymphStationsFilter:: SetInputTracheaLabelImage(const TImageType * image, ImagePixelType bg) { this->SetNthInput(1, const_cast(image)); - m_BackgroundValueTrachea = bg; + SetBackgroundValueTrachea(bg); } //-------------------------------------------------------------------- @@ -94,11 +92,12 @@ SetArgsInfo(ArgsInfoType mArgsInfo) SetVerboseStep_GGO(mArgsInfo); SetWriteStep_GGO(mArgsInfo); SetVerboseWarningOff_GGO(mArgsInfo); - SetCarenaZPositionInMM_GGO(mArgsInfo); + SetAFDBFilename_GGO(mArgsInfo); + SetCarinaZPositionInMM_GGO(mArgsInfo); + m_CarinaZPositionInMMIsSet = false; SetMiddleLobeBronchusZPositionInMM_GGO(mArgsInfo); SetIntermediateSpacing_GGO(mArgsInfo); SetFuzzyThreshold1_GGO(mArgsInfo); - //SetBackgroundValueMediastinum_GGO(mArgsInfo); } //-------------------------------------------------------------------- @@ -113,19 +112,29 @@ GenerateOutputInformation() { // Get input m_mediastinum = dynamic_cast(itk::ProcessObject::GetInput(0)); m_trachea = dynamic_cast(itk::ProcessObject::GetInput(1)); - + + // Get landmarks information + if (!m_CarinaZPositionInMMIsSet) { + ImagePointType carina; + LoadAFDB(); + GetAFDB()->GetPoint3D("Carina", carina); + DD(carina); + m_CarinaZPositionInMM = carina[2]; + } + DD(m_CarinaZPositionInMM); + // ---------------------------------------------------------------- // ---------------------------------------------------------------- - // Superior limit = carena - // Inferior limit = origine middle lobe bronchus - StartNewStep("Inf/Sup limits with carena/bronchus"); + // Superior limit = carina + // Inferior limit = origin right middle lobe bronchus + StartNewStep("Inf/Sup mediastinum limits with carina/bronchus"); ImageRegionType region = m_mediastinum->GetLargestPossibleRegion(); DD(region); ImageSizeType size = region.GetSize(); ImageIndexType index = region.GetIndex(); - DD(m_CarenaZPositionInMM); + DD(m_CarinaZPositionInMM); DD(m_MiddleLobeBronchusZPositionInMM); index[2] = floor((m_MiddleLobeBronchusZPositionInMM - m_mediastinum->GetOrigin()[2]) / m_mediastinum->GetSpacing()[2]); - size[2] = ceil((m_CarenaZPositionInMM-m_MiddleLobeBronchusZPositionInMM) / m_mediastinum->GetSpacing()[2]); + size[2] = 1+ceil((m_CarinaZPositionInMM-m_MiddleLobeBronchusZPositionInMM) / m_mediastinum->GetSpacing()[2]); // +1 to region.SetSize(size); region.SetIndex(index); DD(region); @@ -143,7 +152,7 @@ GenerateOutputInformation() { // ---------------------------------------------------------------- // ---------------------------------------------------------------- // Separate trachea in two CCL - StartNewStep("Separate trachea"); + StartNewStep("Separate trachea under carina"); // DD(region); ImageRegionType trachea_region = m_trachea->GetLargestPossibleRegion(); for(int i=0; i<3; i++) { @@ -175,8 +184,7 @@ GenerateOutputInformation() { // Labelize and consider two main labels m_working_trachea = Labelize(m_working_trachea, 0, true, 1); - StopCurrentStep(m_working_trachea); - + // Detect wich label is at Left typedef itk::ImageSliceConstIteratorWithIndex SliceIteratorType; SliceIteratorType iter(m_working_trachea, m_working_trachea->GetLargestPossibleRegion()); @@ -185,6 +193,7 @@ GenerateOutputInformation() { iter.GoToBegin(); bool stop = false; ImagePixelType leftLabel; + ImagePixelType rightLabel; while (!stop) { if (iter.Get() != m_BackgroundValueTrachea) { // DD(iter.GetIndex()); @@ -194,52 +203,65 @@ GenerateOutputInformation() { } ++iter; } + if (leftLabel == 1) rightLabel = 2; + else rightLabel = 1; DD((int)leftLabel); + DD((int)rightLabel); + + // End step + StopCurrentStep(m_working_trachea); - // Relative position - StartNewStep("Left/Right limits with trachea"); + //----------------------------------------------------- + /* DD("TEST Skeleton"); + typedef itk::BinaryThinningImageFilter SkeletonFilterType; + typename SkeletonFilterType::Pointer skeletonFilter = SkeletonFilterType::New(); + skeletonFilter->SetInput(m_working_trachea); + skeletonFilter->Update(); + writeImage(skeletonFilter->GetOutput(), "skel.mhd"); + writeImage(skeletonFilter->GetThinning(), "skel2.mhd"); + */ - // Select LeftLabel (set label 1 to 0) - ImagePointer temp = SetBackground(m_working_trachea, m_working_trachea, 1, 0); + //----------------------------------------------------- + StartNewStep("Left limits with bronchus (slice by slice)"); + // Select LeftLabel (set right label to 0) + ImagePointer temp = SetBackground(m_working_trachea, m_working_trachea, rightLabel, 0); writeImage(temp, "temp1.mhd"); - // Left relative position - typedef clitk::AddRelativePositionConstraintToLabelImageFilter RelPosFilterType; - typename RelPosFilterType::Pointer relPosFilter = RelPosFilterType::New(); - relPosFilter->SetCurrentStepBaseId(this->GetCurrentStepId()); - relPosFilter->VerboseStepOff(); - relPosFilter->WriteStepOff(); - relPosFilter->SetInput(m_working_image); - relPosFilter->SetInputObject(temp); - relPosFilter->SetOrientationType(RelPosFilterType::RightTo); - relPosFilter->SetIntermediateSpacing(GetIntermediateSpacing()); - relPosFilter->SetFuzzyThreshold(GetFuzzyThreshold1()); - relPosFilter->Update(); - m_working_image = relPosFilter->GetOutput(); - - // Select RightLabel (set label 2 to 0) - temp = SetBackground(m_working_trachea, m_working_trachea, 2, 0); - writeImage(temp, "temp2.mhd"); - - // Left relative position - relPosFilter = RelPosFilterType::New(); - relPosFilter->SetCurrentStepBaseId(this->GetCurrentStepId()); - relPosFilter->VerboseStepOn(); - relPosFilter->WriteStepOn(); - relPosFilter->SetInput(m_working_image); - relPosFilter->SetInputObject(temp); - relPosFilter->SetOrientationType(RelPosFilterType::LeftTo); - relPosFilter->SetIntermediateSpacing(GetIntermediateSpacing()); - relPosFilter->SetFuzzyThreshold(GetFuzzyThreshold1()); - relPosFilter->Update(); - m_working_image = relPosFilter->GetOutput(); + typedef clitk::SliceBySliceRelativePositionFilter SliceRelPosFilterType; + typename SliceRelPosFilterType::Pointer sliceRelPosFilter = SliceRelPosFilterType::New(); + sliceRelPosFilter->SetCurrentStepBaseId(this->GetCurrentStepId()); + sliceRelPosFilter->VerboseStepOn(); + sliceRelPosFilter->WriteStepOn(); + sliceRelPosFilter->SetInput(m_working_image); + sliceRelPosFilter->SetInputObject(temp); + sliceRelPosFilter->SetDirection(2); + sliceRelPosFilter->SetFuzzyThreshold(0.6); + sliceRelPosFilter->SetOrientationType(SliceRelPosFilterType::RelPosFilterType::RightTo); + sliceRelPosFilter->Update(); + m_working_image = sliceRelPosFilter->GetOutput(); + writeImage(m_working_image, "afterslicebyslice.mhd"); //----------------------------------------------------- - // StartNewStep("Left/Right limits with trachea (slice by slice"); - // typedef SliceBySliceImageFilter(m_working_trachea, m_working_trachea, leftLabel, 0); + writeImage(temp, "temp2.mhd"); + + sliceRelPosFilter = SliceRelPosFilterType::New(); + sliceRelPosFilter->SetCurrentStepBaseId(this->GetCurrentStepId()); + sliceRelPosFilter->VerboseStepOn(); + sliceRelPosFilter->WriteStepOn(); + sliceRelPosFilter->SetInput(m_working_image); + sliceRelPosFilter->SetInputObject(temp); + sliceRelPosFilter->SetDirection(2); + sliceRelPosFilter->SetFuzzyThreshold(0.6); + sliceRelPosFilter->SetOrientationType(SliceRelPosFilterType::RelPosFilterType::LeftTo); + sliceRelPosFilter->Update(); + m_working_image = sliceRelPosFilter->GetOutput(); + writeImage(m_working_image, "afterslicebyslice.mhd"); + - DD("end"); m_output = m_working_image; StopCurrentStep(m_output);