[Insight-users] mini-pipeline output region problem

matthew mrrm at web.de
Mon Feb 3 12:36:02 EST 2014


Hi everyone.

I am trying to set up a mini-pipline in the GenerateData() of a filter.
Basically, the filter takes a label map, crops and aggregates it and
produces a binary image.
If I inspect the output's regions, everything seems to be fine, but when
passing the output to the file writer, I am getting the following error:

terminate called after throwing an instance of
'itk::ImageFileWriterException'
  what(): 
/usr/local/ITK/Modules/IO/ImageBase/include/itkImageFileWriter.hxx:402:
Did not get requested region!
Requested:
ImageRegion (0x7fff25c7a050)
  Dimension: 3
  Index: [55, 75, 60]
  Size: [512, 512, 183]
Actual:
ImageRegion (0x7fff25c7a090)
  Dimension: 3
  Index: [55, 75, 60]
  Size: [285, 282, 109]


So, for some reason the writer uses the regions from the input labelmap and
not the regions of the filter's output.
What's going wrong here and how can I get rid of it?


************from main()******************

inputFileName = ....
outputFileName = ....

...
typedef unsigned char                                                                            
BinaryPixelType;
typedef itk::Image<BinaryPixelType, 3>                                                   
BinaryImageType;
typedef itk::LabelObject<BinaryPixelType, 3>                                            
LabelObjectType;
typedef itk::LabelMap<LabelObjectType>                                                  
LabelMapType;
typedef itk::BinaryImageToLabelMapFilter<BinaryImageType, LabelMapType>
ImageToLabelMapFilterType;
typedef itk::ImageFileReader<BinaryImageType>                                      
ReaderType;
typedef itk::ImageFileWriter< BinaryImageType >                                     
WriterType;
    
const BinaryPixelType INSIDE  = itk::NumericTraits<BinaryPixelType>::One;
const BinaryPixelType OUTSIDE = itk::NumericTraits<BinaryPixelType>::Zero;


ReaderType::Pointer reader = ReaderType::New();
reader->SetFileName( inputFileName );

ImageToLabelMapFilterType::Pointer im2LabelMapFilter =
ImageToLabelMapFilterType::New();
im2LabelMapFilter->SetInputForegroundValue(INSIDE);
im2LabelMapFilter->SetOutputBackgroundValue(OUTSIDE);
im2LabelMapFilter->SetInput(reader->GetOutput());

TestFilter<LabelMapType, BinaryImageType>::Pointer testFilter =
TestFilter<LabelMapType, BinaryImageType>::New();
testFilter->SetInput( im2LabelMapFilter->GetOutput() );
testFilter->Update();

testFilter->Print(std::cout, 3);

testFilter->GetOutput()->Print(std::cout, 3);

typename WriterType::Pointer writer = WriterType::New();
writer->SetFileName( outputFileName );
writer->SetInput(  testFilter->GetOutput() );
writer->Update();


***********HEADER*****************

#ifndef TESTFILTER_H_
#define TESTFILTER_H_

#include <itkLabelMapToBinaryImageFilter.h>
#include <itkAutoCropLabelMapFilter.h>
#include <itkAggregateLabelMapFilter.h>
#include <itkLabelMapFilter.h>
#include "itkNumericTraits.h"
#include "itkObjectFactory.h"
#include <itkLabelObject.h>
#include <itkDataObject.h>


template<class TLabelMap, class TBinaryImage>
class TestFilter:
public itk::LabelMapFilter<TLabelMap, TBinaryImage>
{
    public:

        /** standard class typedefs. */
        typedef TestFilter                                                          
Self;
        typedef itk::LabelMapFilter<TLabelMap, TBinaryImage>                     
Superclass;
        typedef itk::SmartPointer< Self >                                           
Pointer;

        /** label map typedefs */
        typedef TLabelMap                                                          
LabelMapType;

        /** binary output image typedefs **/
        typedef TBinaryImage                                                       
BinaryImageType;

        /** label map filter typedefs */
        typedef itk::LabelMapToBinaryImageFilter<LabelMapType,
BinaryImageType>     LabelMapToBinaryImageFilter;
        typedef itk::AutoCropLabelMapFilter<LabelMapType>                          
AutoCropLabelMapFilterType;
        typedef itk::AggregateLabelMapFilter<LabelMapType>                         
AggregateLabelMapFilterType;

        /** Run-time type information (and related methods). */
        itkTypeMacro( TestFilter, LabelMapFilter);

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

    protected:

         TestFilter(){ };
        ~TestFilter(){ };
        virtual void GenerateData();

    private:

        TestFilter(const Self &); //purposely not implemented
        void operator=(const Self &);                                  
//purposely not implemented
};

#include "TestFilter.cpp"

#endif /* TESTFILTER_H_ */




**********SOURCE*****************

#ifndef TESTFILTER_CPP_
#define TESTFILTER_CPP_

#include "TestFilter.h"

