X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=segmentation%2FclitkExtractBonesFilter.txx;h=7f59e92f947c25cc41b5d92b101cadcf8d1b0272;hb=df51e4850f784f8f2fbaead7bb82bd6897fb9fab;hp=ef3f9445ad171b4970d2aa8faf4cae1d87231daf;hpb=6e16222234a90c6079a8f4696c92de7349a496bb;p=clitk.git diff --git a/segmentation/clitkExtractBonesFilter.txx b/segmentation/clitkExtractBonesFilter.txx index ef3f944..7f59e92 100644 --- a/segmentation/clitkExtractBonesFilter.txx +++ b/segmentation/clitkExtractBonesFilter.txx @@ -24,6 +24,7 @@ #include "clitkSetBackgroundImageFilter.h" #include "clitkSegmentationUtils.h" #include "clitkAutoCropFilter.h" +#include "clitkFillMaskFilter.h" // itk #include "itkBinaryThresholdImageFilter.h" @@ -33,11 +34,12 @@ #include "itkCurvatureAnisotropicDiffusionImageFilter.h" //-------------------------------------------------------------------- -template -clitk::ExtractBonesFilter:: +template +clitk::ExtractBonesFilter:: ExtractBonesFilter(): clitk::FilterBase(), - itk::ImageToImageFilter() + clitk::FilterWithAnatomicalFeatureDatabaseManagement(), + itk::ImageToImageFilter() { // Default global options this->SetNumberOfRequiredInputs(1); @@ -61,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)); @@ -78,10 +81,10 @@ SetInput(const TInputImageType * image) //-------------------------------------------------------------------- -template +template template void -clitk::ExtractBonesFilter:: +clitk::ExtractBonesFilter:: SetArgsInfo(ArgsInfoType mArgsInfo) { SetVerboseOption_GGO(mArgsInfo); @@ -89,6 +92,9 @@ SetArgsInfo(ArgsInfoType mArgsInfo) SetWriteStep_GGO(mArgsInfo); SetVerboseWarningOff_GGO(mArgsInfo); + SetAFDBFilename_GGO(mArgsInfo); + SetOutputBonesFilename_GGO(mArgsInfo); + SetInitialSmoothing_GGO(mArgsInfo); SetSmoothingConductanceParameter_GGO(mArgsInfo); SetSmoothingNumberOfIterations_GGO(mArgsInfo); @@ -105,30 +111,34 @@ 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] @@ -254,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] @@ -274,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; } //--------------------------------------------------------------------