{
template <typename TImage>
class CompositeExampleImageFilter : public ImageToImageFilter<TImage, TImage>
{
public:
ITK_DISALLOW_COPY_AND_MOVE(CompositeExampleImageFilter);
using Self = CompositeExampleImageFilter;
using Superclass = ImageToImageFilter<TImage, TImage>;
using Pointer = SmartPointer<Self>;
itkOverrideGetNameOfClassMacro(CompositeExampleImageFilter);
using ImageType = TImage;
using PixelType = typename ImageType::PixelType;
itkGetMacro(Threshold, PixelType);
itkSetMacro(Threshold, PixelType);
protected:
CompositeExampleImageFilter();
protected:
using ThresholdType = ThresholdImageFilter<ImageType>;
using GradientType = GradientMagnitudeImageFilter<ImageType, ImageType>;
using RescalerType = RescaleIntensityImageFilter<ImageType, ImageType>;
void
GenerateData() override;
void
PrintSelf(std::ostream & os, Indent indent) const override;
private:
typename GradientType::Pointer m_GradientFilter;
typename ThresholdType::Pointer m_ThresholdFilter;
typename RescalerType::Pointer m_RescaleFilter;
PixelType m_Threshold;
};
}
{
template <typename TImage>
CompositeExampleImageFilter<TImage>::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(
NumericTraits<PixelType>::NonpositiveMin());
m_RescaleFilter->SetOutputMaximum(NumericTraits<PixelType>::max());
}
template <typename TImage>
void
CompositeExampleImageFilter<TImage>::GenerateData()
{
auto input = ImageType::New();
input->Graft(const_cast<ImageType *>(this->GetInput()));
m_GradientFilter->SetInput(input);
m_ThresholdFilter->ThresholdBelow(this->m_Threshold);
m_RescaleFilter->GraftOutput(this->GetOutput());
m_RescaleFilter->Update();
this->GraftOutput(m_RescaleFilter->GetOutput());
}
template <typename TImage>
void
CompositeExampleImageFilter<TImage>::PrintSelf(std::ostream & os,
{
Superclass::PrintSelf(os, indent);
os << indent << "Threshold: " << 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;
}
auto reader = ReaderType::New();
reader->SetFileName(argv[1]);
using FilterType = itk::CompositeExampleImageFilter<ImageType>;
auto filter = FilterType::New();
filter->SetInput(reader->GetOutput());
filter->SetThreshold(20);
auto writer = WriterType::New();
writer->SetInput(filter->GetOutput());
writer->SetFileName(argv[2]);
try
{
writer->Update();
}
{
std::cerr << "Error: " << e << std::endl;
}
return EXIT_SUCCESS;
}
Standard exception handling object.
Data source that reads image data from a single file.
Writes image data to a single file.
Templated n-dimensional image class.
Control indentation during Print() invocation.
SmartPointer< const Self > ConstPointer
BinaryGeneratorImageFilter< TInputImage1, TInputImage2, TOutputImage > Superclass
SmartPointer< Self > Pointer
The "itk" namespace contains all Insight Segmentation and Registration Toolkit (ITK) classes....