[Insight-users] simple filter wrapping gaussian smooth problem

protein proteinbme at gmail.com
Mon Mar 20 09:07:39 EST 2006


Hi all,

I'm learning to write a basic filter by just wrapping a gaussian smooth filter.
The class definition is as follows and it compiled sucessfully.

However when execicuting, I was given the following error:
Error:
itk::ExceptionObject (0xbfecd420)
Location: "Unknown"
File: /u4/home/gth818n/usr/local/itk/InsightToolkit-2-4-1/Code/Common/itkMultiThreader.cxx
Line: 358
Description: itk::ERROR: MultiThreader(0x8cf21f8): Exception occurred
during SingleMethodExecute

The problem seems to be caused by the convolution not being able to be
execicuted by multi-thread.
Can anyone help me by telling me how can I make this simple wrapping
filiter work?

Thanks!

The class definition is in the same file as the main function as follows:

#include "itkImageToImageFilter.h"
#include "itkDiscreteGaussianImageFilter.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;

  /** Method for creation through object factory */
  itkNewMacro(Self);

  /** Run-time type information */
  itkTypeMacro(CompositeExampleImageFilter, ImageToImageFilter);

  /** Display */
  void PrintSelf( std::ostream& os, Indent indent ) const;

protected:
  CompositeExampleImageFilter();

protected:
  typedef DiscreteGaussianImageFilter< TImageType, TImageType > 
GaussianFilterType;
  void GenerateData();

private:
  CompositeExampleImageFilter(Self&);   // intentionally not
					// implemented

  void operator=(const Self&);          // intentionally not implemented

  typename GaussianFilterType::Pointer     m_GaussianFilter;
};

} /* namespace itk */


namespace itk
{

template <class TImageType>
CompositeExampleImageFilter<TImageType>::CompositeExampleImageFilter()
{
  m_RescaleFilter =  RescalerType::New();
  m_GaussianFilter = GaussianFilterType::New();
  m_GaussianFilter->SetVariance(10);
}

template <class TImageType>
void
CompositeExampleImageFilter<TImageType>::GenerateData()
{
  m_GaussianFilter->SetInput( this->GetInput() );
  m_GaussianFilter->GraftOutput( this->GetOutput() );
  m_GaussianFilter->Update()
  this->GraftOutput( m_GaussianFilter->GetOutput() );
}

template <class TImageType>
void
CompositeExampleImageFilter<TImageType>::PrintSelf( std::ostream& os,
Indent indent ) const
{
  Superclass::PrintSelf(os,indent);
}

} /* end namespace itk */

#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<unsigned 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;
}


More information about the Insight-users mailing list