[Insight-users] Bus Error/ Segmentation Fault with example

Julien Jomier jjomier at cs.unc.edu
Fri Jul 30 15:18:31 EDT 2004


Hi Jacob,

The itkJPEGImageIO supports only 'unsigned char' images. Can you try to
change your InputPixelType to unsigned char? (typedef unsigned char
InputPixelType;)

Also, you should catch the possible exception when reading/writing a file.

  try 
    { 
    reader->Update(); 
    } 
  catch( itk::ExceptionObject & err ) 
    { 
    std::cout << "ExceptionObject caught !" << std::endl; 
    std::cout << err << std::endl; 
    return -1;
    }

Hope this helps,

Julien

> -----Original Message-----
> From: insight-users-bounces at itk.org 
> [mailto:insight-users-bounces at itk.org] On Behalf Of Jacob Boomgaarden
> Sent: Friday, July 30, 2004 3:10 PM
> To: insight-users at itk.org
> Subject: [Insight-users] Bus Error/ Segmentation Fault with example
> 
> 
> Hello all,
> 
> I am running a simple example to use the 
> ConfidenceConnectedImageFilter for
> segmentation
> on a two-dimensional jpg image and I continually encounter 
> either a Bus error (core
> dumped) or a Segmentation fault (core dumped) message when 
> trying to run my program
> 
> Here is my program code:
> 
> #include "itkImage.h"
> #include "itkImageFileReader.h"
> #include "itkImageFileWriter.h"
> 
> #include "itkCurvatureFlowImageFilter.h"
> #include "itkConfidenceConnectedImageFilter.h"
> #include "itkCastImageFilter.h"
> 
> int main(int argc, char **argv)
> {
> 
>    if( argc < 5)
>    {
>       std::cerr<< "Usage: " <<std::endl;
>       std::cerr<< argv[0] << "inputImageFile outputImagefile 
> seedX seedY"<<std::endl;
>       return 1;
>    }
> 
>    typedef float		InputPixelType;
>    typedef unsigned char	OutputPixelType;
>    const unsigned int		Dimension = 2;
> 
>    typedef itk::Image< InputPixelType, Dimension > 	InputImageType;
>    typedef itk::Image< OutputPixelType, Dimension >	OutputImageType;
> 
>    typedef itk::ImageFileReader< InputImageType > 	ReaderType;
>    typedef itk::ImageFileWriter< OutputImageType >	WriterType;
>    typedef itk::CurvatureFlowImageFilter<
> 		InputImageType, InputImageType >	NoiseFilterType;
>    typedef itk::ConfidenceConnectedImageFilter<
> 		InputImageType, InputImageType >	
> SegmentationFilterType;
>    typedef itk::CastImageFilter<
> 		InputImageType, OutputImageType >	
> CastingFilterType;
> 
> 
>    ReaderType::Pointer reader = ReaderType::New();
>    WriterType::Pointer writer = WriterType::New();
>    NoiseFilterType::Pointer noisefilter = NoiseFilterType::New();
>    CastingFilterType::Pointer caster = CastingFilterType::New();
>    SegmentationFilterType::Pointer segmentfilter = 
> SegmentationFilterType::New();
> 
>    const char * inputfile = argv[1];
>    const char * outputfile = argv[2];
> 
>    reader->SetFileName( inputfile );
>    writer->SetFileName( outputfile );
> 
>    noisefilter->SetInput( reader->GetOutput() );
>    segmentfilter->SetInput( noisefilter->GetOutput() );
>    caster->SetInput( segmentfilter->GetOutput() );
>    writer->SetInput( caster->GetOutput() );
> 
>    noisefilter->SetNumberOfIterations( 5 );
>    noisefilter->SetTimeStep( 0.125 );
> 
>    segmentfilter->SetMultiplier( 2.5 );
> 
>    segmentfilter->SetNumberOfIterations( 5 );
> 
>    segmentfilter->SetReplaceValue( 255 );
> 
> 
>    InputImageType::IndexType  index;
> 
>    index[0] = atoi( argv[3] );
>    index[1] = atoi( argv[4] );
> 
>    segmentfilter->SetSeed( index );
> 
>    segmentfilter->SetInitialNeighborhoodRadius( 2 );
> 
> 
>    // Execute the pipeline within an error catching block
>    try
>    {
> 	writer->Update();
>    }
>    catch( itk::ExceptionObject & excep )
>    {
>    	std::cerr << "Exception caught !" << std::endl;
>     	std::cerr << excep << std::endl;
> 		return 1;
>    }
> 
>    std::cout<<"All Done"<<std::endl;
> 
>    return 0;
> 
> }
> 
> Here is what I type in as command line args: ctlungs.jpg 
> newlungs.jpg 198 100
> 
> Thanks for any help you can provide,
> 
> 
> 
> 
> -- 
> Jacob Boomgaarden
> ARSC Intern
> West Ridge Research Building, Room 011
> Phone:  (907)-455-3350
> Office: (907)-450-8701
> Email: boomgaar at arsc.edu
> 
> 
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users
> 



More information about the Insight-users mailing list