X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=segmentation%2FclitkExtractBonesFilter.txx;h=7f59e92f947c25cc41b5d92b101cadcf8d1b0272;hb=df51e4850f784f8f2fbaead7bb82bd6897fb9fab;hp=db29cc727f2d18774e4d36df1f36fe91e660e4b3;hpb=e008d74b0ecdc4ca2eaae8c429901a78f9ef5c31;p=clitk.git diff --git a/segmentation/clitkExtractBonesFilter.txx b/segmentation/clitkExtractBonesFilter.txx index db29cc7..7f59e92 100644 --- a/segmentation/clitkExtractBonesFilter.txx +++ b/segmentation/clitkExtractBonesFilter.txx @@ -22,26 +22,35 @@ // clitk #include "clitkImageCommon.h" #include "clitkSetBackgroundImageFilter.h" -#include "clitkSegmentationFunctions.h" +#include "clitkSegmentationUtils.h" #include "clitkAutoCropFilter.h" +#include "clitkFillMaskFilter.h" // itk #include "itkBinaryThresholdImageFilter.h" #include "itkConnectedComponentImageFilter.h" #include "itkRelabelComponentImageFilter.h" #include "itkNeighborhoodConnectedImageFilter.h" +#include "itkCurvatureAnisotropicDiffusionImageFilter.h" //-------------------------------------------------------------------- -template -clitk::ExtractBonesFilter:: +template +clitk::ExtractBonesFilter:: ExtractBonesFilter(): clitk::FilterBase(), - itk::ImageToImageFilter() + clitk::FilterWithAnatomicalFeatureDatabaseManagement(), + itk::ImageToImageFilter() { // Default global options this->SetNumberOfRequiredInputs(1); SetBackgroundValue(0); // Must be zero SetForegroundValue(1); + SetInitialSmoothing(false); + + SetSmoothingConductanceParameter(3.0); + SetSmoothingNumberOfIterations(5); + SetSmoothingTimeStep(0.0625); + SetSmoothingUseImageSpacing(false); SetMinimalComponentSize(100); SetUpperThreshold1(1500); @@ -54,15 +63,16 @@ ExtractBonesFilter(): s.Fill(1); SetRadius2(s); SetSampleRate2(0); - AutoCropOff(); + AutoCropOn(); + FillHolesOn(); } //-------------------------------------------------------------------- //-------------------------------------------------------------------- -template +template void -clitk::ExtractBonesFilter:: +clitk::ExtractBonesFilter:: SetInput(const TInputImageType * image) { this->SetNthInput(0, const_cast(image)); @@ -71,16 +81,25 @@ SetInput(const TInputImageType * image) //-------------------------------------------------------------------- -template +template template void -clitk::ExtractBonesFilter:: +clitk::ExtractBonesFilter:: SetArgsInfo(ArgsInfoType mArgsInfo) { SetVerboseOption_GGO(mArgsInfo); SetVerboseStep_GGO(mArgsInfo); SetWriteStep_GGO(mArgsInfo); SetVerboseWarningOff_GGO(mArgsInfo); + + SetAFDBFilename_GGO(mArgsInfo); + SetOutputBonesFilename_GGO(mArgsInfo); + + SetInitialSmoothing_GGO(mArgsInfo); + SetSmoothingConductanceParameter_GGO(mArgsInfo); + SetSmoothingNumberOfIterations_GGO(mArgsInfo); + SetSmoothingTimeStep_GGO(mArgsInfo); + SetSmoothingUseImageSpacing_GGO(mArgsInfo); SetMinimalComponentSize_GGO(mArgsInfo); SetUpperThreshold1_GGO(mArgsInfo); @@ -92,42 +111,65 @@ SetArgsInfo(ArgsInfoType mArgsInfo) SetRadius2_GGO(mArgsInfo); SetSampleRate2_GGO(mArgsInfo); SetAutoCrop_GGO(mArgsInfo); + SetFillHoles_GGO(mArgsInfo); } //-------------------------------------------------------------------- //-------------------------------------------------------------------- -template +template void -clitk::ExtractBonesFilter:: +clitk::ExtractBonesFilter:: GenerateOutputInformation() { + // Get input pointers InputImagePointer input = dynamic_cast(itk::ProcessObject::GetInput(0)); - // InputImagePointer input = dynamic_cast(itk::ProcessObject::GetInput(0)); Superclass::GenerateOutputInformation(); - OutputImagePointer outputImage = this->GetOutput(0); + MaskImagePointer outputImage = this->GetOutput(0); outputImage->SetRegions(input->GetLargestPossibleRegion()); + // Read DB + LoadAFDB(); + // typedefs typedef itk::BinaryThresholdImageFilter InputBinarizeFilterType; typedef itk::BinaryThresholdImageFilter BinarizeFilterType; typedef itk::ConnectedComponentImageFilter ConnectFilterType; typedef itk::RelabelComponentImageFilter RelabelFilterType; typedef clitk::SetBackgroundImageFilter SetBackgroundFilterType; - typedef itk::CastImageFilter CastImageFilterType; - typedef itk::ImageFileWriter WriterType; + typedef itk::CastImageFilter CastImageFilterType; + typedef itk::ImageFileWriter WriterType; + + //--------------------------------- + // Smoothing [Optional] + //--------------------------------- + if (GetInitialSmoothing()) { + StartNewStep("Initial Smoothing"); + typedef itk::CurvatureAnisotropicDiffusionImageFilter FilterType; + typename FilterType::Pointer df = FilterType::New(); + df->SetConductanceParameter(GetSmoothingConductanceParameter()); + df->SetNumberOfIterations(GetSmoothingNumberOfIterations()); + df->SetTimeStep(GetSmoothingTimeStep()); + df->SetUseImageSpacing(GetSmoothingUseImageSpacing()); + df->SetInput(input); + df->Update(); + filtered_input = df->GetOutput(); + StopCurrentStep(filtered_input); + } + else { + filtered_input = input; + } //-------------------------------------------------------------------- //-------------------------------------------------------------------- StartNewStep("Initial Labeling"); - typename InternalImageType::Pointer firstLabelImage; //--------------------------------- // Binarize the image //--------------------------------- typename InputBinarizeFilterType::Pointer binarizeFilter=InputBinarizeFilterType::New(); - binarizeFilter->SetInput(input); + binarizeFilter->SetInput(filtered_input); binarizeFilter->SetLowerThreshold(GetLowerThreshold1()); binarizeFilter->SetUpperThreshold(GetUpperThreshold1()); binarizeFilter->SetInsideValue(this->GetForegroundValue()); @@ -160,6 +202,7 @@ GenerateOutputInformation() { binarizeFilter2->Update(); firstLabelImage = binarizeFilter2->GetOutput(); + StopCurrentStep(firstLabelImage); //-------------------------------------------------------------------- //-------------------------------------------------------------------- @@ -179,7 +222,7 @@ GenerateOutputInformation() { neighborhoodConnectedImageFilter->SetUpper(GetUpperThreshold2()); neighborhoodConnectedImageFilter->SetReplaceValue(this->GetForegroundValue()); neighborhoodConnectedImageFilter->SetRadius(GetRadius2()); - neighborhoodConnectedImageFilter->SetInput(input); + neighborhoodConnectedImageFilter->SetInput(filtered_input); // Seeds from label image typedef itk::ImageRegionIteratorWithIndex IteratorType; @@ -209,7 +252,7 @@ GenerateOutputInformation() { //-------------------------------------------------------------------- //-------------------------------------------------------------------- - StartNewStep("Combine de images"); + StartNewStep("Combine the images"); typedef clitk::SetBackgroundImageFilter SetBackgroundImageFilterType; typename SetBackgroundImageFilterType::Pointer setBackgroundFilter=SetBackgroundImageFilterType::New(); @@ -221,6 +264,20 @@ GenerateOutputInformation() { output = setBackgroundFilter->GetOutput(); + //-------------------------------------------------------------------- + //-------------------------------------------------------------------- + // Fill Bones + if (GetFillHoles()) { + StartNewStep("Fill Holes"); + typedef clitk::FillMaskFilter FillMaskFilterType; + typename FillMaskFilterType::Pointer fillMaskFilter = FillMaskFilterType::New(); + fillMaskFilter->SetInput(output); + fillMaskFilter->AddDirection(2); + fillMaskFilter->Update(); + output = fillMaskFilter->GetOutput(); + StopCurrentStep(output); + } + //-------------------------------------------------------------------- //-------------------------------------------------------------------- // [Optional] @@ -241,20 +298,23 @@ GenerateOutputInformation() { //-------------------------------------------------------------------- -template +template void -clitk::ExtractBonesFilter:: +clitk::ExtractBonesFilter:: GenerateData() { //-------------------------------------------------------------------- //-------------------------------------------------------------------- // Final Cast - typedef itk::CastImageFilter CastImageFilterType; + typedef itk::CastImageFilter CastImageFilterType; typename CastImageFilterType::Pointer caster= CastImageFilterType::New(); caster->SetInput(output); caster->Update(); - //this->SetNthOutput(0, caster->GetOutput()); this->GraftOutput(caster->GetOutput()); + + // Store image filenames into AFDB + GetAFDB()->SetImageFilename("bones", this->GetOutputBonesFilename()); + WriteAFDB(); return; } //--------------------------------------------------------------------