From: David Sarrut Date: Fri, 3 Feb 2012 06:57:12 +0000 (+0100) Subject: Moved from repository clitk to clitk.private/tests_dav X-Git-Tag: v1.4.0~307 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=dfc493a2927e89bce1e380dd12b08028e3247fae;p=clitk.git Moved from repository clitk to clitk.private/tests_dav --- diff --git a/segmentation/CMakeLists.txt b/segmentation/CMakeLists.txt index 7e40973..f26ec74 100644 --- a/segmentation/CMakeLists.txt +++ b/segmentation/CMakeLists.txt @@ -1,7 +1,7 @@ #========================================================= # Add Libraries used in vv and clitk to avoid recompilation -FOREACH(clitkTool clitkExtractLung clitkExtractPatient clitkConnectedComponentLabeling) +FOREACH(clitkTool clitkExtractLung clitkExtractPatient clitkConnectedComponentLabeling clitkRegionGrowing) WRAP_GGO(${clitkTool}_GGO_C ${clitkTool}.ggo) SET(GGO_C_FILES ${GGO_C_FILES} ${${clitkTool}_GGO_C}) ENDFOREACH(clitkTool) @@ -46,6 +46,10 @@ IF(CLITK_BUILD_SEGMENTATION) TARGET_LINK_LIBRARIES(clitkMotionMask clitkCommon ${ITK_LIBRARIES}) SET(SEGMENTATION_INSTALL ${SEGMENTATION_INSTALL} clitkMotionMask) + WRAP_GGO(clitkRegionGrowing_GGO_C clitkRegionGrowing.ggo) + ADD_EXECUTABLE(clitkRegionGrowing clitkRegionGrowing.cxx ${clitkRegionGrowing_GGO_C} ${clitkRelativePosition_GGO_C}) + TARGET_LINK_LIBRARIES(clitkRegionGrowing clitkCommon ${ITK_LIBRARIES}) + SET_TARGET_PROPERTIES(${SEGMENTATION_INSTALL} PROPERTIES INSTALL_RPATH "${VTK_DIR}:${ITK_DIR}" ) INSTALL (TARGETS ${SEGMENTATION_INSTALL} DESTINATION bin PERMISSIONS OWNER_READ OWNER_WRITE OWNER_EXECUTE GROUP_EXECUTE WORLD_EXECUTE) diff --git a/segmentation/clitkRegionGrowing.cxx b/segmentation/clitkRegionGrowing.cxx index 83aa816..d24d2f7 100644 --- a/segmentation/clitkRegionGrowing.cxx +++ b/segmentation/clitkRegionGrowing.cxx @@ -16,22 +16,11 @@ - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html ===========================================================================**/ -/* ================================================= - * @file clitkRegionGrowing.cxx - * @author - * @date - * - * @brief - * - ===================================================*/ - - // clitk #include "clitkRegionGrowing_ggo.h" #include "clitkIO.h" #include "clitkRegionGrowingGenericFilter.h" - //-------------------------------------------------------------------- int main(int argc, char * argv[]) { @@ -40,7 +29,8 @@ int main(int argc, char * argv[]) { CLITK_INIT; // Filter - clitk::RegionGrowingGenericFilter::Pointer genericFilter=clitk::RegionGrowingGenericFilter::New(); + typedef clitk::RegionGrowingGenericFilter FilterType; + FilterType::Pointer genericFilter = FilterType::New(); genericFilter->SetArgsInfo(args_info); genericFilter->Update(); diff --git a/segmentation/clitkRegionGrowing.ggo b/segmentation/clitkRegionGrowing.ggo index 60bcae2..cd2d03e 100644 --- a/segmentation/clitkRegionGrowing.ggo +++ b/segmentation/clitkRegionGrowing.ggo @@ -15,8 +15,8 @@ option "output" o "Output image filename" string yes section "Parameters" option "type" t "Region growing filter type: 0=threshold , 1=neighborhood-threshold , 2=confidence , 3= locally-adaptive-threshold, 4= explosion-controlled-threshold" int no default="0" -option "lower" l "1,2,3,4: Lower threshold value" double no default="0" -option "upper" u "1,2,3,4: Upper threshold value" double no default="1" +option "lower" l "1,2,3,4: Lower threshold value" double no default="310" +option "upper" u "1,2,3,4: Upper threshold value" double no default="4000" option "maxUpper" - "4: Maximum upper threshold value" double no default="2000" option "minLower" - "4: Minimum lower threshold value" double no default="-1000" option "step" - "4: Threshold step size" double no default="64.0" diff --git a/segmentation/clitkRegionGrowingGenericFilter.h b/segmentation/clitkRegionGrowingGenericFilter.h index 6f7872a..225619d 100644 --- a/segmentation/clitkRegionGrowingGenericFilter.h +++ b/segmentation/clitkRegionGrowingGenericFilter.h @@ -15,24 +15,13 @@ - BSD See included LICENSE.txt file - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html ===========================================================================**/ -#ifndef clitkRegionGrowingGenericFilter_h -#define clitkRegionGrowingGenericFilter_h - -/* ================================================= - * @file clitkRegionGrowingGenericFilter.h - * @author - * @date - * - * @brief - * - ===================================================*/ +#ifndef CLITKREGIONGROWINGGENERICFILTER_H +#define CLITKREGIONGROWINGGENERICFILTER_H // clitk include #include "clitkIO.h" -#include "clitkCommon.h" -#include "clitkImageCommon.h" -#include "clitkRegionGrowing_ggo.h" +#include "clitkImageToImageGenericFilter.h" #include "clitkLocallyAdaptiveThresholdConnectedImageFilter.h" #include "clitkExplosionControlledThresholdConnectedImageFilter.h" @@ -43,79 +32,45 @@ #include "itkConfidenceConnectedImageFilter.h" #include "itkConfidenceConnectedImageFilter.h" +//-------------------------------------------------------------------- namespace clitk { - - - class ITK_EXPORT RegionGrowingGenericFilter : public itk::LightObject + template + class ITK_EXPORT RegionGrowingGenericFilter: + public ImageToImageGenericFilter > { + public: //---------------------------------------- - // ITK + RegionGrowingGenericFilter(); + //---------------------------------------- - typedef RegionGrowingGenericFilter Self; - typedef itk::LightObject Superclass; + typedef RegionGrowingGenericFilter Self; typedef itk::SmartPointer Pointer; typedef itk::SmartPointer ConstPointer; - // Method for creation through the object factory + //---------------------------------------- itkNewMacro(Self); - - // Run-time type information (and related methods) itkTypeMacro( RegionGrowingGenericFilter, LightObject ); + //-------------------------------------------------------------------- + void SetArgsInfo(const ArgsInfoType & a); - //---------------------------------------- - // Typedefs - //---------------------------------------- - - - //---------------------------------------- - // Set & Get - //---------------------------------------- - void SetArgsInfo(const args_info_clitkRegionGrowing & a) - { - m_ArgsInfo=a; - m_Verbose=m_ArgsInfo.verbose_flag; - m_InputFileName=m_ArgsInfo.input_arg; - } - - - //---------------------------------------- - // Update - //---------------------------------------- - void Update(); + //-------------------------------------------------------------------- + // Main function called each time the filter is updated + template + void UpdateWithInputImageType(); protected: + void Modified() {} // Need for using itkMacros + template void InitializeImageType(); + ArgsInfoType mArgsInfo; - //---------------------------------------- - // Constructor & Destructor - //---------------------------------------- - RegionGrowingGenericFilter(); - ~RegionGrowingGenericFilter() {}; - - - //---------------------------------------- - // Templated members - //---------------------------------------- - template void UpdateWithDim(std::string PixelType); - template void UpdateWithDimAndPixelType(); - - - //---------------------------------------- - // Data members - //---------------------------------------- - args_info_clitkRegionGrowing m_ArgsInfo; - bool m_Verbose; - std::string m_InputFileName; - - }; - - + }; // end class } // end namespace clitk #ifndef ITK_MANUAL_INSTANTIATION #include "clitkRegionGrowingGenericFilter.txx" #endif -#endif // #define clitkRegionGrowingGenericFilter_h +#endif // #define CLITKREGIONGROWINGGENERICFILTER_H diff --git a/segmentation/clitkRegionGrowingGenericFilter.txx b/segmentation/clitkRegionGrowingGenericFilter.txx index eead0d5..e8f3653 100644 --- a/segmentation/clitkRegionGrowingGenericFilter.txx +++ b/segmentation/clitkRegionGrowingGenericFilter.txx @@ -14,91 +14,93 @@ - BSD See included LICENSE.txt file - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html -===========================================================================**/ -#ifndef clitkRegionGrowingGenericFilter_txx -#define clitkRegionGrowingGenericFilter_txx -#include -#include + ===========================================================================**/ -namespace clitk -{ +#ifndef CLITKREGIONGROWINGGENERICFILTER_TXX +#define CLITKREGIONGROWINGGENERICFILTER_TXX - //------------------------------------------------------------------- - // Update with the number of dimensions - //------------------------------------------------------------------- - template - void - RegionGrowingGenericFilter::UpdateWithDim(std::string PixelType) - { - if (m_Verbose) std::cout << "Image was detected to be "<(); - } - // 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(); - } - - // 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(); - } - } +#include +#include - //------------------------------------------------------------------- - // Update with the number of dimensions and the pixeltype - //------------------------------------------------------------------- - template - void - RegionGrowingGenericFilter::UpdateWithDimAndPixelType() - { +//-------------------------------------------------------------------- +template +clitk::RegionGrowingGenericFilter::RegionGrowingGenericFilter(): + ImageToImageGenericFilter("RegionGrowing") +{ + InitializeImageType<2>(); + InitializeImageType<3>(); + //InitializeImageType<4>(); +} +//-------------------------------------------------------------------- + + +//-------------------------------------------------------------------- +template +template +void clitk::RegionGrowingGenericFilter::InitializeImageType() +{ + ADD_IMAGE_TYPE(Dim, uchar); + ADD_IMAGE_TYPE(Dim, short); + // ADD_IMAGE_TYPE(Dim, int); + ADD_IMAGE_TYPE(Dim, float); +} +//-------------------------------------------------------------------- + - // ImageTypes - typedef itk::Image InputImageType; - typedef itk::Image OutputImageType; +//-------------------------------------------------------------------- +template +void clitk::RegionGrowingGenericFilter::SetArgsInfo(const ArgsInfoType & a) +{ + mArgsInfo=a; + this->SetIOVerbose(mArgsInfo.verbose_flag); + if (mArgsInfo.input_given) this->AddInputFilename(mArgsInfo.input_arg); + if (mArgsInfo.output_given) this->SetOutputFilename(mArgsInfo.output_arg); +} +//-------------------------------------------------------------------- + + +//-------------------------------------------------------------------- +// Update with the number of dimensions and the pixeltype +//-------------------------------------------------------------------- +template +template +void clitk::RegionGrowingGenericFilter::UpdateWithInputImageType() +{ + DD("UpdateWithInputImageType"); + const int Dimension = ImageType::ImageDimension; + + // ImageTypes + typedef ImageType InputImageType; + typedef ImageType OutputImageType; + typedef typename ImageType::PixelType PixelType; - // Read the input - typedef itk::ImageFileReader InputReaderType; - typename InputReaderType::Pointer reader = InputReaderType::New(); - reader->SetFileName( m_InputFileName); - reader->Update(); - typename InputImageType::Pointer input= reader->GetOutput(); - - // Seed - typedef typename std::vector SeedsType; - SeedsType seeds(1); - if(m_ArgsInfo.seed_given==Dimension) - for (unsigned int i=0; itemplate GetInput(0); + + // Seed + typedef typename std::vector SeedsType; + SeedsType seeds(1); + if (mArgsInfo.seed_given==Dimension) + for (unsigned int i=0; i BallType; typename BallType::RadiusType r; - if (m_ArgsInfo.seedRadius_given == Dimension) + if (mArgsInfo.seedRadius_given == Dimension) for (unsigned i = 0; i < Dimension; i++) - r[i] = m_ArgsInfo.seedRadius_arg[i]; + r[i] = mArgsInfo.seedRadius_arg[i]; else - r.Fill(m_ArgsInfo.seedRadius_arg[0]); + r.Fill(mArgsInfo.seedRadius_arg[0]); BallType ball; ball.SetRadius(r); @@ -106,22 +108,22 @@ namespace clitk typedef itk::ConstShapedNeighborhoodIterator IteratorType; IteratorType it(ball.GetRadius(), - input, - input->GetLargestPossibleRegion()); + input, + input->GetLargestPossibleRegion()); #if ITK_VERSION_MAJOR < 4 typename BallType::ConstIterator nit; unsigned idx = 0; for (nit = ball.Begin(); nit != ball.End(); ++nit, ++idx) - { - if (*nit) { - it.ActivateOffset(it.GetOffset(idx)); + if (*nit) + { + it.ActivateOffset(it.GetOffset(idx)); + } + else + { + it.DeactivateOffset(it.GetOffset(idx)); + } } - else - { - it.DeactivateOffset(it.GetOffset(idx)); - } - } #else it.CreateActiveListFromNeighborhood(ball); it.NeedToUseBoundaryConditionOff(); @@ -129,174 +131,170 @@ namespace clitk it.SetLocation(seeds[0]); for (typename IteratorType::ConstIterator i = it.Begin(); !i.IsAtEnd(); ++i) - { - typename InputImageType::IndexType id = seeds[0] + i.GetNeighborhoodOffset(); - if (id != seeds[0] && input->GetLargestPossibleRegion().IsInside(id)) - seeds.push_back(id); - } + { + typename InputImageType::IndexType id = seeds[0] + i.GetNeighborhoodOffset(); + if (id != seeds[0] && input->GetLargestPossibleRegion().IsInside(id)) + seeds.push_back(id); + } } - // Filter - typedef itk::ImageToImageFilter ImageToImageFilterType; - typename ImageToImageFilterType::Pointer filter; + // Filter + typedef itk::ImageToImageFilter ImageToImageFilterType; + typename ImageToImageFilterType::Pointer filter; - switch (m_ArgsInfo.type_arg) - { - case 0: { + switch (mArgsInfo.type_arg) + { + case 0: { - typedef itk::ConnectedThresholdImageFilter ImageFilterType; - typename ImageFilterType::Pointer f= ImageFilterType::New(); + typedef itk::ConnectedThresholdImageFilter ImageFilterType; + typename ImageFilterType::Pointer f= ImageFilterType::New(); - f->SetLower(m_ArgsInfo.lower_arg); - f->SetUpper(m_ArgsInfo.upper_arg); - f->SetReplaceValue(static_cast(m_ArgsInfo.pad_arg)); - for (typename SeedsType::const_iterator it = seeds.begin(); it != seeds.end(); ++it) - f->AddSeed(*it); - filter=f; - if(m_Verbose)std::cout<<"Using the connected threshold image filter..."<SetLower(mArgsInfo.lower_arg); + f->SetUpper(mArgsInfo.upper_arg); + f->SetReplaceValue(static_cast(mArgsInfo.pad_arg)); + for (typename SeedsType::const_iterator it = seeds.begin(); it != seeds.end(); ++it) + f->AddSeed(*it); + filter=f; + if (mArgsInfo.verbose_flag) std::cout<<"Using the connected threshold image filter..."< ImageFilterType; - typename ImageFilterType::Pointer f= ImageFilterType::New(); + typedef itk::NeighborhoodConnectedImageFilter ImageFilterType; + typename ImageFilterType::Pointer f= ImageFilterType::New(); - // Radius - typename InputImageType::SizeType size; - if(m_ArgsInfo.radius_given==Dimension) - for (unsigned int i=0; iSetLower(m_ArgsInfo.lower_arg); - f->SetUpper(m_ArgsInfo.upper_arg); - f->SetReplaceValue(static_cast(m_ArgsInfo.pad_arg)); - for (typename SeedsType::const_iterator it = seeds.begin(); it != seeds.end(); ++it) - f->AddSeed(*it); - f->SetRadius(size); - filter=f; - if(m_Verbose)std::cout<<"Using the neighborhood threshold connected image filter..."<SetLower(mArgsInfo.lower_arg); + f->SetUpper(mArgsInfo.upper_arg); + f->SetReplaceValue(static_cast(mArgsInfo.pad_arg)); + for (typename SeedsType::const_iterator it = seeds.begin(); it != seeds.end(); ++it) + f->AddSeed(*it); + f->SetRadius(size); + filter=f; + if (mArgsInfo.verbose_flag) std::cout<<"Using the neighborhood threshold connected image filter..."< ImageFilterType; - typename ImageFilterType::Pointer f= ImageFilterType::New(); + typedef itk::ConfidenceConnectedImageFilter ImageFilterType; + typename ImageFilterType::Pointer f= ImageFilterType::New(); - // Radius - typename InputImageType::SizeType size; - if(m_ArgsInfo.radius_given==Dimension) - for (unsigned int i=0; iSetMultiplier( m_ArgsInfo.multiplier_arg ); - f->SetNumberOfIterations( m_ArgsInfo.multiplier_arg ); - for (typename SeedsType::const_iterator it = seeds.begin(); it != seeds.end(); ++it) - f->AddSeed(*it); - f->SetNumberOfIterations( m_ArgsInfo.iter_arg); - f->SetReplaceValue(static_cast(m_ArgsInfo.pad_arg)); - f->SetInitialNeighborhoodRadius(size[0]); - filter=f; - if(m_Verbose)std::cout<<"Using the confidence threshold connected image filter..."<SetMultiplier( mArgsInfo.multiplier_arg ); + f->SetNumberOfIterations( mArgsInfo.multiplier_arg ); + for (typename SeedsType::const_iterator it = seeds.begin(); it != seeds.end(); ++it) + f->AddSeed(*it); + f->SetNumberOfIterations( mArgsInfo.iter_arg); + f->SetReplaceValue(static_cast(mArgsInfo.pad_arg)); + f->SetInitialNeighborhoodRadius(size[0]); + filter=f; + if (mArgsInfo.verbose_flag) std::cout<<"Using the confidence threshold connected image filter..."< ImageFilterType; - typename ImageFilterType::Pointer f= ImageFilterType::New(); + typedef clitk::LocallyAdaptiveThresholdConnectedImageFilter ImageFilterType; + typename ImageFilterType::Pointer f= ImageFilterType::New(); - // Radius - typename InputImageType::SizeType size; - if(m_ArgsInfo.radius_given==Dimension) - for (unsigned int i=0; iSetLower(m_ArgsInfo.lower_arg); - f->SetUpper(m_ArgsInfo.upper_arg); - f->SetLowerBorderIsGiven(m_ArgsInfo.adaptLower_flag); - f->SetLowerBorderIsGiven(m_ArgsInfo.adaptUpper_flag); - f->SetReplaceValue(static_cast(m_ArgsInfo.pad_arg)); - f->SetMultiplier(m_ArgsInfo.multiplier_arg); - f->SetMaximumSDIsGiven(m_ArgsInfo.maxSD_given); - if (m_ArgsInfo.maxSD_given) f->SetMaximumSD(m_ArgsInfo.maxSD_arg); - for (typename SeedsType::const_iterator it = seeds.begin(); it != seeds.end(); ++it) - f->AddSeed(*it); - f->SetRadius(size); - filter=f; - if(m_Verbose)std::cout<<"Using the locally adaptive threshold connected image filter..."<SetLower(mArgsInfo.lower_arg); + f->SetUpper(mArgsInfo.upper_arg); + f->SetLowerBorderIsGiven(mArgsInfo.adaptLower_flag); + f->SetLowerBorderIsGiven(mArgsInfo.adaptUpper_flag); + f->SetReplaceValue(static_cast(mArgsInfo.pad_arg)); + f->SetMultiplier(mArgsInfo.multiplier_arg); + f->SetMaximumSDIsGiven(mArgsInfo.maxSD_given); + if (mArgsInfo.maxSD_given) f->SetMaximumSD(mArgsInfo.maxSD_arg); + for (typename SeedsType::const_iterator it = seeds.begin(); it != seeds.end(); ++it) + f->AddSeed(*it); + f->SetRadius(size); + filter=f; + if (mArgsInfo.verbose_flag) std::cout<<"Using the locally adaptive threshold connected image filter..."< ImageFilterType; - typename ImageFilterType::Pointer f= ImageFilterType::New(); + typedef clitk::ExplosionControlledThresholdConnectedImageFilter ImageFilterType; + typename ImageFilterType::Pointer f= ImageFilterType::New(); - // // Radius - // typename InputImageType::SizeType size; - // if(m_ArgsInfo.radius_given==Dimension) - // for (unsigned int i=0; iSetVerbose(m_ArgsInfo.verbose_flag); - f->SetLower(m_ArgsInfo.lower_arg); - f->SetUpper(m_ArgsInfo.upper_arg); - f->SetMinimumLowerThreshold(m_ArgsInfo.minLower_arg); - f->SetMaximumUpperThreshold(m_ArgsInfo.maxUpper_arg); - f->SetAdaptLowerBorder(m_ArgsInfo.adaptLower_flag); - f->SetAdaptUpperBorder(m_ArgsInfo.adaptUpper_flag); - f->SetReplaceValue(static_cast(m_ArgsInfo.pad_arg)); - f->SetMultiplier(m_ArgsInfo.multiplier_arg); - f->SetThresholdStepSize(m_ArgsInfo.step_arg); - f->SetMinimumThresholdStepSize(m_ArgsInfo.minStep_arg); - f->SetFullyConnected(m_ArgsInfo.full_flag); - for (typename SeedsType::const_iterator it = seeds.begin(); it != seeds.end(); ++it) - f->AddSeed(*it); - filter=f; - if(m_Verbose)std::cout<<"Using the explosion controlled threshold connected image filter..."<SetVerbose(mArgsInfo.verbose_flag); + f->SetLower(mArgsInfo.lower_arg); + f->SetUpper(mArgsInfo.upper_arg); + f->SetMinimumLowerThreshold(mArgsInfo.minLower_arg); + f->SetMaximumUpperThreshold(mArgsInfo.maxUpper_arg); + f->SetAdaptLowerBorder(mArgsInfo.adaptLower_flag); + f->SetAdaptUpperBorder(mArgsInfo.adaptUpper_flag); + f->SetReplaceValue(static_cast(mArgsInfo.pad_arg)); + f->SetMultiplier(mArgsInfo.multiplier_arg); + f->SetThresholdStepSize(mArgsInfo.step_arg); + f->SetMinimumThresholdStepSize(mArgsInfo.minStep_arg); + f->SetFullyConnected(mArgsInfo.full_flag); + for (typename SeedsType::const_iterator it = seeds.begin(); it != seeds.end(); ++it) + f->AddSeed(*it); + filter=f; + if (mArgsInfo.verbose_flag) std::cout<<"Using the explosion controlled threshold connected image filter..."<SetInput(input); - filter->Update(); - typename OutputImageType::Pointer output=filter->GetOutput(); + filter->SetInput(input); + filter->Update(); + typename OutputImageType::Pointer output=filter->GetOutput(); - // Output - typedef itk::ImageFileWriter WriterType; - typename WriterType::Pointer writer = WriterType::New(); - writer->SetFileName(m_ArgsInfo.output_arg); - writer->SetInput(output); - writer->Update(); - } + // Write/Save results + this->template SetNextOutput(output); +} +//-------------------------------------------------------------------- -}//end clitk -#endif //#define clitkRegionGrowingGenericFilter_txx +#endif //#define CLITKREGIONGROWINGGENERICFILTER_TXX