/*========================================================================= 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 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::Testing::ComparisonImageFilter 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