From: dsarrut Date: Fri, 6 May 2011 12:35:28 +0000 (+0200) Subject: Add filter to reconstruct labeled images with successive dilatation. Dilatation only... X-Git-Tag: v1.2.1~4^2~5 X-Git-Url: https://git.creatis.insa-lyon.fr/pubgit/?a=commitdiff_plain;h=c07fdccd87e9df37bf77f0fdfc73d7765c0fbde1;p=clitk.git Add filter to reconstruct labeled images with successive dilatation. Dilatation only occurs into BG pixels (no fusion between label objects) --- diff --git a/itk/clitkReconstructWithConditionalGrayscaleDilateImageFilter.h b/itk/clitkReconstructWithConditionalGrayscaleDilateImageFilter.h new file mode 100644 index 0000000..0b0de84 --- /dev/null +++ b/itk/clitkReconstructWithConditionalGrayscaleDilateImageFilter.h @@ -0,0 +1,108 @@ +/*========================================================================= + Program: vv http://www.creatis.insa-lyon.fr/rio/vv + + Authors belong to: + - University of LYON http://www.universite-lyon.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 + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the copyright notices for more information. + + It is distributed under dual licence + + - BSD See included LICENSE.txt file + - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html +===========================================================================*/ + +#ifndef clitkReconstructWithConditionalGrayscaleDilateImageFilter_h +#define clitkReconstructWithConditionalGrayscaleDilateImageFilter_h + +// clitk include +#include "clitkIO.h" +#include "clitkCommon.h" +#include "clitkConditionalGrayscaleDilateImageFilter.h" + +namespace clitk +{ + /* + This filter takes as input a multilabel image (and a bg value). + It performs several greyscale dilatation of radius 1, but only in + the bg pixels. It means that when two objects (with different + labels) will dilate inside each other (collistion), the dilatation + is stopped. + */ + + template + class ITK_EXPORT ReconstructWithConditionalGrayscaleDilateImageFilter : + public itk::ImageToImageFilter + { + public: + //---------------------------------------- + // ITK + //---------------------------------------- + typedef ReconstructWithConditionalGrayscaleDilateImageFilter 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( ReconstructWithConditionalGrayscaleDilateImageFilter, ImageToImageFilter); + + /** Dimension of the domain space. */ + itkStaticConstMacro(ImageDimension, unsigned int, Superclass::InputImageDimension); + + //---------------------------------------- + // Typedefs + //---------------------------------------- + typedef typename ImageType::PixelType PixelType; + typedef typename ImageType::SizeType SizeType; + + //---------------------------------------- + // Set & Get + //---------------------------------------- + itkBooleanMacro(Verbose); + itkSetMacro( Verbose, bool); + itkGetConstReferenceMacro( Verbose, bool); + + itkSetMacro(IterationNumber, int); + itkGetConstMacro(IterationNumber, int); + + itkSetMacro(BackgroundValue, PixelType); + itkGetConstMacro(BackgroundValue, PixelType); + + protected: + + //---------------------------------------- + // Constructor & Destructor + //---------------------------------------- + ReconstructWithConditionalGrayscaleDilateImageFilter(); + ~ReconstructWithConditionalGrayscaleDilateImageFilter() {}; + + //---------------------------------------- + // Update + //---------------------------------------- + // Generate Data + void GenerateData(void); + + //---------------------------------------- + // Data members + //---------------------------------------- + bool m_Verbose; + PixelType m_BackgroundValue; + int m_IterationNumber; + }; + +} // end namespace clitk + +#ifndef ITK_MANUAL_INSTANTIATION +#include "clitkReconstructWithConditionalGrayscaleDilateImageFilter.txx" +#endif + +#endif // #define clitkReconstructWithConditionalGrayscaleDilateImageFilter_h + + diff --git a/itk/clitkReconstructWithConditionalGrayscaleDilateImageFilter.txx b/itk/clitkReconstructWithConditionalGrayscaleDilateImageFilter.txx new file mode 100644 index 0000000..7a68818 --- /dev/null +++ b/itk/clitkReconstructWithConditionalGrayscaleDilateImageFilter.txx @@ -0,0 +1,79 @@ +/*========================================================================= + Program: vv http://www.creatis.insa-lyon.fr/rio/vv + + Authors belong to: + - University of LYON http://www.universite-lyon.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 + the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR + PURPOSE. See the copyright notices for more information. + + It is distributed under dual licence + + - BSD See included LICENSE.txt file + - CeCILL-B http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html +===========================================================================*/ + +#ifndef clitkReconstructWithConditionalGrayscaleDilateImageFilter_txx +#define clitkReconstructWithConditionalGrayscaleDilateImageFilter_txx + +#include + +namespace clitk +{ + + //------------------------------------------------------------------- + template + ReconstructWithConditionalGrayscaleDilateImageFilter::ReconstructWithConditionalGrayscaleDilateImageFilter() + { + m_Verbose=false; + m_BackgroundValue=0; + m_IterationNumber = 5; + } + //------------------------------------------------------------------- + + //------------------------------------------------------------------- + template + void + ReconstructWithConditionalGrayscaleDilateImageFilter::GenerateData() + { + // Get input image + typename ImageType::ConstPointer input = this->GetInput(); + + // Main loop + typename ImageType::Pointer output; + for(int r=0; r KernelType; + KernelType k; + k.SetRadius(1); + k.CreateStructuringElement(); + + // Check that BG is 0, because ConditionalGrayscaleDilateImageFilter consider BG is 0 + if (GetBackgroundValue() !=0) { + FATAL("FATAL -> BG is not 0, check ReconstructWithConditionalGrayscaleDilateImageFilter"); + // TODO -> replace 0 with new label, replace BG with 0 ; reverse at the end + } + + // ConditionalGrayscaleDilateImageFilter -> Dilate only BG value + typedef itk::ConditionalGrayscaleDilateImageFilter FilterType; + typename FilterType::Pointer m = FilterType::New(); + m->SetKernel(k); + if (r==0) { + m->SetInput(input); // First time + } + else m->SetInput(output); + m->Update(); + output = m->GetOutput(); + } + + //--------------------------------- + this->SetNthOutput(0, output); + } + +}//end clitk + +#endif //#define clitkReconstructWithConditionalGrayscaleDilateImageFilter_txx