[Insight-users] CompositeFilterExample and modification
    Ignacio García Fenoll 
    igfenoll at gmail.com
       
    Wed Apr  2 07:49:48 EDT 2008
    
    
  
Good after-noon itk users!!
I am trying to use CompositeFilterExample (the compilation has been
satisfactory) but the output image is not well built. Have anybody had the
same problem?
By the way, I have constructed another filter using as base
CompositeFilterExample. I want that my filter get an image, reescale its
intensity and, after that, make an automatic adaptation of the histogram. In
the same way, I have obtained an executable, but it doesn't work. What is
the problem with that?
This is my code.
#if defined(_MSC_VER)
#pragma warning ( disable : 4786 )
#endif
#ifdef __BORLANDC__
#define ITK_LEAN_AND_MEAN
#endif
#include "itkImageToImageFilter.h"
#include "itkRescaleIntensityImageFilter.h"
#include "itkAdaptiveHistogramEqualizationImageFilter.h"
#include "itkNumericTraits.h"
namespace itk {
template <class TImageType>
class ITK_EXPORT 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);
  typedef typename TImageType::PixelType PixelType;
protected:
  CompositeExampleImageFilter();
protected:
  typedef RescaleIntensityImageFilter< TImageType, TImageType >
RescalerType;
  typedef AdaptiveHistogramEqualizationImageFilter< TImageType >
EqualizerType;
    void GenerateData();
private:
  CompositeExampleImageFilter(Self&);   // intentionally not implemented
  void operator=(const Self&);          // intentionally not implemented
  typename RescalerType::Pointer     m_RescaleFilter;
  typename EqualizerType::Pointer    m_EqualizeFilter;
};
}
namespace itk
{
//  Software Guide : BeginCodeSnippet
template <class TImageType>
CompositeExampleImageFilter<TImageType>
::CompositeExampleImageFilter()
{
  m_RescaleFilter = RescalerType::New();
  m_EqualizeFilter = EqualizerType::New();
m_RescaleFilter->SetOutputMinimum(NumericTraits<PixelType>::NonpositiveMin());
  m_RescaleFilter->SetOutputMaximum(NumericTraits<PixelType>::max());
  m_EqualizeFilter->SetInput( m_RescaleFilter->GetOutput() );
}
template <class TImageType>
void
CompositeExampleImageFilter<TImageType>::
GenerateData()
{
  m_RescaleFilter->SetInput( this->GetInput() );
  m_RescaleFilter->Update();
  m_EqualizeFilter->SetInput( this->GetOutput() );
  m_EqualizeFilter->Update();
}
}
#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"
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::Image<short, 2>                        ImageType;
  typedef itk::ImageFileReader<ImageType>             ReaderType;
  typedef itk::ImageFileWriter<ImageType>             WriterType;
  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() );
  writer->SetInput( filter->GetOutput() );
  writer->SetFileName( argv[2] );
  try
    {
    writer->Update();
    }
  catch ( itk::ExceptionObject e )
    {
    std::cerr << "Error: " << e << std::endl;
    }
  return 0;
}
Thank you very much!!!
-- 
Ignacio García Fenoll
Grupo de Imágenes Médicas
Departamento de Teoría de la Señal y Comunicaciones
Universidad de Sevilla
e-mail: igfenoll at gmail.com
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20080402/ba1b2373/attachment.htm>
    
    
More information about the Insight-users
mailing list