/*========================================================================= 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 clitkDecomposeThroughErosionImageFilter_txx #define clitkDecomposeThroughErosionImageFilter_txx /* ================================================= * @file clitkDecomposeThroughErosionImageFilter.txx * @author * @date * * @brief * ===================================================*/ namespace clitk { //------------------------------------------------------------------- // Update with the number of dimensions //------------------------------------------------------------------- template DecomposeThroughErosionImageFilter::DecomposeThroughErosionImageFilter() { m_Verbose=false; m_Lower =1; m_Upper=1; m_Inside=1; m_Outside=0; m_ErosionPaddingValue=static_cast(-1); for (unsigned int i=0; i void DecomposeThroughErosionImageFilter::GenerateData() { //--------------------------------- // Typedefs //--------------------------------- // Internal type typedef itk::Image InternalImageType; // Filters used typedef itk::BinaryThresholdImageFilter InputBinaryThresholdImageFilter; typedef itk::BinaryBallStructuringElement KernelType; typedef itk::BinaryErodeImageFilter BinaryErodeImageFilterType; typedef itk::BinaryThresholdImageFilter BinaryThresholdImageFilterType; typedef itk::StatisticsImageFilter StatisticsImageFilterType; typedef itk::ConnectedComponentImageFilter ConnectFilterType; typedef itk::RelabelComponentImageFilter RelabelImageFilterType; typedef clitk::SetBackgroundImageFilter SetBackgroundImageFilterType; //--------------------------------- // Binarize input //--------------------------------- typename InputBinaryThresholdImageFilter::Pointer inputBinarizer=InputBinaryThresholdImageFilter::New(); inputBinarizer->SetInput(this->GetInput()); inputBinarizer->SetLowerThreshold(m_Lower); inputBinarizer->SetUpperThreshold(m_Upper); inputBinarizer ->SetInsideValue(m_Inside); inputBinarizer ->SetOutsideValue(m_Outside); if(m_Verbose) std::cout<<"Binarizing the input..."<Update(); //--------------------------------- // Label the input //--------------------------------- typename ConnectFilterType::Pointer inputConnectFilter=ConnectFilterType::New(); inputConnectFilter->SetInput(inputBinarizer->GetOutput()); inputConnectFilter->SetBackgroundValue(0); inputConnectFilter->SetFullyConnected(m_FullyConnected); if(m_Verbose) std::cout<<"Labelling the connected components..."<Update(); //--------------------------------- // Count the initial labels //--------------------------------- typename StatisticsImageFilterType::Pointer inputStatisticsImageFilter=StatisticsImageFilterType::New(); inputStatisticsImageFilter->SetInput(inputConnectFilter->GetOutput()); if(m_Verbose) std::cout<<"Counting the initial labels..."<Update(); unsigned int initialNumberOfLabels= inputStatisticsImageFilter->GetMaximum(); if(m_Verbose) std::cout<<"The input contained "<GetOutput(); typename InternalImageType::Pointer output=inputBinarizer->GetOutput(); unsigned int iteration=0; unsigned int max =initialNumberOfLabels; while ( (iteration < m_MinimumNumberOfIterations) || ( (max< initialNumberOfLabels + m_NumberOfNewLabels ) && (iteration<100 ) ) ) { if(m_Verbose) std::cout<<"Eroding image (iteration "<SetInput (current); erosionFilter->SetForegroundValue (1); erosionFilter->SetBackgroundValue (-1); erosionFilter->SetBoundaryToForeground(false); erosionFilter->SetKernel(structuringElement); erosionFilter->Update(); current=erosionFilter->GetOutput(); //--------------------------------- // Binarize (remove -1) //--------------------------------- typename BinaryThresholdImageFilterType::Pointer binarizer=BinaryThresholdImageFilterType::New(); binarizer->SetInput(erosionFilter->GetOutput()); binarizer->SetLowerThreshold(1); binarizer->SetUpperThreshold(1); binarizer ->SetInsideValue(1); binarizer ->SetOutsideValue(0); if(m_Verbose) std::cout<<"Binarizing the eroded image..."<Update(); //--------------------------------- // ReLabel the connected components //--------------------------------- typename ConnectFilterType::Pointer connectFilter=ConnectFilterType::New(); connectFilter->SetInput(binarizer->GetOutput()); connectFilter->SetBackgroundValue(0); connectFilter->SetFullyConnected(m_FullyConnected); if(m_Verbose) std::cout<<"Labelling the connected components..."<Update(); //--------------------------------- // Sort //--------------------------------- typename RelabelImageFilterType::Pointer relabelFilter=RelabelImageFilterType::New(); relabelFilter->SetInput(connectFilter->GetOutput()); relabelFilter->SetMinimumObjectSize(m_MinimumObjectSize); //relabelFilter->Update(); //--------------------------------- // Count the labels //--------------------------------- typename StatisticsImageFilterType::Pointer statisticsImageFilter=StatisticsImageFilterType::New(); statisticsImageFilter->SetInput(relabelFilter->GetOutput()); statisticsImageFilter->Update(); max= statisticsImageFilter->GetMaximum(); if(m_Verbose) std::cout<<"Counted "<GetOutput(); // Next iteration iteration++; } //--------------------------------- // Binarize current (remove -1) //--------------------------------- typename BinaryThresholdImageFilterType::Pointer binarizer=BinaryThresholdImageFilterType::New(); binarizer->SetInput(current); binarizer->SetLowerThreshold(1); binarizer->SetUpperThreshold(1); binarizer ->SetInsideValue(1); binarizer ->SetOutsideValue(0); if(m_Verbose) std::cout<<"Binarizing the eroded image..."<Update(); //--------------------------------- // ReLabel the connected components //--------------------------------- typename ConnectFilterType::Pointer connectFilter=ConnectFilterType::New(); connectFilter->SetInput(binarizer->GetOutput()); connectFilter->SetBackgroundValue(0); connectFilter->SetFullyConnected(m_FullyConnected); if(m_Verbose) std::cout<<"Labelling the connected components..."<Update(); //--------------------------------- // Sort //--------------------------------- typename RelabelImageFilterType::Pointer relabelFilter=RelabelImageFilterType::New(); relabelFilter->SetInput(connectFilter->GetOutput()); //relabelFilter->SetMinimumObjectSize(m_MinimumObjectSize); // Preserve all intensities //relabelFilter->Update(); //--------------------------------- // Set -1 to padding value //--------------------------------- typename SetBackgroundImageFilterType::Pointer setBackgroundFilter =SetBackgroundImageFilterType::New(); setBackgroundFilter->SetInput(relabelFilter->GetOutput()); setBackgroundFilter->SetInput2(current); setBackgroundFilter->SetMaskValue(-1); setBackgroundFilter->SetOutsideValue(m_ErosionPaddingValue); if(m_Verbose) std::cout<<"Setting the eroded region to "< CastImageFilterType; typename CastImageFilterType::Pointer caster= CastImageFilterType::New(); caster->SetInput(setBackgroundFilter->GetOutput()); caster->Update(); //--------------------------------- // SetOutput //--------------------------------- this->SetNthOutput(0, caster->GetOutput()); } }//end clitk #endif //#define clitkDecomposeThroughErosionImageFilter_txx