[Insight-users] RE: Run time Error in itk::ImageMomentsCalculator().

Lydia Ng lng at insightful.com
Sun, 14 Mar 2004 12:20:26 -0800


Hi,

You might want to put a try/catch around calculator->Compute() so try to
catch the exception and display the message.

Also I think you might need to connectedThreshold->Update() before =
calling
calculator->Compute().

- Lydia


> -----Original Message-----
> From: yasser salman [mailto:yass71 at yahoo.com]
> Sent: Saturday, March 13, 2004 12:28 PM
> To: insight-users at itk.org; Lydia Ng
> Cc: Luis Ibanez
> Subject: Run time Error in itk::ImageMomentsCalculator().
>=20
> hi Lydia.,
> when i'm using
> calculator->
>      SetImage( connectedThreshold->GetOutput() );
>  calculator->Compute();
> the run time error Msg occured when i remove
> calculator->Compute(); there is no problem .., can i
> find out where is the error..,
>=20
>=20
> ..,
>=20
>=20
>=20
> typedef unsigned short   InputPixelType;
> >   typedef float        InternalPixelType;
> >   typedef unsigned short   SegmentedPixelType;
> >
> >   typedef itk::Image< InputPixelType, 3 >
> > InputImageType;
> >   typedef itk::Image< InternalPixelType, 3>
> > InternalImageType;
> >   typedef itk::Image< SegmentedPixelType, 3 >
> > SegmentedImageType;
> >
> > typedef
> > itk::ImageMomentsCalculator<SegmentedImageType>
> > 		ImageMomentsType;
> >
> >   typedef   itk::CastImageFilter<
> >                  InputImageType,
> >                  InternalImageType >
> > CastImageFilterType;
> >
> >   typedef   itk::CurvatureFlowImageFilter<
> >                  InternalImageType,
> >                  InternalImageType >
> > CurvatureFlowImageFilterType;
> >
> >
> >   typedef itk::ConnectedThresholdImageFilter<
> > 			InternalImageType, SegmentedImageType >
> > ConnectedFilterType;
> >
> >   typedef itk::ImageToVTKImageFilter<
> > SegmentedImageType >
> > ITK2VTKConnectorFilterType;
> >
> >   typedef itk::VTKImageToImageFilter< InputImageType
> >   >
> > VTK2ITKConnectorFilterType;
> >
> > typedef itk::ImageSeriesReader< InputImageType >
> > ReaderType;
> >
> >   itk::DICOMImageIO2::Pointer dicomIO =3D
> > itk::DICOMImageIO2::New();
> >
> >   // Get the DICOM filenames from the directory
> >   itk::DICOMSeriesFileNames::Pointer nameGenerator =3D
> > itk::DICOMSeriesFileNames::New();
> >
> >   nameGenerator->SetDirectory( argv[1] );
> >
> >          std::cerr << "Usage: viewer1 imagefilename
> > xseed yseed zseed neighborhoodsize" << std::endl;
> >
> >   typedef std::vector<std::string>
> seriesIdContainer;
> >   const seriesIdContainer & seriesUID =3D
> > nameGenerator->GetSeriesUIDs();
> > seriesIdContainer::const_iterator seriesItr =3D
> > seriesUID.begin();
> >   seriesIdContainer::const_iterator seriesEnd =3D
> > seriesUID.end();
> >   std::cout << std::endl << "The directory: " <<
> > std::endl;
> >   //std::cout << std::endl << argv[1] << std::endl
> <<
> > std::endl;
> >   std::cout << "Contains the following DICOM Series:
> > ";
> >   std::cout << std::endl << std::endl;
> >   while( seriesItr !=3D seriesEnd )
> >     {
> >     std::cout << seriesItr->c_str() << std::endl;
> >     seriesItr++;
> >     }
> >
> >   std::cout << std::endl << std::endl;
> >   std::cout << "Now reading series: " << std::endl
> <<
> > std::endl;
> >
> >   typedef std::vector<std::string>
> fileNamesContainer;
> >   fileNamesContainer fileNames;
> >   argc=3D3;   ///Part One
> >   if( argc < 4 ) // If no optional third argument
> >     {
> >     std::cout << seriesUID.begin()->c_str() <<
> > std::endl;
> >     fileNames =3D nameGenerator->GetFileNames();
> >     }
> >   else  //part Two..
> >     {
> >     std::cout << argv[3] << std::endl;
> >     fileNames =3D nameGenerator->GetFileNames( argv[3]
> > );
> >     }
> >   std::cout << std::endl << std::endl;
> >
> >   ReaderType::Pointer reader =3D ReaderType::New();
> >   reader->SetFileNames( fileNames );
> >   reader->SetImageIO( dicomIO );
> >
> >   try
> >     {
> >     reader->Update();
> >     }
> >   catch (itk::ExceptionObject &ex)
> >     {
> >     std::cout << ex << std::endl;
> >     return EXIT_FAILURE;
> >     }
> >
> >
> >   CastImageFilterType::Pointer cast =3D
> > CastImageFilterType::New();
> >
> >   CurvatureFlowImageFilterType::Pointer smoothing =3D
> > CurvatureFlowImageFilterType::New();
> >
> >
> >   ConnectedFilterType::Pointer connectedThreshold =3D
> > 	  ConnectedFilterType::New();
> >
> >   VTK2ITKConnectorFilterType::Pointer
> VTK2ITKconnector
> > =3D
> > VTK2ITKConnectorFilterType::New();
> >   ImageMomentsType::Pointer
> > calculator=3DImageMomentsType::New();
> >
> >
> >   cast->SetInput( reader->GetOutput() );
> >
> >   smoothing->SetInput(  cast->GetOutput() );
> >   confidence->SetInput( smoothing->GetOutput() );
> >
> >   smoothing->SetTimeStep( 0.125 );
> >   smoothing->SetNumberOfIterations( 2 );
> >     connectedThreshold->SetInput(
> > smoothing->GetOutput() );
> >
> > 	 const InternalPixelType lowerThreshold =3D 190;
> >   const InternalPixelType upperThreshold =3D 205;
> >   connectedThreshold->SetLower(  lowerThreshold  );
> >   connectedThreshold->SetUpper(  upperThreshold  );
> >   connectedThreshold->SetReplaceValue( 255 );
> >
> >
> >   typedef ConnectedFilterType::IndexType IndexType;
> >   IndexType seed;
> >   seed[0] =3D 126;
> >   seed[1] =3D 126;
> >   seed[2] =3D 9;
> >
> >   std::cout << "Using seed =3D " << seed << std::endl;
> >   connectedThreshold->SetSeed( seed );
> >
> >   //confidence->SetInitialNeighborhoodRadius( 2);
> >
> >   ITK2VTKConnectorFilterType::Pointer
> ITK2VTKconnector
> > =3D
> > ITK2VTKConnectorFilterType::New();
> >
> >     SetImage( connectedThreshold->GetOutput() );
>  calculator->Compute();
>=20
> >
> >// double area =3D calculator->GetTotalMass();
> ...,,,
>=20
> vtk_visualization...,,,,,etc..,
> ...,
>=20
> __________________________________
> Do you Yahoo!?
> Yahoo! Mail - More reliable, more storage, less spam
> http://mail.yahoo.com