/*========================================================================= Program: Insight Segmentation & Registration Toolkit Module: $RCSfile: itkBinaryReconstructionByErosionImageFilter.txx,v $ Language: C++ Date: $Date: 2006/08/01 19:16:18 $ Version: $Revision: 1.7 $ 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 __itkBinaryReconstructionByErosionImageFilter_txx #define __itkBinaryReconstructionByErosionImageFilter_txx #include "itkBinaryReconstructionByErosionImageFilter.h" #include "itkProgressAccumulator.h" namespace itk { template BinaryReconstructionByErosionImageFilter ::BinaryReconstructionByErosionImageFilter() { m_BackgroundValue = NumericTraits::NonpositiveMin(); m_ForegroundValue = NumericTraits::max(); m_FullyConnected = false; this->SetNumberOfRequiredInputs(2); } template void BinaryReconstructionByErosionImageFilter ::GenerateInputRequestedRegion() { // call the superclass' implementation of this method Superclass::GenerateInputRequestedRegion(); // We need all the input. InputImagePointer input = const_cast(this->GetMarkerImage()); if( input ) { input->SetRequestedRegion( input->GetLargestPossibleRegion() ); } input = const_cast(this->GetMaskImage()); if( input ) { input->SetRequestedRegion( input->GetLargestPossibleRegion() ); } } template void BinaryReconstructionByErosionImageFilter ::EnlargeOutputRequestedRegion(DataObject *) { this->GetOutput() ->SetRequestedRegion( this->GetOutput()->GetLargestPossibleRegion() ); } template void BinaryReconstructionByErosionImageFilter ::GenerateData() { // Create a process accumulator for tracking the progress of this minipipeline ProgressAccumulator::Pointer progress = ProgressAccumulator::New(); progress->SetMiniPipelineFilter(this); // Allocate the output this->AllocateOutputs(); typename NotType::Pointer notMask = NotType::New(); notMask->SetInput( this->GetMaskImage() ); notMask->SetForegroundValue( m_ForegroundValue ); notMask->SetBackgroundValue( m_BackgroundValue ); notMask->SetNumberOfThreads( this->GetNumberOfThreads() ); progress->RegisterInternalFilter(notMask, .1f); typename NotType::Pointer notMarker = NotType::New(); notMarker->SetInput( this->GetMarkerImage() ); notMarker->SetForegroundValue( m_ForegroundValue ); notMarker->SetBackgroundValue( m_BackgroundValue ); notMarker->SetNumberOfThreads( this->GetNumberOfThreads() ); progress->RegisterInternalFilter(notMarker, .1f); typename LabelizerType::Pointer labelizer = LabelizerType::New(); labelizer->SetInput( notMask->GetOutput() ); labelizer->SetForegroundValue( m_ForegroundValue ); labelizer->SetBackgroundValue( m_BackgroundValue ); labelizer->SetFullyConnected( m_FullyConnected ); labelizer->SetNumberOfThreads( this->GetNumberOfThreads() ); progress->RegisterInternalFilter(labelizer, .3f); typename ReconstructionType::Pointer reconstruction = ReconstructionType::New(); reconstruction->SetInput( labelizer->GetOutput() ); reconstruction->SetMarkerImage( notMarker->GetOutput() ); reconstruction->SetForegroundValue( m_ForegroundValue ); reconstruction->SetNumberOfThreads( this->GetNumberOfThreads() ); progress->RegisterInternalFilter(reconstruction, .3f); // invert the image during the binarization typename BinarizerType::Pointer binarizer = BinarizerType::New(); binarizer->SetInput( reconstruction->GetOutput() ); binarizer->SetLabel( m_BackgroundValue ); binarizer->SetNegated( true ); binarizer->SetBackgroundValue( m_ForegroundValue ); binarizer->SetFeatureImage( this->GetMaskImage() ); binarizer->SetNumberOfThreads( this->GetNumberOfThreads() ); progress->RegisterInternalFilter(binarizer, .2f); binarizer->GraftOutput( this->GetOutput() ); binarizer->Update(); this->GraftOutput( binarizer->GetOutput() ); } template void BinaryReconstructionByErosionImageFilter ::PrintSelf(std::ostream &os, Indent indent) const { Superclass::PrintSelf(os, indent); os << indent << "FullyConnected: " << m_FullyConnected << std::endl; os << indent << "BackgroundValue: " << static_cast::PrintType>(m_BackgroundValue) << std::endl; os << indent << "ForegroundValue: " << static_cast::PrintType>(m_ForegroundValue) << std::endl; } }// end namespace itk #endif