SPAM: [Insight-users] read raw images

camille le men camillelemen at hotmail.com
Mon Dec 5 05:58:07 EST 2005


Thanks Julien!
I think I fixed that problem of providing more information. But I still get 
an error at the execution time. It says Segmentation fault. It seems that 
the error is between thode two lines: itk::ImageIORegion::IndexType 
start;//cout works
start[0] = 0;//cout doesn't work
It must be a problem like I did not well initialize start, and it does not 
know haw much space it needs for it but I don't knox how to do it, since 
there is no New() function for it.
I give U my code:

#include "itkImageFileReader.h"
#include "itkImageFileWriter.h"
#include "itkRawImageIO.h"
#include "itkImageIOBase.h"
#include<iostream>
#include "itkImage.h"
#include "itkCastImageFilter.h"
#include "itkPNGImageIO.h"
int main( int argc, char ** argv )
{
  // Verify the number of parameters in the command line
  if( argc < 3 )
    {
    std::cerr << "Usage: " << std::endl;
    std::cerr << argv[0] << " inputImageFile  outputImageFile " << 
std::endl;
    return EXIT_FAILURE;
    }
  typedef unsigned short      PixelType;
  const   unsigned int        Dimension = 2;
  typedef itk::Image< PixelType, Dimension >    ImageType;
typedef unsigned char      PixelTypeOut;
  typedef itk::Image< PixelTypeOut, Dimension >    ImageTypeOut;
  typedef itk::ImageFileReader< ImageType >  ReaderType;
  typedef itk::ImageFileWriter< ImageTypeOut >  WriterType;
  typedef itk::RawImageIO<PixelType,Dimension> ImageIOType;
  typedef itk::PNGImageIO ImageIOTypeOut;
  typedef itk::CastImageFilter<ImageType,ImageTypeOut> CasterType;
  //typedef itk::ImageIORegion IORegionType;
ImageIOType::Pointer RawIO = ImageIOType::New();
RawIO->SetPixelType(itk::ImageIOBase::SCALAR);
RawIO->SetNumberOfDimensions(2);
RawIO->SetDimensions(0,3000);
RawIO->SetDimensions(1,2000);
RawIO->SetComponentType(itk::ImageIOBase::USHORT);

RawIO->SetByteOrderToBigEndian();
RawIO->SetFileTypeToASCII();
ImageIOTypeOut::Pointer RawIOOut = ImageIOTypeOut::New();
RawIOOut->SetPixelType(itk::ImageIOBase::SCALAR);
RawIOOut->SetNumberOfDimensions(2);
RawIOOut->SetDimensions(0,3000);
RawIOOut->SetDimensions(1,2000);
RawIOOut->SetComponentType(itk::ImageIOBase::UCHAR);

itk::ImageIORegion::IndexType start;//cout works
start[0] = 0;//cout  does not work
start[1] = 0;
itk::ImageIORegion::SizeType size;

size[0] = 300;
size[1] = 400;
itk::ImageIORegion ioregion;

ioregion.SetSize(  size  );
ioregion.SetIndex( start );

RawIOOut->SetIORegion(ioregion);

  ReaderType::Pointer reader = ReaderType::New();
  WriterType::Pointer writer = WriterType::New();

reader->SetImageIO( RawIO );
writer->SetImageIO( RawIOOut);
//writer->Print(std::cout,itk::Indent indent);
  const char * inputFilename  = argv[1];
  const char * outputFilename = argv[2];

CasterType::Pointer caster = CasterType::New();

  reader->SetFileName( inputFilename  );
  writer->SetFileName( outputFilename );
  caster->SetInput( reader->GetOutput() );
  writer->SetInput( caster->GetOutput() );


  try
    {
    writer->Update();
    }
  catch( itk::ExceptionObject & err )
    {
    std::cerr << "ExceptionObject caught !" << std::endl;
    std::cerr << err << std::endl;
    return EXIT_FAILURE;
    }


  return EXIT_SUCCESS;
}

ERROR: Segmentation Fault




