From f45a4930b0c399e69ad52f2f14e33a849033f1e9 Mon Sep 17 00:00:00 2001 From: Romulo Pinho Date: Wed, 6 Jul 2011 13:27:26 +0200 Subject: [PATCH] optional opening after 1st step in ExtractPatient - controlled by the radius given on the cmd line --- segmentation/clitkExtractPatient.ggo | 1 + segmentation/clitkExtractPatientFilter.h | 5 +++- segmentation/clitkExtractPatientFilter.txx | 27 +++++++++++++++++-- .../clitkExtractPatientGenericFilter.txx | 1 + 4 files changed, 31 insertions(+), 3 deletions(-) diff --git a/segmentation/clitkExtractPatient.ggo b/segmentation/clitkExtractPatient.ggo index 5c2861d..f494440 100644 --- a/segmentation/clitkExtractPatient.ggo +++ b/segmentation/clitkExtractPatient.ggo @@ -22,6 +22,7 @@ section "Binarize" option "lower" - "Initial lower threshold" double no option "upper" - "Initial upper threshold" double no default="-300" +option "openingRadius" - "Radius for opening after threshold" int no default="0" section "First Label Image (air=1)" diff --git a/segmentation/clitkExtractPatientFilter.h b/segmentation/clitkExtractPatientFilter.h index b612fd3..fe290cc 100644 --- a/segmentation/clitkExtractPatientFilter.h +++ b/segmentation/clitkExtractPatientFilter.h @@ -98,7 +98,9 @@ namespace clitk { itkSetMacro(LowerThreshold, InputImagePixelType); itkGetMacro(LowerThreshold, InputImagePixelType); - itkSetMacro(UseLowerThreshold, bool); + itkSetMacro(UseLowerThreshold, bool); + itkGetMacro(PrimaryOpeningRadius, unsigned int); + itkSetMacro(PrimaryOpeningRadius, unsigned int); itkGetConstMacro(UseLowerThreshold, bool); itkBooleanMacro(UseLowerThreshold); @@ -165,6 +167,7 @@ namespace clitk { bool m_DecomposeAndReconstructDuringFirstStep; bool m_DecomposeAndReconstructDuringSecondStep; bool m_FinalOpenClose; + unsigned m_PrimaryOpeningRadius; InternalImageSizeType m_Radius1; InternalImageSizeType m_Radius2; int m_MaximumNumberOfLabels1; diff --git a/segmentation/clitkExtractPatientFilter.txx b/segmentation/clitkExtractPatientFilter.txx index 00e3165..43e8a9b 100644 --- a/segmentation/clitkExtractPatientFilter.txx +++ b/segmentation/clitkExtractPatientFilter.txx @@ -48,6 +48,7 @@ ExtractPatientFilter(): this->SetNumberOfRequiredInputs(1); SetBackgroundValue(0); // Must be zero SetForegroundValue(1); + SetPrimaryOpeningRadius(0); // Step 1: Threshold + CC + sort (Find low density areas) SetUpperThreshold(-300); @@ -134,14 +135,36 @@ GenerateOutputInformation() { binarizeFilter->SetUpperThreshold(GetUpperThreshold()); binarizeFilter ->SetInsideValue(this->GetForegroundValue()); binarizeFilter ->SetOutsideValue(this->GetBackgroundValue()); + working_image = binarizeFilter->GetOutput(); + typedef itk::BinaryBallStructuringElement KernelType; + unsigned int radius = this->GetPrimaryOpeningRadius(); + if (radius > 0) + { + if (this->GetVerboseOptionFlag()) std::cout << ("Opening after threshold; R = ") << radius << std::endl; + KernelType kernel; + kernel.SetRadius(radius); + + typedef itk::BinaryMorphologicalOpeningImageFilter OpenFilterType2; + typename OpenFilterType2::Pointer openFilter2 = OpenFilterType2::New(); + openFilter2->SetInput(working_image); + openFilter2->SetBackgroundValue(0); + openFilter2->SetForegroundValue(1); + openFilter2->SetKernel(kernel); + openFilter2->Update(); + working_image = openFilter2->GetOutput(); + } + + if (this->GetVerboseOptionFlag()) std::cout << ("Labelling") << std::endl; // Connected component labeling typedef itk::ConnectedComponentImageFilter ConnectFilterType; typename ConnectFilterType::Pointer connectFilter=ConnectFilterType::New(); - connectFilter->SetInput(binarizeFilter->GetOutput()); + connectFilter->SetInput(working_image); connectFilter->SetBackgroundValue(this->GetBackgroundValue()); connectFilter->SetFullyConnected(false); + connectFilter->Update(); + if (this->GetVerboseOptionFlag()) std::cout << ("RelabelComponentImageFilter") << std::endl; // Sort labels according to size typedef itk::RelabelComponentImageFilter RelabelFilterType; typename RelabelFilterType::Pointer relabelFilter=RelabelFilterType::New(); @@ -175,6 +198,7 @@ GenerateOutputInformation() { //-------------------------------------------------------------------- //-------------------------------------------------------------------- + if (this->GetVerboseOptionFlag()) std::cout << ("Remove the air (largest area)") << std::endl; StartNewStep("Remove the air (largest area)"); typedef itk::BinaryThresholdImageFilter iBinarizeFilterType; typename iBinarizeFilterType::Pointer binarizeFilter2 = iBinarizeFilterType::New(); @@ -226,7 +250,6 @@ GenerateOutputInformation() { if (GetFinalOpenClose()) { StartNewStep("Final OpenClose"); // Open - typedef itk::BinaryBallStructuringElement KernelType; KernelType structuringElement; structuringElement.SetRadius(1); structuringElement.CreateStructuringElement(); diff --git a/segmentation/clitkExtractPatientGenericFilter.txx b/segmentation/clitkExtractPatientGenericFilter.txx index a8fbad8..e7d4ebe 100644 --- a/segmentation/clitkExtractPatientGenericFilter.txx +++ b/segmentation/clitkExtractPatientGenericFilter.txx @@ -75,6 +75,7 @@ SetOptionsFromArgsInfoToFilter(FilterType * f) f->SetUpperThreshold(mArgsInfo.upper_arg); f->SetLowerThreshold(mArgsInfo.lower_arg); + f->SetPrimaryOpeningRadius(mArgsInfo.openingRadius_arg); f->SetDecomposeAndReconstructDuringFirstStep(mArgsInfo.erode1_flag); -- 2.47.1