template<class TLabelMap, class TBinaryImage>
void
TestFilter<TLabelMap, TBinaryImage>
::GenerateData()
{
        // allocate the output
        this->AllocateOutputs();

        // auto crop the input label map
        typename AutoCropLabelMapFilterType::Pointer autoCropLabelMapFilter  
= AutoCropLabelMapFilterType::New();
        autoCropLabelMapFilter->SetInput( this->GetInput() );

        // aggregate croped input label map
        typename AggregateLabelMapFilterType::Pointer
aggregateLabelMapFilter = AggregateLabelMapFilterType::New();
       
aggregateLabelMapFilter->SetInput(autoCropLabelMapFilter->GetOutput());

        // generate a binary image from the label map
        typename LabelMapToBinaryImageFilter::Pointer
labelMapToBinaryImageFilter = LabelMapToBinaryImageFilter::New();
        labelMapToBinaryImageFilter->SetInput(
aggregateLabelMapFilter->GetOutput() );
       
labelMapToBinaryImageFilter->SetForegroundValue(itk::NumericTraits<typename
TBinaryImage::PixelType>::One);
       
labelMapToBinaryImageFilter->SetBackgroundValue(itk::NumericTraits<typename
TBinaryImage::PixelType>::Zero);

        // Graft this filters output onto the mini-pipeline so the
mini-pipeline
        // has the correct region ivars and will write to this filters bulk
data
        // output.
        labelMapToBinaryImageFilter->GraftOutput( this->GetOutput() );

        // Update the filter
        labelMapToBinaryImageFilter->Update();

        // Graft the last output of the mini-pipeline onto this filters
output so
        // the final output has the correct region ivars and a handle to the
final
        // bulk data
        this->GraftOutput(labelMapToBinaryImageFilter->GetOutput());
}

#endif


**********testFilter->Print(std::cout, 3)*****************

   TestFilter (0x1de60c0)
     RTTI typeinfo:  
TestFilter<itk::LabelMap<itk::LabelObject<unsigned char, 3u> >,
itk::Image<unsigned char, 3u> >
     Reference Count: 1
     Modified Time: 87
     Debug: Off
     Observers: 
       none
     Inputs: 
       Primary: (0x1de5d60) *
     Indexed Inputs: 
       0: Primary (0x1de5d60)
     Required Input Names: Primary
     NumberOfRequiredInputs: 1
     Outputs: 
       Primary: (0x1dea5b0)
     Indexed Outputs: 
       0: Primary (0x1dea5b0)
     NumberOfRequiredOutputs: 1
     Number Of Threads: 4
     ReleaseDataFlag: Off
     ReleaseDataBeforeUpdateFlag: Off
     AbortGenerateData: Off
     Progress: 0
     Multithreader: 
       RTTI typeinfo:   itk::MultiThreader
       Reference Count: 1
       Modified Time: 76
       Debug: Off
       Observers: 
         none
       Thread Count: 4
       Global Maximum Number Of Threads: 128
       Global Default Number Of Threads: 4
     CoordinateTolerance: 1e-06
     DirectionTolerance: 1e-06


**********testFilter->GetOutput()->Print(std::cout, 3)*****************

   Image (0x1dea5b0)
     RTTI typeinfo:   itk::Image<unsigned char, 3u>
     Reference Count: 1
     Modified Time: 46718
     Debug: Off
     Observers: 
       none
     Source: (0x1de60c0) 
     Source output name: Primary
     Release Data: Off
     Data Released: False
     Global Release Data: Off
     PipelineMTime: 246
     UpdateMTime: 46719
     RealTimeStamp: 0 seconds 
     LargestPossibleRegion: 
       Dimension: 3
       Index: [55, 75, 60]
       Size: [285, 282, 109]
     BufferedRegion: 
       Dimension: 3
       Index: [55, 75, 60]
       Size: [285, 282, 109]
     RequestedRegion: 
       Dimension: 3
       Index: [55, 75, 60]
       Size: [285, 282, 109]
     Spacing: [0.74219, 0.74219, 1.5]
     Origin: [0, 0, 0]
     Direction: 
1 0 0
0 1 0
0 0 1

     IndexToPointMatrix: 
0.74219 0 0
0 0.74219 0
0 0 1.5

     PointToIndexMatrix: 
1.34736 0 0
0 1.34736 0
0 0 0.666667

     Inverse Direction: 
1 0 0
0 1 0
0 0 1

     PixelContainer: 
       ImportImageContainer (0x1dea870)
         RTTI typeinfo:   itk::ImportImageContainer<unsigned long, unsigned
char>
         Reference Count: 1
         Modified Time: 46709
         Debug: Off
         Observers: 
           none
         Pointer: 0x7f37a41ee010
         Container manages memory: true
         Size: 8760330
         Capacity: 47972352




--
View this message in context: http://itk-users.7.n7.nabble.com/mini-pipeline-output-region-problem-tp33314.html
Sent from the ITK - Users mailing list archive at Nabble.com.


More information about the Insight-users mailing list