>From: Julien Jomier <jjomier at cs.unc.edu>
>To: camille le men <camillelemen at hotmail.com>
>CC: insight-users at itk.org
>Subject: Re: SPAM:  [Insight-users] read raw images
>Date: Thu, 01 Dec 2005 16:00:29 -0500
>
>Hi Camille,
>
>It seems that you are only setting the RawImageIO for the writer and not 
>the reader. Also you need to provide more information, i.e size of the 
>image otherwise ITK won't be able to guess it.
>
>You can take a look at the Insight\Testing\Code\IO\itkRawImageIOTestX.cxx 
>file for more information.
>
>Hope that helps,
>
>Julien
>
>camille le men wrote:
>>Hi!
>>I'm trying to read raw images that are binary images of unsigned short. I 
>>tried with the following program, but when I execute it, it says it 
>>catches an exception in the ImageFileReader due to the non existence of 
>>m_ImageIO. If anyone knows where is the pb...I'd be glad!
>>thanks!
>>Cam.
>>prgrmme:
>>
>>#include "itkImageFileReader.h"
>>#include "itkImageFileWriter.h"
>>#include "itkRawImageIO.h"
>>#include<iostream>
>>#include "itkImage.h"
>>
>>
>>int main( int argc, char ** argv )
>>{
>>  if( argc < 3 )
>>    {
>>    std::cerr << "Usage: " << std::endl;
>>    std::cerr << argv[0] << " inputImageFile  outputImageFile " << 
>>std::endl;
>>    return EXIT_FAILURE;
>>    }
>>
>>  typedef unsigned short      PixelType;
>>  const   unsigned int        Dimension = 2;
>>  typedef itk::Image< PixelType, Dimension >    ImageType;
>>
>>  typedef itk::ImageFileReader< ImageType >  ReaderType;
>>  typedef itk::ImageFileWriter< ImageType >  WriterType;
>>  typedef itk::RawImageIO<PixelType,Dimension> ImageIOType;
>>
>>  ImageIOType::Pointer RawIO = ImageIOType::New();
>>
>>  ReaderType::Pointer reader = ReaderType::New();
>>  WriterType::Pointer writer = WriterType::New();
>>  writer->SetImageIO( RawIO );
>>  const char * inputFilename  = argv[1];
>>  const char * outputFilename = argv[2];
>>
>>  reader->SetFileName( inputFilename  );
>>  writer->SetFileName( outputFilename );
>>
>>  writer->SetInput( reader->GetOutput() );
>>
>>  try
>>    {
>>    writer->Update();
>>    }
>>  catch( itk::ExceptionObject & err )
>>    {
>>    std::cerr << "ExceptionObject caught !" << std::endl;
>>    std::cerr << err << std::endl;
>>    return EXIT_FAILURE;
>>    }
>>
>>  return EXIT_SUCCESS;
>>}
>>
>>error message:
>>
>>ExceptionObject caught !
>>
>>itk::ImageFileReaderException (0x80f5b70)
>>Location: "Unknown"
>>File: 
>>/tsi/rigoletto/tulip/kitware/install-linux-3.3/include/InsightToolkit/IO/itkImageFileReader.txx
>>
>>Line: 114
>>Description:  Could not create IO object for file part_S1_20001015.raw
>>  Tried to create one of the following:
>>    MetaImageIO
>>    PNGImageIO
>>    VTKImageIO
>>    GiplImageIO
>>    AnalyzeImageIO
>>    StimulateImageIO
>>    JPEGImageIO
>>    TIFFImageIO
>>    NrrdImageIO
>>    BMPImageIO
>>    GDCMImageIO
>>  You probably failed to set a file suffix, or
>>    set the suffix to an unsupported type.
>>
>>_________________________________________________________________
>>3 XBox 360 à gagner chaque jour avec Magic Search ! 
>>http://www.magicsearch.fr
>>
>>_______________________________________________
>>Insight-users mailing list
>>Insight-users at itk.org
>>http://www.itk.org/mailman/listinfo/insight-users
>

_________________________________________________________________
MSN Hotmail : antivirus et antispam gratuits ! 
http://www.imagine-msn.com/hotmail/default.aspx?locale=fr-FR



More information about the Insight-users mailing list