X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=segmentation%2FclitkExtractPatientFilter.txx;h=a04232b9d3a72119f973fa784cc9f2011aee6a52;hb=d64e6b39ec8d4bb7b99f9d1a531e9dba3121e2bc;hp=cfc2ab2f8d4544c992374864ab38364b5da187d3;hpb=e008d74b0ecdc4ca2eaae8c429901a78f9ef5c31;p=clitk.git diff --git a/segmentation/clitkExtractPatientFilter.txx b/segmentation/clitkExtractPatientFilter.txx index cfc2ab2..a04232b 100644 --- a/segmentation/clitkExtractPatientFilter.txx +++ b/segmentation/clitkExtractPatientFilter.txx @@ -3,7 +3,7 @@ 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" @@ -35,11 +37,12 @@ #include "itkCastImageFilter.h" //-------------------------------------------------------------------- -template -clitk::ExtractPatientFilter:: +template +clitk::ExtractPatientFilter:: ExtractPatientFilter(): clitk::FilterBase(), - itk::ImageToImageFilter() + clitk::FilterWithAnatomicalFeatureDatabaseManagement(), + itk::ImageToImageFilter() { this->SetNumberOfRequiredInputs(1); SetBackgroundValue(0); // Must be zero @@ -71,16 +74,16 @@ ExtractPatientFilter(): SetLastKeep(1); // Step 4: OpenClose (option) - FinalOpenCloseOn(); - AutoCropOff(); + FinalOpenCloseOff(); + AutoCropOn(); } //-------------------------------------------------------------------- //-------------------------------------------------------------------- -template +template void -clitk::ExtractPatientFilter:: +clitk::ExtractPatientFilter:: SetInput(const TInputImageType * image) { this->SetNthInput(0, const_cast(image)); @@ -89,49 +92,17 @@ SetInput(const TInputImageType * image) //-------------------------------------------------------------------- -template -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:: +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 @@ -194,10 +165,10 @@ GenerateOutputInformation() { typedef itk::BinaryThresholdImageFilter iBinarizeFilterType; typename iBinarizeFilterType::Pointer binarizeFilter2 = iBinarizeFilterType::New(); binarizeFilter2->SetInput(working_image); - binarizeFilter2->SetLowerThreshold(this->GetForegroundValue()); - binarizeFilter2->SetUpperThreshold(this->GetForegroundValue()); - binarizeFilter2 ->SetInsideValue(this->GetBackgroundValue()); - binarizeFilter2 ->SetOutsideValue(this->GetForegroundValue()); + binarizeFilter2->SetLowerThreshold(GetFirstKeep()); + binarizeFilter2->SetUpperThreshold(GetLastKeep()); + binarizeFilter2 ->SetInsideValue(0); + binarizeFilter2 ->SetOutsideValue(1); // binarizeFilter2 ->Update(); // NEEDED ? typename ConnectFilterType::Pointer connectFilter2 = ConnectFilterType::New(); @@ -209,6 +180,10 @@ 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); //-------------------------------------------------------------------- @@ -231,19 +206,6 @@ GenerateOutputInformation() { StopCurrentStep(working_image); } - //-------------------------------------------------------------------- - //-------------------------------------------------------------------- - StartNewStep("Keep patient's labels"); - typename iBinarizeFilterType::Pointer binarizeFilter3 = iBinarizeFilterType::New(); - binarizeFilter3->SetInput(working_image); - binarizeFilter3->SetLowerThreshold(GetFirstKeep()); - binarizeFilter3->SetUpperThreshold(GetLastKeep()); - binarizeFilter3 ->SetInsideValue(this->GetForegroundValue()); - binarizeFilter3 ->SetOutsideValue(this->GetBackgroundValue()); - binarizeFilter3->Update(); - working_image = binarizeFilter3->GetOutput(); - StopCurrentStep(working_image); - //-------------------------------------------------------------------- //-------------------------------------------------------------------- // [Optional] @@ -276,7 +238,7 @@ GenerateOutputInformation() { //-------------------------------------------------------------------- //-------------------------------------------------------------------- // Final Cast - typedef itk::CastImageFilter CastImageFilterType; + typedef itk::CastImageFilter CastImageFilterType; typename CastImageFilterType::Pointer caster= CastImageFilterType::New(); caster->SetInput(working_image); caster->Update(); @@ -287,25 +249,28 @@ 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(); output = cropFilter->GetOutput(); - StopCurrentStep(output); + StopCurrentStep(output); } } //-------------------------------------------------------------------- //-------------------------------------------------------------------- -template +template void -clitk::ExtractPatientFilter:: +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(); } //--------------------------------------------------------------------