[Insight-users] Graft error: cannot cast: is it a mini pipeline problem?

lynx.abraxas at freenet.de lynx.abraxas at freenet.de
Sat Jul 25 03:38:46 EDT 2009


Hello!


Looking  at the other threads about Graft() I wonder if my "cannot cast" error
has something to do with some minipipeline somewhere in the filters I use.  As
far  as  I  understand  MorphologicalWatershedImageFilter  has a mini pipeline
where as MorphologicalWatershedFromMarkersImageFilter has not.
Another idea I have: Could the filters I connect in my program  be  the  wrong
ones  and they don't fit to each other? Contrary they are pretty much the same
as in segGel.cxx (from the watershed insight publication).
How can I find out what PKN3itk10DataObjectE and  PKN3itk5ImageIsLj2EEE  stand
for?

Many thanks for any hints or help
Lynx

On 23/07/09 23:31:21, lynx.abraxas at freenet.de wrote:
> Hello!
> 
> 
> I've written the little test program below but it only works if I use MorphologicalWatershedImageFilter directly but not if I use MorphologicalWatershedFromMarkersImageFilter and hm, rm and cc as discribed in the publication. I used segGel.cxx as an example.
> What is wrong with my test in long form?
> What is causing:
> terminate called after throwing an instance of 'itk::ExceptionObject'
>   what():  /usr/local/include/InsightToolkit/Common/itkImage.txx:135:
> itk::ERROR: Image(0x85dd268): itk::Image::Graft() cannot cast PKN3itk10DataObjectE to PKN3itk5ImageIsLj2EEE
> 
> Many thanks for any hints or help
> Lynx
> 
> 
> 
> 
> #include <iostream>
> #include "itkSignedDanielssonDistanceMapImageFilter.h"
> #include "itkWatershedImageFilter.h"
> #include "itkMorphologicalWatershedImageFilter.h"
> #include "itkMorphologicalWatershedFromMarkersImageFilter.h"
> #include "itkMaskImageFilter.h"
> #include "itkRegionalMinimaImageFilter.h"
> #include "itkHMinimaImageFilter.h"
> #include "itkConnectedComponentImageFilter.h"
> 
> //#include "itkImage.h"
> #include "itkImageFileReader.h"
> #include "itkImageFileWriter.h"
> #include "itkRescaleIntensityImageFilter.h"
> #include "itkInvertIntensityImageFilter.h"
> #include "itkScalarToRGBPixelFunctor.h"
> #include "itkUnaryFunctorImageFilter.h"
> #include "itkLabelOverlayImageFilter.h"
> 
> 
> int main( int argc, char * argv[] )
> {
>   if( argc < 3 )
>     {
>     std::cerr << "Usage: " << argv[0];
>     std::cerr << " inputImageFile outputDistanceMapImageFile ";
>     std::cerr << " outputVoronoiMapImageFile ";
>     std::cerr << std::endl;  
>     return EXIT_FAILURE;
>     }
> 
>   typedef  unsigned char   InputPixelType;
>   //typedef  float          FilterPixelType;
>   typedef  signed short SDDMPType; // has to support negative values!
>   typedef  unsigned char  OutputPixelType;
>   const unsigned int Dimension = 2;
> 
>   typedef itk::Image<InputPixelType,  Dimension>   InputImageType;
>   typedef itk::Image<SDDMPType,  Dimension>   SDDMIType;
>   typedef itk::Image<OutputPixelType, Dimension>   OutputImageType;
>   
>   typedef itk::ImageFileReader<InputImageType>  ReaderType;
>   typedef itk::ImageFileWriter<OutputImageType>  WriterType;
> 
>   ReaderType::Pointer reader = ReaderType::New();
>   WriterType::Pointer writer = WriterType::New();
> 
>   reader->SetFileName(argv[1]);
> 
> 
> 
>   typedef itk::SignedDanielssonDistanceMapImageFilter<InputImageType,  SDDMIType>  FilterType;
>   
>   FilterType::Pointer sddm = FilterType::New();
>   sddm->SetSquaredDistance(true);
>   FilterType::Pointer sddm2 = FilterType::New();
>   sddm2->SetSquaredDistance(true);
> 
> 
>   typedef itk::HMinimaImageFilter<SDDMIType, OutputImageType> HMType;
>   HMType::Pointer hm= HMType::New();
>   hm->SetHeight(atoi(argv[5]));
>   HMType::Pointer hm2= HMType::New();
>   hm2->SetHeight(atoi(argv[5]));
> 
> 
>   typedef itk::RegionalMinimaImageFilter<OutputImageType, OutputImageType> RegMinType;
>   RegMinType::Pointer rm = RegMinType::New();
>   rm->SetFullyConnected(atoi(argv[6]));
>   RegMinType::Pointer rm2 = RegMinType::New();
>   rm2->SetFullyConnected(atoi(argv[6]));
> 
> 
>   typedef itk::ConnectedComponentImageFilter<OutputImageType, OutputImageType> LabelType;
>   LabelType::Pointer cc = LabelType::New();
>   cc->SetFullyConnected(atoi(argv[6]));
> 
> 
>   typedef itk::MorphologicalWatershedFromMarkersImageFilter<SDDMIType, OutputImageType> MWatershedType;
> //  typedef itk::MorphologicalWatershedImageFilter<SDDMIType, OutputImageType> MWatershedType;
>   MWatershedType::Pointer ws = MWatershedType::New();
>   ws->SetMarkWatershedLine(true);
>   ws->SetFullyConnected(atoi(argv[6]));
> 
>  
>   typedef itk::MaskImageFilter<OutputImageType, InputImageType, OutputImageType> MaskType;
>   MaskType::Pointer mask = MaskType::New();
>   mask->SetInput(1, reader->GetOutput());
> 
>   typedef itk::RGBPixel<unsigned char>   RGBPixelType;
>   typedef itk::Image<RGBPixelType, Dimension>    RGBImageType;
>   typedef itk::Image<unsigned long, Dimension>   LabeledImageType;
> 
>   typedef itk::Functor::ScalarToRGBPixelFunctor<OutputPixelType> ColorMapFunctorType_v;
>   typedef itk::UnaryFunctorImageFilter<OutputImageType, RGBImageType, ColorMapFunctorType_v> ColorMapFilterType_v;
>   ColorMapFilterType_v::Pointer colormapper_v = ColorMapFilterType_v::New();
> 
>   typedef itk::Functor::ScalarToRGBPixelFunctor<unsigned long> ColorMapFunctorType;
>   typedef itk::UnaryFunctorImageFilter<LabeledImageType, RGBImageType, ColorMapFunctorType> ColorMapFilterType;
>   ColorMapFilterType::Pointer colormapper = ColorMapFilterType::New();
> 
>   typedef itk::ImageFileWriter<RGBImageType> RGBFileWriterType;
>   RGBFileWriterType::Pointer writer_rgb = RGBFileWriterType::New();
> 
> 
>   typedef itk::LabelOverlayImageFilter<SDDMIType, OutputImageType, RGBImageType > OverlayType;
>   OverlayType::Pointer overlay = OverlayType::New();
> 
> 
> 
> 
> /////distmap    
>   std::cout << "signed danielson distance map..." << std::endl;
>   sddm->SetInput(reader->GetOutput());
> 
> 
> 
> ////Watershed
>   std::cout << "Morphological watershed..." << std::endl;
>   const char * watershedFileName = argv[4];
> 
>  hm->SetInput(sddm->GetOutput());
>  rm->SetInput(hm->GetOutput());
>  cc->SetInput(rm->GetOutput());
> 
> //  ws->SetInput(sddm->GetOutput());
>   ws->SetMarkerImage(cc->GetOutput());
> 
>   std::cout << "Creating first pre-output..." << std::endl;
>   writer->SetFileName(argv[2]);
>   writer->SetInput(rm->GetOutput());
>   writer->Update();
> 
>   std::cout << "Creating second pre-output..." << std::endl;
>   writer->SetFileName(argv[3]);
>   writer->SetInput(cc->GetOutput());
>   writer->Update();
> 
>   std::cout << "Creating nice output..." << std::endl;
>   mask->SetInput(0, ws->GetOutput());
>   //writer->SetInput(mask->GetOutput());
>   colormapper_v->SetInput(mask->GetOutput());
>   writer_rgb->SetInput(colormapper_v->GetOutput());
>   writer_rgb->SetFileName(watershedFileName);
> 
>   try
>     {
>     writer_rgb->Update();
>     }
>   catch( itk::ExceptionObject exp )
>     {
>     std::cerr << "Exception caught !" << std::endl;
>     std::cerr <<     exp    << std::endl;
>     }
> 
> 
>   return EXIT_SUCCESS;
> }
> 
> 
> 
> _____________________________________
> Powered by www.kitware.com
> 
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
> 
> Please keep messages on-topic and check the ITK FAQ at: http://www.itk.org/Wiki/ITK_FAQ
> 
> Follow this link to subscribe/unsubscribe:
> http://www.itk.org/mailman/listinfo/insight-users


More information about the Insight-users mailing list