X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=segmentation%2FclitkExtractPatientFilter.txx;h=00e31653afce00e5ea32c5a91a1218fbe39251fa;hb=703487ce9c727034bddad25e1b33750a835f7caf;hp=e9dd6fe57bd8da7f034b7c27634c99376ebbccad;hpb=7c4ea05111826e62fe6efc7886dd9b034abf7cd1;p=clitk.git diff --git a/segmentation/clitkExtractPatientFilter.txx b/segmentation/clitkExtractPatientFilter.txx index e9dd6fe..00e3165 100644 --- a/segmentation/clitkExtractPatientFilter.txx +++ b/segmentation/clitkExtractPatientFilter.txx @@ -1,9 +1,9 @@ /*========================================================================= 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://oncora1.lyon.fnclcc.fr + - Léon Bérard cancer center http://www.centreleonberard.fr - CREATIS CNRS laboratory http://www.creatis.insa-lyon.fr This software is distributed WITHOUT ANY WARRANTY; without even @@ -14,7 +14,7 @@ - BSD See included LICENSE.txt file - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html - ======================================================================-====*/ + ===========================================================================**/ #ifndef CLITKEXTRACTPATIENTFILTER_TXX #define CLITKEXTRACTPATIENTFILTER_TXX @@ -24,6 +24,8 @@ #include "clitkSetBackgroundImageFilter.h" #include "clitkDecomposeAndReconstructImageFilter.h" #include "clitkAutoCropFilter.h" +#include "clitkMemoryUsage.h" +#include "clitkSegmentationUtils.h" // itk #include "itkBinaryThresholdImageFilter.h" @@ -33,13 +35,15 @@ #include "itkBinaryMorphologicalOpeningImageFilter.h" #include "itkBinaryBallStructuringElement.h" #include "itkCastImageFilter.h" +#include "itkConstantPadImageFilter.h" //-------------------------------------------------------------------- -template -clitk::ExtractPatientFilter:: +template +clitk::ExtractPatientFilter:: ExtractPatientFilter(): clitk::FilterBase(), - itk::ImageToImageFilter() + clitk::FilterWithAnatomicalFeatureDatabaseManagement(), + itk::ImageToImageFilter() { this->SetNumberOfRequiredInputs(1); SetBackgroundValue(0); // Must be zero @@ -65,23 +69,23 @@ 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) - FinalOpenCloseOn(); - AutoCropOff(); + FinalOpenCloseOff(); + AutoCropOn(); } //-------------------------------------------------------------------- //-------------------------------------------------------------------- -template -void -clitk::ExtractPatientFilter:: -SetInput(const TInputImageType * image) +template +void +clitk::ExtractPatientFilter:: +SetInput(const TInputImageType * image) { this->SetNthInput(0, const_cast(image)); } @@ -89,62 +93,43 @@ SetInput(const TInputImageType * image) //-------------------------------------------------------------------- -template -template -void -clitk::ExtractPatientFilter:: -SetArgsInfo(ArgsInfoType arg) -{ - SetVerboseOption_GGO(arg); - SetVerboseStep_GGO(arg); - SetWriteStep_GGO(arg); - SetVerboseWarningOff_GGO(arg); - - SetUpperThreshold_GGO(arg); - SetLowerThreshold_GGO(arg); - - SetDecomposeAndReconstructDuringFirstStep_GGO(arg); - SetRadius1_GGO(arg); - SetMaximumNumberOfLabels1_GGO(arg); - SetNumberOfNewLabels1_GGO(arg); - - SetDecomposeAndReconstructDuringSecondStep_GGO(arg); - SetRadius2_GGO(arg); - SetMaximumNumberOfLabels2_GGO(arg); - SetNumberOfNewLabels2_GGO(arg); - - SetFirstKeep_GGO(arg); - SetLastKeep_GGO(arg); - - SetFinalOpenClose_GGO(arg); - SetAutoCrop_GGO(arg); -} -//-------------------------------------------------------------------- +template +void +clitk::ExtractPatientFilter:: +GenerateOutputInformation() { - -//-------------------------------------------------------------------- -template -void -clitk::ExtractPatientFilter:: -GenerateOutputInformation() { + clitk::PrintMemory(GetVerboseMemoryFlag(), "Initial memory"); // OK Superclass::GenerateOutputInformation(); input = dynamic_cast(itk::ProcessObject::GetInput(0)); - // OutputImagePointer outputImage = this->GetOutput(0); + // MaskImagePointer outputImage = this->GetOutput(0); // outputImage->SetRegions(input->GetLargestPossibleRegion()); // 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"); - typedef itk::BinaryThresholdImageFilter BinarizeFilterType; + + // Pad images with air to prevent patient touching the image border + typedef itk::ConstantPadImageFilter PadFilterType; + typename PadFilterType::Pointer padFilter = PadFilterType::New(); + padFilter->SetInput(input); + padFilter->SetConstant(GetUpperThreshold() - 1); + typename InputImageType::SizeType bounds; + for (unsigned i = 0; i < Dim - 1; ++i) + bounds[i] = 1; + bounds[Dim - 1] = 0; + padFilter->SetPadLowerBound(bounds); + padFilter->SetPadUpperBound(bounds); + + typedef itk::BinaryThresholdImageFilter BinarizeFilterType; typename BinarizeFilterType::Pointer binarizeFilter=BinarizeFilterType::New(); - binarizeFilter->SetInput(input); + binarizeFilter->SetInput(padFilter->GetOutput()); if (m_UseLowerThreshold) binarizeFilter->SetLowerThreshold(GetLowerThreshold()); binarizeFilter->SetUpperThreshold(GetUpperThreshold()); binarizeFilter ->SetInsideValue(this->GetForegroundValue()); @@ -156,7 +141,7 @@ GenerateOutputInformation() { connectFilter->SetInput(binarizeFilter->GetOutput()); connectFilter->SetBackgroundValue(this->GetBackgroundValue()); connectFilter->SetFullyConnected(false); - + // Sort labels according to size typedef itk::RelabelComponentImageFilter RelabelFilterType; typename RelabelFilterType::Pointer relabelFilter=RelabelFilterType::New(); @@ -164,13 +149,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; @@ -187,11 +172,11 @@ GenerateOutputInformation() { working_image = f->GetOutput(); StopCurrentStep(working_image); } - + //-------------------------------------------------------------------- //-------------------------------------------------------------------- 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()); @@ -209,11 +194,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); StopCurrentStep(working_image); //-------------------------------------------------------------------- //-------------------------------------------------------------------- - // [Optional] + // [Optional] if (GetDecomposeAndReconstructDuringSecondStep()) { StartNewStep("Second Decompose & Reconstruct step"); typedef clitk::DecomposeAndReconstructImageFilter FilterType; @@ -246,7 +235,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(); @@ -255,15 +244,15 @@ GenerateOutputInformation() { closeFilter->SetForegroundValue(this->GetForegroundValue()); // closeFilter->SetBackgroundValue(SetBackgroundValue()); closeFilter->SetKernel(structuringElement); - closeFilter->Update(); + closeFilter->Update(); working_image = closeFilter->GetOutput(); StopCurrentStep(working_image); } //-------------------------------------------------------------------- //-------------------------------------------------------------------- - // Final Cast - typedef itk::CastImageFilter CastImageFilterType; + // Final Cast + typedef itk::CastImageFilter CastImageFilterType; typename CastImageFilterType::Pointer caster= CastImageFilterType::New(); caster->SetInput(working_image); caster->Update(); @@ -274,27 +263,41 @@ GenerateOutputInformation() { // [Optional] if (GetAutoCrop()) { StartNewStep("AutoCrop"); - typedef clitk::AutoCropFilter CropFilterType; + typedef clitk::AutoCropFilter CropFilterType; typename CropFilterType::Pointer cropFilter = CropFilterType::New(); cropFilter->SetInput(output); cropFilter->SetBackgroundValue(GetBackgroundValue()); - cropFilter->Update(); + cropFilter->Update(); + output = cropFilter->GetOutput(); + StopCurrentStep(output); + } + else + { + // Remove Padding region + typedef itk::CropImageFilter CropFilterType; + typename CropFilterType::Pointer cropFilter = CropFilterType::New(); + cropFilter->SetInput(output); + cropFilter->SetLowerBoundaryCropSize(bounds); + cropFilter->SetUpperBoundaryCropSize(bounds); + cropFilter->Update(); output = cropFilter->GetOutput(); - StopCurrentStep(output); } } //-------------------------------------------------------------------- //-------------------------------------------------------------------- -template -void -clitk::ExtractPatientFilter:: +template +void +clitk::ExtractPatientFilter:: GenerateData() { - //this->SetNthOutput(0, output); // -> no because redo filter otherwise + // Final Graft this->GraftOutput(output); + // Store image filename into AFDB + GetAFDB()->SetImageFilename("Patient", this->GetOutputPatientFilename()); + WriteAFDB(); } //-------------------------------------------------------------------- - + #endif //#define CLITKBOOLEANOPERATORLABELIMAGEFILTER_TXX