/*========================================================================= Program: Insight Segmentation & Registration Toolkit Module: $RCSfile: itkRobustAutomaticThresholdImageFilter.txx,v $ Language: C++ Date: $Date: 2006/03/15 01:57:09 $ Version: $Revision: 1.8 $ Copyright (c) Insight Software Consortium. All rights reserved. See ITKCopyright.txt or http://www.itk.org/HTML/Copyright.htm for details. This software is distributed WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the above copyright notices for more information. =========================================================================*/ #ifndef _itkRobustAutomaticThresholdImageFilter_txx #define _itkRobustAutomaticThresholdImageFilter_txx #include "itkRobustAutomaticThresholdImageFilter.h" #include "itkBinaryThresholdImageFilter.h" #include "itkProgressAccumulator.h" namespace itk { template RobustAutomaticThresholdImageFilter ::RobustAutomaticThresholdImageFilter() { m_OutsideValue = NumericTraits::Zero; m_InsideValue = NumericTraits::max(); m_Threshold = NumericTraits::Zero; m_Pow = 1; m_MaskValue = NumericTraits::max(); this->SetNumberOfRequiredInputs( 2 ); } template void RobustAutomaticThresholdImageFilter ::GenerateData() { typename ProgressAccumulator::Pointer progress = ProgressAccumulator::New(); progress->SetMiniPipelineFilter(this); // Compute the Threshold for the input image typename CalculatorType::Pointer thresholdCalculator = CalculatorType::New(); thresholdCalculator->SetInput( this->GetInput() ); thresholdCalculator->SetGradient( this->GetGradientImage() ); thresholdCalculator->SetMask( this->GetMaskImage() ); thresholdCalculator->SetMaskValue( m_MaskValue ); thresholdCalculator->SetPow( m_Pow ); thresholdCalculator->Compute(); m_Threshold = thresholdCalculator->GetOutput(); typename BinaryThresholdImageFilter::Pointer threshold = BinaryThresholdImageFilter::New();; progress->RegisterInternalFilter(threshold, 1); threshold->GraftOutput (this->GetOutput()); threshold->SetInput (this->GetInput()); threshold->SetLowerThreshold( m_Threshold ); threshold->SetInsideValue (m_InsideValue); threshold->SetOutsideValue (m_OutsideValue); threshold->Update(); this->GraftOutput(threshold->GetOutput()); } template void RobustAutomaticThresholdImageFilter ::GenerateInputRequestedRegion() { const_cast(this->GetInput())->SetRequestedRegionToLargestPossibleRegion(); const_cast(this->GetGradientImage())->SetRequestedRegionToLargestPossibleRegion(); if( this->GetMaskImage() ) { const_cast(this->GetMaskImage())->SetRequestedRegionToLargestPossibleRegion(); } } template void RobustAutomaticThresholdImageFilter ::PrintSelf(std::ostream& os, Indent indent) const { Superclass::PrintSelf(os,indent); os << indent << "Threshold: " << static_cast::PrintType>(m_Threshold) << std::endl; os << indent << "MaskValue: " << static_cast::PrintType>(m_MaskValue) << std::endl; os << indent << "Pow: " << m_Pow << std::endl; } }// end namespace itk #endif