How to use MakeOutput() in class which derives from ProcessObject

I had a class which was deriving from ImageToImage filter and in its constructor I was setting Inputs and Outputs in the following manner:

this->SetPrimaryInputName("BaselineImage");
this->AddRequiredInputName("BaselineImage");
this->AddRequiredInputName("FollowupImage");
this->AddRequiredInputName("BaselineICC");
this->AddRequiredInputName("FollowupICC");
this->SetNumberOfRequiredOutputs( 2 );
this->SetOutput("BaselineImage",this->MakeOutput(0)); 
this->SetOutput("FollowupImage",this->MakeOutput(1));
this->SetTransformationTypeToCombined(); 

Here is how the class has been derived:

template<typename BaselineImageType, typename FollowupImageType, typename MaskType>
	class MyFilterClass : public itk::ImageToImageFilter<BaselineImageType, itk::Image<float,BaselineImageType::ImageDimension> >

This worked, but I am now trying to derive from ProcessObject instead:

template<typename BaselineImageType, typename FollowupImageType, typename MaskType>
	class MyFilterClass : public itk::ProcessObject

And for some reason I am receiving now: Segmentation Fault (core dumped). I’ve tried debugging it and I figured it is occurring during the call of MakeOutput(0).

Any ideas why this is happening and how can avoid using MakeOutput when deriving from ProcessObject, or at least use it correctly?

If you decided to derive from ProcessObject, you will need to override more methods than when inheriting from ImageToImageFilter. You probably need to override MakeOutput(). You could look for inspiration in ImageToImageFilter's version of it, or maybe in ImageSource's version (one of them might not exist).

If you are running it in debug mode with full debug symbols, your IDE should tell you where the exception is occurring, not just silently crash. Knowing where the crash is happening should allow you to focus your attention more effectively.

1 Like

Sorry for late response. It did work like a charm :slight_smile:

1 Like