namespace itk {
template <class TImageType>
class CompositeExampleImageFilter :
public ImageToImageFilter<TImageType, TImageType>
{
public:
typedef CompositeExampleImageFilter Self;
typedef ImageToImageFilter<TImageType,TImageType> Superclass;
typedef SmartPointer<Self> Pointer;
typedef SmartPointer<const Self> ConstPointer;
itkNewMacro(Self);
itkTypeMacro(CompositeExampleImageFilter, ImageToImageFilter);
void PrintSelf( std::ostream& os, Indent indent ) const;
typedef typename TImageType::PixelType PixelType;
itkGetMacro( Threshold, PixelType);
itkSetMacro( Threshold, PixelType);
protected:
CompositeExampleImageFilter();
protected:
typedef ThresholdImageFilter< TImageType > ThresholdType;
typedef GradientMagnitudeImageFilter< TImageType, TImageType > GradientType;
typedef RescaleIntensityImageFilter< TImageType, TImageType > RescalerType;
void GenerateData();
private:
CompositeExampleImageFilter(Self&);
void operator=(const Self&);
typename GradientType::Pointer m_GradientFilter;
typename ThresholdType::Pointer m_ThresholdFilter;
typename RescalerType::Pointer m_RescaleFilter;
PixelType m_Threshold;
};
}
namespace itk
{
template <class TImageType>
CompositeExampleImageFilter<TImageType>
::CompositeExampleImageFilter()
{
m_Threshold = 1;
m_GradientFilter = GradientType::New();
m_ThresholdFilter = ThresholdType::New();
m_ThresholdFilter->SetInput( m_GradientFilter->GetOutput() );
m_RescaleFilter = RescalerType::New();
m_RescaleFilter->SetInput( m_ThresholdFilter->GetOutput() );
m_RescaleFilter->SetOutputMinimum(
}
template <class TImageType>
void
CompositeExampleImageFilter<TImageType>::
GenerateData()
{
m_GradientFilter->SetInput( this->GetInput() );
m_ThresholdFilter->ThresholdBelow( this->m_Threshold );
m_RescaleFilter->GraftOutput( this->GetOutput() );
m_RescaleFilter->Update();
this->GraftOutput( m_RescaleFilter->GetOutput() );
}
template <class TImageType>
void
CompositeExampleImageFilter<TImageType>::
PrintSelf( std::ostream& os, Indent indent ) const
{
Superclass::PrintSelf(os,indent);
os
<< indent << "Threshold:" << this->m_Threshold
<< std::endl;
}
}
int main( int argc, char* argv[] )
{
if( argc < 3 )
{
std::cerr << "Usage: " << std::endl;
std::cerr << argv[0] << " inputImageFile outputImageFile" << std::endl;
return EXIT_FAILURE;
}
typedef itk::CompositeExampleImageFilter<ImageType> FilterType;
ReaderType::Pointer reader = ReaderType::New();
WriterType::Pointer writer = WriterType::New();
FilterType::Pointer filter = FilterType::New();
reader->SetFileName( argv[1] );
filter->SetInput( reader->GetOutput() );
filter->SetThreshold( 20 );
writer->SetInput( filter->GetOutput() );
writer->SetFileName( argv[2] );
try
{
writer->Update();
}
{
std::cerr << "Error: " << e << std::endl;
}
return 0;
}