From 0d181563607d9b97bc296cfab1ab5f2bb69c3db9 Mon Sep 17 00:00:00 2001 From: dsarrut Date: Wed, 30 Jun 2010 05:59:41 +0000 Subject: [PATCH] reconstruct with dilatation (jef) --- ...itkReconstructThroughDilationImageFilter.h | 124 +++++++++++++ ...kReconstructThroughDilationImageFilter.txx | 166 ++++++++++++++++++ 2 files changed, 290 insertions(+) create mode 100644 itk/clitkReconstructThroughDilationImageFilter.h create mode 100644 itk/clitkReconstructThroughDilationImageFilter.txx diff --git a/itk/clitkReconstructThroughDilationImageFilter.h b/itk/clitkReconstructThroughDilationImageFilter.h new file mode 100644 index 0000000..23cc98b --- /dev/null +++ b/itk/clitkReconstructThroughDilationImageFilter.h @@ -0,0 +1,124 @@ +#ifndef clitkReconstructThroughDilationImageFilter_h +#define clitkReconstructThroughDilationImageFilter_h + +/* ================================================= + * @file clitkReconstructThroughDilationImageFilter.h + * @author + * @date + * + * @brief + * + ===================================================*/ + + +// clitk include +#include "clitkIO.h" +#include "clitkCommon.h" +#include "clitkConditionalBinaryDilateImageFilter.h" + +//itk include +#include "itkImageToImageFilter.h" +#include "itkBinaryBallStructuringElement.h" +#include "itkConnectedComponentImageFilter.h" +#include "itkStatisticsImageFilter.h" +#include "itkCastImageFilter.h" +#include "itkDifferenceImageFilter.h" +#include "itkThresholdImageFilter.h" + +namespace clitk +{ + + template + class ITK_EXPORT ReconstructThroughDilationImageFilter : + public itk::ImageToImageFilter + { + public: + //---------------------------------------- + // ITK + //---------------------------------------- + typedef ReconstructThroughDilationImageFilter Self; + typedef itk::ImageToImageFilter Superclass; + 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( ReconstructThroughDilationImageFilter, ImageToImageFilter ); + + /** Dimension of the domain space. */ + itkStaticConstMacro(InputImageDimension, unsigned int, Superclass::InputImageDimension); + itkStaticConstMacro(OutputImageDimension, unsigned int, Superclass::OutputImageDimension); + + //---------------------------------------- + // Typedefs + //---------------------------------------- + typedef typename OutputImageType::RegionType OutputImageRegionType; + typedef int InternalPixelType; + typedef typename InputImageType::PixelType InputPixelType; + typedef typename OutputImageType::PixelType OutputPixelType; + typedef typename InputImageType::SizeType SizeType; + + //---------------------------------------- + // Set & Get + //---------------------------------------- + itkBooleanMacro(Verbose); + itkSetMacro( Verbose, bool); + itkGetConstReferenceMacro( Verbose, bool); + void SetRadius ( const SizeType& s){ m_Radius=s; this->Modified();} + SizeType GetRadius(void){return m_Radius;} + itkSetMacro( ErosionPaddingValue, OutputPixelType); + itkGetConstMacro( ErosionPaddingValue, OutputPixelType) + itkSetMacro( MaximumNumberOfLabels, unsigned int); + itkGetConstMacro( MaximumNumberOfLabels, unsigned int); + itkSetMacro( BackgroundValue, InternalPixelType); + itkGetConstMacro( BackgroundValue, InternalPixelType); + itkSetMacro( ForegroundValue, InternalPixelType); + itkGetConstMacro( ForegroundValue, InternalPixelType); + + protected: + + //---------------------------------------- + // Constructor & Destructor + //---------------------------------------- + ReconstructThroughDilationImageFilter(); + ~ReconstructThroughDilationImageFilter() {}; + + //---------------------------------------- + // Update + //---------------------------------------- + // Generate Data + void GenerateData(void); + + // // Threaded Generate Data + // void BeforeThreadedGenerateData(void ); + // void ThreadedGenerateData(const OutputImageRegionType & outputRegionForThread, int threadId ); + // void AfterThreadedGenerateData(void ); + // // Override defaults + // virtual void GenerateInputRequestedRegion(); + // virtual void GenerateOutputInformation (void); + // virtual void EnlargeOutputRequestedRegion(DataObject *data); + // void AllocateOutputs(); + //---------------------------------------- + // Data members + //---------------------------------------- + bool m_Verbose; + InternalPixelType m_BackgroundValue; + InternalPixelType m_ForegroundValue; + unsigned int m_MaximumNumberOfLabels; + OutputPixelType m_ErosionPaddingValue; + SizeType m_Radius; + + }; + + +} // end namespace clitk + +#ifndef ITK_MANUAL_INSTANTIATION +#include "clitkReconstructThroughDilationImageFilter.txx" +#endif + +#endif // #define clitkReconstructThroughDilationImageFilter_h + + diff --git a/itk/clitkReconstructThroughDilationImageFilter.txx b/itk/clitkReconstructThroughDilationImageFilter.txx new file mode 100644 index 0000000..d2d3d31 --- /dev/null +++ b/itk/clitkReconstructThroughDilationImageFilter.txx @@ -0,0 +1,166 @@ +#ifndef clitkReconstructThroughDilationImageFilter_txx +#define clitkReconstructThroughDilationImageFilter_txx + +/* ================================================= + * @file clitkReconstructThroughDilationImageFilter.txx + * @author + * @date + * + * @brief + * + ===================================================*/ + + +namespace clitk +{ + + //------------------------------------------------------------------- + // Update with the number of dimensions + //------------------------------------------------------------------- + template + ReconstructThroughDilationImageFilter::ReconstructThroughDilationImageFilter() + { + m_Verbose=false; + m_BackgroundValue=0; + m_ForegroundValue=1; + m_ErosionPaddingValue=static_cast(-1); + for (unsigned int i=0; i + void + ReconstructThroughDilationImageFilter::GenerateData() + { + + //--------------------------------- + // Typedefs + //--------------------------------- + + // Internal type + typedef itk::Image InternalImageType; + + // Filters used + typedef itk::CastImageFilter InputCastImageFilterType; + typedef itk::ThresholdImageFilter InputThresholdImageFilterType; + typedef itk::StatisticsImageFilter StatisticsImageFilterType; + typedef itk::BinaryBallStructuringElement KernelType; + typedef clitk::ConditionalBinaryDilateImageFilter ConditionalBinaryDilateImageFilterType; + typedef itk::DifferenceImageFilter DifferenceImageFilterType; + typedef itk::CastImageFilter OutputCastImageFilterType; + typedef clitk::SetBackgroundImageFilter SetBackgroundImageFilterType; + + //--------------------------------- + // Cast + //--------------------------------- + typename InputCastImageFilterType::Pointer castImageFilter=InputCastImageFilterType::New(); + castImageFilter->SetInput(this->GetInput()); + castImageFilter->Update(); + + //--------------------------------- + // Threshold + //--------------------------------- + typename InputThresholdImageFilterType::Pointer thresholdImageFilter=InputThresholdImageFilterType::New(); + thresholdImageFilter->SetInput(castImageFilter->GetOutput()); + thresholdImageFilter->ThresholdAbove(m_MaximumNumberOfLabels); + thresholdImageFilter->SetOutsideValue(m_ForegroundValue); + if(m_Verbose) std::cout<<"Thresholding the input to "<Update(); + + //--------------------------------- + // Set -1 to padding value + //--------------------------------- + typename SetBackgroundImageFilterType::Pointer setBackgroundFilter =SetBackgroundImageFilterType::New(); + setBackgroundFilter->SetInput(thresholdImageFilter->GetOutput()); + setBackgroundFilter->SetInput2(castImageFilter->GetOutput()); + setBackgroundFilter->SetMaskValue(m_ErosionPaddingValue); + setBackgroundFilter->SetOutsideValue(-1); + if(m_Verbose) std::cout<<"Setting the eroded region from "<SetInput(setBackgroundFilter->GetOutput()); + if(m_Verbose) std::cout<<"Counting the initial labels..."<Update(); + unsigned int initialNumberOfLabels= inputStatisticsImageFilter->GetMaximum(); + if(m_Verbose) std::cout<<"The input contained "<::AccumulateType difference=1; + typename InternalImageType::Pointer labelImage=inputStatisticsImageFilter->GetOutput(); + typename InternalImageType::Pointer oldLabelImage=inputStatisticsImageFilter->GetOutput(); + + // element + KernelType structuringElement; + structuringElement.SetRadius(m_Radius); + structuringElement.CreateStructuringElement(); + + while( difference) + { + // Dilate all labels once + for ( int label=0; label<(int)numberOfConsideredLabels+1;label++) + if ( m_BackgroundValue != label) + { + typename ConditionalBinaryDilateImageFilterType::Pointer dilateFilter=ConditionalBinaryDilateImageFilterType::New(); + dilateFilter->SetBoundaryToForeground(false); + dilateFilter->SetKernel(structuringElement); + dilateFilter->SetBackgroundValue (-1); + dilateFilter->SetInput (labelImage); + dilateFilter->SetForegroundValue (label); + if(m_Verbose) std::cout<<"Dilating the label "<Update(); + labelImage=dilateFilter->GetOutput(); + } + + // Difference with previous labelImage + typename DifferenceImageFilterType::Pointer differenceFilter=DifferenceImageFilterType::New(); + differenceFilter->SetValidInput(oldLabelImage); + differenceFilter->SetTestInput(labelImage); + differenceFilter->Update(); + difference =differenceFilter->GetTotalDifference(); + if(m_Verbose) std::cout<<"The change in this iteration was "<SetInput(labelImage); + setBackgroundFilter2->SetInput2(labelImage); + setBackgroundFilter2->SetMaskValue(-1); + setBackgroundFilter2->SetOutsideValue(m_ErosionPaddingValue); + if(m_Verbose) std::cout<<"Setting the eroded region to "<SetInput(setBackgroundFilter2->GetOutput()); + if(m_Verbose) std::cout<<"Casting the output..."<Update(); + + //--------------------------------- + // SetOutput + //--------------------------------- + this->SetNthOutput(0, outputCastImageFilter->GetOutput()); + + + } + + +}//end clitk + +#endif //#define clitkReconstructThroughDilationImageFilter_txx -- 2.45.1