[Insight-users] ImageToImageFilter: producing two different types of output

Mathieu Malaterre mathieu.malaterre at gmail.com
Wed Aug 22 08:31:25 EDT 2007


Hello,


  I am trying to write an ImagetoImageFilter that would produce two
types of output, two output are the same type as the input and the
last one (3rd) is floating point type. For some reason the filter is
crashing. I suspect that the allocation did not go correctly for the
third output (second type).

Prototype is:

template <class TImage>
class ITK_EXPORT MyImageFilter:
    public ImageToImageFilter<TImage, TImage>
{
...
  /** Get the error image output of this process object.  */
  typedef Image<float,3> ErrorImageType;
  ErrorImageType::Pointer GetErrorOutput()
  { return static_cast<ErrorImageType *>(this->ProcessObject::GetOutput(2)); }

  /** Set the error image output of this process object.  */
  void SetErrorOutput(ErrorImageType *output)
  { this->SetNthOutput(2, output); }
...
}

And in the ThreadedGenerateData :

ThreadedGenerateData(const ImageRegionType& outputRegionForThread,
                       int threadId)
{
  ErrorImageType::Pointer outputErrorPtr = this->GetErrorOutput();
  OutputIterator outIt(outputPtr, outputRegionForThread);
  ...
  //outIt.Set( residual ); // everything works if I comment out the 'Set'
  ...
}

Finally here is the cstor:

::MyImageFilter()
{
  this->ProcessObject::SetNumberOfRequiredOutputs(3);
  typename TImage::Pointer output = TImage::New();
  this->ProcessObject::SetNthOutput(1, output.GetPointer());
  ErrorImageType::Pointer e1 = ErrorImageType::New();
  this->ProcessObject::SetNthOutput(2, e1.GetPointer());
}

Comments welcome,


-- 
Mathieu


More information about the Insight-users mailing list