X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=segmentation%2FclitkExtractPatientFilter.txx;h=43e8a9b27bc79ba6b74247fc6a857ed7d2ed08ae;hb=f3c961676689a38cca96888462ddb9689d9e0217;hp=74cc2ccd0f7cc1909b7c70f3335583a2eb88d8d7;hpb=667a674794cf667db213d3c03f2d4b5d907ca35d;p=clitk.git diff --git a/segmentation/clitkExtractPatientFilter.txx b/segmentation/clitkExtractPatientFilter.txx index 74cc2cc..43e8a9b 100644 --- a/segmentation/clitkExtractPatientFilter.txx +++ b/segmentation/clitkExtractPatientFilter.txx @@ -1,7 +1,7 @@ /*========================================================================= Program: vv http://www.creatis.insa-lyon.fr/rio/vv - Authors belong to: + Authors belong to: - University of LYON http://www.universite-lyon.fr/ - Léon Bérard cancer center http://www.centreleonberard.fr - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr @@ -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); @@ -69,11 +70,11 @@ ExtractPatientFilter(): SetRadius2(r); SetMaximumNumberOfLabels2(2); SetNumberOfNewLabels2(1); - + // Step 5: Only keep label corresponding (Keep patient's labels) SetFirstKeep(1); SetLastKeep(1); - + // Step 4: OpenClose (option) FinalOpenCloseOff(); AutoCropOn(); @@ -83,9 +84,9 @@ ExtractPatientFilter(): //-------------------------------------------------------------------- template -void +void clitk::ExtractPatientFilter:: -SetInput(const TInputImageType * image) +SetInput(const TInputImageType * image) { this->SetNthInput(0, const_cast(image)); } @@ -94,9 +95,9 @@ SetInput(const TInputImageType * image) //-------------------------------------------------------------------- template -void +void clitk::ExtractPatientFilter:: -GenerateOutputInformation() { +GenerateOutputInformation() { clitk::PrintMemory(GetVerboseMemoryFlag(), "Initial memory"); // OK @@ -109,10 +110,10 @@ GenerateOutputInformation() { // Get input pointers static const unsigned int Dim = InputImageType::ImageDimension; //input = dynamic_cast(itk::ProcessObject::GetInput(0)); - + //-------------------------------------------------------------------- //-------------------------------------------------------------------- - // Step 1: + // Step 1: StartNewStep("Find low densities areas"); // Pad images with air to prevent patient touching the image border @@ -127,21 +128,43 @@ GenerateOutputInformation() { padFilter->SetPadLowerBound(bounds); padFilter->SetPadUpperBound(bounds); - typedef itk::BinaryThresholdImageFilter BinarizeFilterType; + typedef itk::BinaryThresholdImageFilter BinarizeFilterType; typename BinarizeFilterType::Pointer binarizeFilter=BinarizeFilterType::New(); binarizeFilter->SetInput(padFilter->GetOutput()); if (m_UseLowerThreshold) binarizeFilter->SetLowerThreshold(GetLowerThreshold()); 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(); @@ -149,13 +172,13 @@ GenerateOutputInformation() { relabelFilter->SetInput(connectFilter->GetOutput()); relabelFilter->Update(); working_image = relabelFilter->GetOutput(); - + // End StopCurrentStep(working_image); //-------------------------------------------------------------------- //-------------------------------------------------------------------- - // [Optional] + // [Optional] if (GetDecomposeAndReconstructDuringFirstStep()) { StartNewStep("First Decompose & Reconstruct step"); typedef clitk::DecomposeAndReconstructImageFilter FilterType; @@ -172,11 +195,12 @@ GenerateOutputInformation() { working_image = f->GetOutput(); StopCurrentStep(working_image); } - + //-------------------------------------------------------------------- //-------------------------------------------------------------------- + if (this->GetVerboseOptionFlag()) std::cout << ("Remove the air (largest area)") << std::endl; StartNewStep("Remove the air (largest area)"); - typedef itk::BinaryThresholdImageFilter iBinarizeFilterType; + typedef itk::BinaryThresholdImageFilter iBinarizeFilterType; typename iBinarizeFilterType::Pointer binarizeFilter2 = iBinarizeFilterType::New(); binarizeFilter2->SetInput(working_image); binarizeFilter2->SetLowerThreshold(GetFirstKeep()); @@ -194,15 +218,15 @@ GenerateOutputInformation() { relabelFilter2->SetInput(connectFilter2->GetOutput()); relabelFilter2->Update(); working_image = relabelFilter2->GetOutput(); - + // Keep main label working_image = KeepLabels - (working_image, GetBackgroundValue(), GetForegroundValue(), 1, 1, true); + (working_image, GetBackgroundValue(), GetForegroundValue(), 1, 1, true); StopCurrentStep(working_image); //-------------------------------------------------------------------- //-------------------------------------------------------------------- - // [Optional] + // [Optional] if (GetDecomposeAndReconstructDuringSecondStep()) { StartNewStep("Second Decompose & Reconstruct step"); typedef clitk::DecomposeAndReconstructImageFilter FilterType; @@ -226,7 +250,6 @@ GenerateOutputInformation() { if (GetFinalOpenClose()) { StartNewStep("Final OpenClose"); // Open - typedef itk::BinaryBallStructuringElement KernelType; KernelType structuringElement; structuringElement.SetRadius(1); structuringElement.CreateStructuringElement(); @@ -235,7 +258,7 @@ GenerateOutputInformation() { openFilter->SetInput(working_image); openFilter->SetBackgroundValue(this->GetBackgroundValue()); openFilter->SetForegroundValue(this->GetForegroundValue()); - openFilter->SetKernel(structuringElement); + openFilter->SetKernel(structuringElement); // Close typedef itk::BinaryMorphologicalClosingImageFilter CloseFilterType; typename CloseFilterType::Pointer closeFilter = CloseFilterType::New(); @@ -244,14 +267,14 @@ GenerateOutputInformation() { closeFilter->SetForegroundValue(this->GetForegroundValue()); // closeFilter->SetBackgroundValue(SetBackgroundValue()); closeFilter->SetKernel(structuringElement); - closeFilter->Update(); + closeFilter->Update(); working_image = closeFilter->GetOutput(); StopCurrentStep(working_image); } //-------------------------------------------------------------------- //-------------------------------------------------------------------- - // Final Cast + // Final Cast typedef itk::CastImageFilter CastImageFilterType; typename CastImageFilterType::Pointer caster= CastImageFilterType::New(); caster->SetInput(working_image); @@ -267,7 +290,7 @@ GenerateOutputInformation() { typename CropFilterType::Pointer cropFilter = CropFilterType::New(); cropFilter->SetInput(output); cropFilter->SetBackgroundValue(GetBackgroundValue()); - cropFilter->Update(); + cropFilter->Update(); output = cropFilter->GetOutput(); StopCurrentStep(output); } @@ -288,16 +311,16 @@ GenerateOutputInformation() { //-------------------------------------------------------------------- template -void +void clitk::ExtractPatientFilter:: GenerateData() { // Final Graft this->GraftOutput(output); // Store image filename into AFDB - GetAFDB()->SetImageFilename("Patient", this->GetOutputPatientFilename()); + GetAFDB()->SetImageFilename("Patient", this->GetOutputPatientFilename()); WriteAFDB(); } //-------------------------------------------------------------------- - + #endif //#define CLITKBOOLEANOPERATORLABELIMAGEFILTER_TXX