X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=blobdiff_plain;f=segmentation%2FclitkMorphoMathGenericFilter.txx;h=9edef723f0637bb5fb159291adc995d37160e775;hb=56ae68bbe5b50ad1ea8b6846f43f322d4aa36b70;hp=cb641de85cb2b141e82660ecc0e54fd4febad993;hpb=2f5b335da5621bdfc86cb594cc667d0929f4d8e3;p=clitk.git diff --git a/segmentation/clitkMorphoMathGenericFilter.txx b/segmentation/clitkMorphoMathGenericFilter.txx old mode 100755 new mode 100644 index cb641de..9edef72 --- a/segmentation/clitkMorphoMathGenericFilter.txx +++ b/segmentation/clitkMorphoMathGenericFilter.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,219 +14,112 @@ - BSD See included LICENSE.txt file - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html -======================================================================-====*/ -#ifndef clitkMorphoMathGenericFilter_txx -#define clitkMorphoMathGenericFilter_txx -/** - ================================================= - * @file clitkMorphoMathGenericFilter.txx - * @author Jef Vandemeulebroucke - * @date 5 May 2009 - * - * @brief - * - =================================================*/ - - -namespace clitk + ===========================================================================**/ + +#include "clitkSegmentationUtils.h" + +//-------------------------------------------------------------------- +template +clitk::MorphoMathGenericFilter:: +MorphoMathGenericFilter(): + ImageToImageGenericFilter >("MorphMath") { + // Default values + cmdline_parser_clitkMorphoMath_init(&mArgsInfo); + InitializeImageType<2>(); + InitializeImageType<3>(); + InitializeImageType<4>(); +} +//-------------------------------------------------------------------- + + +//-------------------------------------------------------------------- +template +template +void clitk::MorphoMathGenericFilter:: +InitializeImageType() +{ + ADD_DEFAULT_IMAGE_TYPES(Dim); + //ADD_IMAGE_TYPE(Dim, short); // +} +//-------------------------------------------------------------------- + +//-------------------------------------------------------------------- +template +void clitk::MorphoMathGenericFilter:: +SetArgsInfo(const ArgsInfoType & a) +{ + mArgsInfo=a; + this->SetIOVerbose(mArgsInfo.verbose_flag); + if (mArgsInfo.imagetypes_flag) this->PrintAvailableImageTypes(); + if (mArgsInfo.input_given) this->AddInputFilename(mArgsInfo.input_arg); + if (mArgsInfo.output_given) this->AddOutputFilename(mArgsInfo.output_arg); +} +//-------------------------------------------------------------------- + + +//-------------------------------------------------------------------- +template +template +void clitk::MorphoMathGenericFilter:: +SetOptionsFromArgsInfoToFilter(FilterType * f) +{ + f->SetVerboseFlag(mArgsInfo.verbose_flag); + f->SetExtendSupportFlag(mArgsInfo.extend_flag); + f->SetOperationType(mArgsInfo.type_arg); + f->SetBackgroundValue(mArgsInfo.bg_arg); + f->SetForegroundValue(mArgsInfo.fg_arg); + f->SetBoundaryToForegroundFlag(mArgsInfo.bound_flag); + if (mArgsInfo.radius_given && mArgsInfo.radiusInMM_given) { + clitkExceptionMacro("Please give --radius OR --radiusInMM, not both."); + } - //============================================================================== - // Update with the number of dimensions - //============================================================================== - template - void - MorphoMathGenericFilter::UpdateWithDim(std::string PixelType) - { - if(PixelType == "short"){ - if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and signed short..." << std::endl; - UpdateWithDimAndPixelType(); - } - // else if(PixelType == "unsigned_short"){ - // if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and unsigned_short..." << std::endl; - // UpdateWithDimAndPixelType(); - // } - - else if (PixelType == "unsigned_char"){ - if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and unsigned_char..." << std::endl; - UpdateWithDimAndPixelType(); + if (mArgsInfo.radiusInMM_given) { + typename FilterType::PointType p; + if (mArgsInfo.radiusInMM_given) { + ConvertOptionMacro(mArgsInfo.radiusInMM, p, FilterType::ImageDimension, false); + f->SetRadiusInMM(p); } - - // else if (PixelType == "char"){ - // if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and signed_char..." << std::endl; - // UpdateWithDimAndPixelType(); - // } - else { - if (m_Verbose) std::cout << "Launching filter in "<< Dimension <<"D and float..." << std::endl; - UpdateWithDimAndPixelType(); + } + else { + typename FilterType::SizeType r; + if (mArgsInfo.radius_given) { + ConvertOptionMacro(mArgsInfo.radius, r, FilterType::ImageDimension, false); + f->SetRadius(r); } } - - - //============================================================================== - // Update with the pixel type - //============================================================================== - template - void - MorphoMathGenericFilter::UpdateWithDimAndPixelType() - { - - //--------------------------------- - // Define the images - //--------------------------------- - typedef float InternalPixelType; - typedef itk::Image InputImageType; - typedef itk::Image InternalImageType; - typedef itk::Image OutputImageType; - typedef itk::ImageFileReader FileReaderType; - typename FileReaderType::Pointer fileReader=FileReaderType::New(); - fileReader->SetFileName(m_InputFileName); - typedef itk::CastImageFilter InputCastImageFilterType; - typename InputCastImageFilterType::Pointer caster = InputCastImageFilterType::New(); - caster->SetInput(fileReader->GetOutput()); - caster->Update(); - typename InternalImageType::Pointer input =caster->GetOutput(); - - - //--------------------------------- - // Find the type of action - //--------------------------------- - typedef itk::ImageToImageFilter ImageFilterType; - typename ImageFilterType::Pointer filter; - - typedef itk::BinaryBallStructuringElement KernelType; - KernelType structuringElement; - typename InternalImageType::SizeType radius; - if (m_ArgsInfo.radius_given==Dimension) - for (unsigned int i=0;i FilterType; - typename FilterType::Pointer m = FilterType::New(); - m->SetBackgroundValue(m_ArgsInfo.bg_arg); - m->SetForegroundValue(m_ArgsInfo.fg_arg); - m->SetBoundaryToForeground(m_ArgsInfo.bound_flag); - m->SetKernel(structuringElement); - - filter=m; - if(m_Verbose) std::cout<<"Using the erode filter..."< FilterType; - typename FilterType::Pointer m = FilterType::New(); - m->SetBackgroundValue(m_ArgsInfo.bg_arg); - m->SetForegroundValue(m_ArgsInfo.fg_arg); - m->SetBoundaryToForeground(m_ArgsInfo.bound_flag); - m->SetKernel(structuringElement); - - filter=m; - if(m_Verbose) std::cout<<"Using the dilate filter..."< FilterType; - typename FilterType::Pointer m = FilterType::New(); - m->SetForegroundValue(m_ArgsInfo.fg_arg); - m->SetSafeBorder(m_ArgsInfo.bound_flag); - m->SetKernel(structuringElement); - - filter=m; - if(m_Verbose) std::cout<<"Using the closing filter..."< FilterType; - typename FilterType::Pointer m = FilterType::New(); - m->SetBackgroundValue(m_ArgsInfo.bg_arg); - m->SetForegroundValue(m_ArgsInfo.fg_arg); - m->SetKernel(structuringElement); - - filter=m; - if(m_Verbose) std::cout<<"Using the opening filter..."< FilterType; - typename FilterType::Pointer m = FilterType::New(); - m->SetBackgroundValue(m_ArgsInfo.bg_arg); - m->SetForegroundValue(m_ArgsInfo.fg_arg); - m->SetBoundaryToForeground(m_ArgsInfo.bound_flag); - m->SetKernel(structuringElement); - - filter=m; - if(m_Verbose) std::cout<<"Using the conditional erode filter..."< FilterType; - typename FilterType::Pointer m = FilterType::New(); - m->SetBackgroundValue(m_ArgsInfo.bg_arg); - m->SetForegroundValue(m_ArgsInfo.fg_arg); - m->SetBoundaryToForeground(m_ArgsInfo.bound_flag); - m->SetKernel(structuringElement); - - filter=m; - if(m_Verbose) std::cout<<"Using the conditional dilate filter..."<SetInput(input); +} + +//-------------------------------------------------------------------- +// Update with the number of dimensions and the pixeltype +//-------------------------------------------------------------------- +template +template +void clitk::MorphoMathGenericFilter:: +UpdateWithInputImageType() +{ + // Reading input + typename ImageType::Pointer input = this->template GetInput(0); + + // Create filter + typedef clitk::MorphoMathFilter FilterType; + typename FilterType::Pointer filter = FilterType::New(); - try - { - filter->Update(); - } - catch( itk::ExceptionObject & err ) - { - std::cerr << "ExceptionObject caught executing the filter!" << std::endl; - std::cerr << err << std::endl; - return; - } + // Set the filter (needed for example for threaded monitoring) + this->SetFilterBase(filter); + // Set global Options + filter->SetInput(input); + SetOptionsFromArgsInfoToFilter(filter); + + // Go ! + filter->Update(); + + // Write/Save results + typename ImageType::Pointer output = filter->GetOutput(); + this->template SetNextOutput(output); +} +//-------------------------------------------------------------------- - //--------------------------------- - // Write the output - //--------------------------------- - typedef itk::CastImageFilter< InternalImageType, OutputImageType > OutputCastImageFilterType; - typename OutputCastImageFilterType::Pointer oCaster = OutputCastImageFilterType::New(); - oCaster->SetInput(filter->GetOutput()); - typedef itk::ImageFileWriter FileWriterType; - typename FileWriterType::Pointer writer=FileWriterType::New(); - writer->SetInput(oCaster->GetOutput()); - writer->SetFileName(m_ArgsInfo.output_arg); - writer->Update(); - - } -}//end namespace - -#endif //#define clitkMorphoMathGenericFilter_txx