[Insight-users] Erreur de segmentation

Luis Ibanez luis.ibanez at kitware.com
Thu Sep 24 12:23:05 EDT 2009


Hi Yoann,

A "segmentation error" message typically means that you are
using a pointer for accessing memory that has not been allocated
or that has been released already.

Looking at your code, you are accessing argv[7] for the filename
of the image to write, but you are only checking for argc to be
at least 6. You should check for it to be at least 8.

Chances are that you  are passing an insufficient number of
command line arguments to your program, and therefore the
argv[] pointers attempt to access unallocated memory.


BTW: Compiling your program for Debug and running it into
      a debugger, would give you a definite confirmation.


    Regards,


        Luis


--------------------
Yoann Moreau wrote:
> Hi all !
> 
> I'm in trouble with famous "Erreur of segmentation", I try to read about 
> this problem in different post, but I 'm always still in the fog. (not 
> sure about that expression).
> 
> What mean that error : Erreur de segmentation
> Is it due to OTB ? Gdal ( I suspect this one) ? or a misstake in the 
> matrix (I'm still not sure of that expression) ? or simply an error in 
> source code ?
> 
> Anyway I'm working on a Debian Etch with Gdal version 1.5.2 and otb 3.0
> Thank for explanation.
> 
> 
> (The aim of my work is to apply a centered2rigidtransform to an image 
> for which I define the parameters there is my source code in case :
> 
> #include "otbImage.h"
> 
> 
> #include "otbImageFileReader.h"
> #include "otbImageFileWriter.h"
> 
> #include "itkCenteredRigid2DTransform.h"
> #include "itkResampleImageFilter.h"
> 
> 
> int main( int argc, char *argv[] )
> {
>   if ( argc < 6 )
>   {
>     std::cerr << "Missing Parameters " << std::endl;
>     std::cerr << "Usage: " << argv[0];
>     std::cerr << " ImageFile ";
>     std::cerr << " angle centreRotX centreRotY transX transY ";
>     std::cerr << " OutputImageFile";
>     std::cerr << " "<< std::endl;
>     return EXIT_FAILURE;
>   }
> 
> 
> const    unsigned int    Dimension = 2;
> typedef  unsigned short   PixelType;
> 
> typedef otb::Image< PixelType, Dimension >  ImageType;
> typedef otb::ImageFileReader< ImageType  > ImageReaderType;
> 
> ImageReaderType::Pointer  ImageReader  = ImageReaderType::New();
> 
> ImageReader->SetFileName(  argv[1] );
> ImageReader->Update();
> 
> ImageType::Pointer Image = ImageReader->GetOutput();
> 
> typedef itk::ResampleImageFilter<  ImageType,  ImageType >    
> ResampleFilterType;
> typedef itk::CenteredRigid2DTransform< double > TransformType;
>  
> 
> ResampleFilterType::Pointer resample = ResampleFilterType::New();
> 
> const unsigned int FinalParametersLength = 5;
> typedef TransformType::ParametersType FinalParametersType;
> 
> FinalParametersType Parameters;
> 
> Parameters[0] =atoi(argv[2]);
> 
> Parameters[1] = atoi(argv[3]);
> 
> Parameters[2] = atoi(argv[4]);
> 
> Parameters[3] = atoi(argv[5]);
> 
> Parameters[4] = atoi(argv[6]);
> 
> TransformType::Pointer finalTransform = TransformType::New();
> finalTransform->SetParameters( Parameters );
> 
>   std::cout << "Origin  = " << Image->GetOrigin() <<std::endl;
>   std::cout << " Spacing  = " << Image->GetSpacing()  << std::endl;
>   std::cout << " Size   = " << 
> Image->GetLargestPossibleRegion().GetSize()  << std::endl;
> 
>   resample->SetTransform( finalTransform );
>   resample->SetInput( ImageReader->GetOutput() );
>   resample->SetSize( Image->GetLargestPossibleRegion().GetSize() );
>   resample->SetOutputOrigin(  Image->GetOrigin() );
>   resample->SetOutputSpacing( Image->GetSpacing() );
>   resample->SetDefaultPixelValue( 1 );
> 
>  typedef otb::ImageFileWriter < ImageType >  WriterType;
> WriterType::Pointer      writer =  WriterType::New();
>  writer->SetFileName( argv[7] );
>   writer->SetInput( resample->GetOutput() );
> 
>   try
>   {
>     writer->Update();
>   }
>   catch ( itk::ExceptionObject & excp )
>   {
>     std::cerr << "ExceptionObject while writing the resampled image !" 
> << std::endl;
>     std::cerr << excp << std::endl;
>     return EXIT_FAILURE;
>   }
> 
> 
> ------------------------------------------------------------------------
> 
> _____________________________________
> 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