Reading Analyze 7.5 images with ITK

View: New views
5 Messages — Rating Filter:   Alert me  

Reading Analyze 7.5 images with ITK

by A.Burak Yoldemir :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hello,

I am trying to read Analyze 7.5 images using ITK, however I am getting segfault. Here is the relevant code:

            typedef unsigned char PixelType;
            const unsigned int Dimension = 3;
            typedef itk::Image< PixelType, Dimension > ImageType;
           
            typedef itk::ImageSeriesReader< ImageType > ReaderType;
           
            ReaderType::Pointer reader = ReaderType::New();
           
            typedef itk::NumericSeriesFileNames    NameGeneratorType;
            NameGeneratorType::Pointer nameGenerator = NameGeneratorType::New();

            nameGenerator->SetSeriesFormat( "/root/Desktop/default_10-v1.0.3/default_10-v1.0.3/phantom_01/clean/dwi-%02d.hdr" );
           
            nameGenerator->SetStartIndex( 0 );
            nameGenerator->SetEndIndex( 66 );
            nameGenerator->SetIncrementIndex( 1 );
           
            reader->SetImageIO( itk::AnalyzeImageIO::New() );
           
            reader->SetFileNames( nameGenerator->GetFileNames() );
            reader->Update();

I am getting a segmentation fault when the update method is called. Any ideas?

Thanks in advance,


Ahmet Burak Yoldemi

_____________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html

Kitware offers ITK Training Courses, for more information visit:
http://www.kitware.com/products/protraining.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

Re: Reading Analyze 7.5 images with ITK

by Bill Lorensen-2 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Place a try/catch block around the reader->Update() and print the
exception if one is thrown.

  try
    {
    reader->Update();
    }
  catch (itk::ExceptionObject &e)
    {
    std::cerr << e << std::endl;
    return EXIT_FAILURE;
    }


On Sun, Nov 8, 2009 at 3:40 PM, A.Burak Yoldemir <yoldemir@...> wrote:

> Hello,
>
> I am trying to read Analyze 7.5 images using ITK, however I am getting
> segfault. Here is the relevant code:
>
>             typedef unsigned char PixelType;
>             const unsigned int Dimension = 3;
>             typedef itk::Image< PixelType, Dimension > ImageType;
>
>             typedef itk::ImageSeriesReader< ImageType > ReaderType;
>
>             ReaderType::Pointer reader = ReaderType::New();
>
>             typedef itk::NumericSeriesFileNames    NameGeneratorType;
>             NameGeneratorType::Pointer nameGenerator =
> NameGeneratorType::New();
>
>             nameGenerator->SetSeriesFormat(
> "/root/Desktop/default_10-v1.0.3/default_10-v1.0.3/phantom_01/clean/dwi-%02d.hdr"
> );
>
>             nameGenerator->SetStartIndex( 0 );
>             nameGenerator->SetEndIndex( 66 );
>             nameGenerator->SetIncrementIndex( 1 );
>
>             reader->SetImageIO( itk::AnalyzeImageIO::New() );
>
>             reader->SetFileNames( nameGenerator->GetFileNames() );
>             reader->Update();
>
> I am getting a segmentation fault when the update method is called. Any
> ideas?
>
> Thanks in advance,
>
>
> Ahmet Burak Yoldemi
> _____________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Kitware offers ITK Training Courses, for more information visit:
> http://www.kitware.com/products/protraining.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
>
>
_____________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html

Kitware offers ITK Training Courses, for more information visit:
http://www.kitware.com/products/protraining.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

Re: Reading Analyze 7.5 images with ITK

by kent williams-5 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Why are you using the Image Series Reader? Analyze images comprise a
header file + a raw image data file.  Here's what we use in our code:

  template <typename TImage>
  typename TImage::Pointer ReadImage( const std::string &fileName)
  {
    typename TImage::Pointer image;

    typedef itk::ImageFileReader<TImage> ReaderType;
    typename ReaderType::Pointer reader = ReaderType::New();
    reader->SetFileName( fileName.c_str() );
    try
      {
      reader->Update();
      }
    catch( itk::ExceptionObject & err )
      {
      std::cout << "Caught an exception reading" << fileName << ": "
<< std::endl;
      std::cout << err << " " << __FILE__ << " " << __LINE__ << std::endl;
      throw err;
      }
    catch(...)
      {
      std::cout << "Error while reading image " << fileName << std::endl;
      throw;
      }
     image = reader->GetOutput();
    }
    return image;
  }



On Sun, Nov 8, 2009 at 2:40 PM, A.Burak Yoldemir <yoldemir@...> wrote:

> Hello,
>
> I am trying to read Analyze 7.5 images using ITK, however I am getting
> segfault. Here is the relevant code:
>
>             typedef unsigned char PixelType;
>             const unsigned int Dimension = 3;
>             typedef itk::Image< PixelType, Dimension > ImageType;
>
>             typedef itk::ImageSeriesReader< ImageType > ReaderType;
>
>             ReaderType::Pointer reader = ReaderType::New();
>
>             typedef itk::NumericSeriesFileNames    NameGeneratorType;
>             NameGeneratorType::Pointer nameGenerator =
> NameGeneratorType::New();
>
>             nameGenerator->SetSeriesFormat(
> "/root/Desktop/default_10-v1.0.3/default_10-v1.0.3/phantom_01/clean/dwi-%02d.hdr"
> );
>
>             nameGenerator->SetStartIndex( 0 );
>             nameGenerator->SetEndIndex( 66 );
>             nameGenerator->SetIncrementIndex( 1 );
>
>             reader->SetImageIO( itk::AnalyzeImageIO::New() );
>
>             reader->SetFileNames( nameGenerator->GetFileNames() );
>             reader->Update();
>
> I am getting a segmentation fault when the update method is called. Any
> ideas?
>
> Thanks in advance,
>
>
> Ahmet Burak Yoldemi
> _____________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Kitware offers ITK Training Courses, for more information visit:
> http://www.kitware.com/products/protraining.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
>
>
_____________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html

Kitware offers ITK Training Courses, for more information visit:
http://www.kitware.com/products/protraining.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

Re: Reading Analyze 7.5 images with ITK

by kent williams-5 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Err shouldnt' edit code in GMAIL -- remove the curly brace before
"return image;"

On Mon, Nov 9, 2009 at 9:10 AM, kent williams <nkwmailinglists@...> wrote:

> Why are you using the Image Series Reader? Analyze images comprise a
> header file + a raw image data file.  Here's what we use in our code:
>
>  template <typename TImage>
>  typename TImage::Pointer ReadImage( const std::string &fileName)
>  {
>    typename TImage::Pointer image;
>
>    typedef itk::ImageFileReader<TImage> ReaderType;
>    typename ReaderType::Pointer reader = ReaderType::New();
>    reader->SetFileName( fileName.c_str() );
>    try
>      {
>      reader->Update();
>      }
>    catch( itk::ExceptionObject & err )
>      {
>      std::cout << "Caught an exception reading" << fileName << ": "
> << std::endl;
>      std::cout << err << " " << __FILE__ << " " << __LINE__ << std::endl;
>      throw err;
>      }
>    catch(...)
>      {
>      std::cout << "Error while reading image " << fileName << std::endl;
>      throw;
>      }
>     image = reader->GetOutput();
>    }
>    return image;
>  }
>
>
>
> On Sun, Nov 8, 2009 at 2:40 PM, A.Burak Yoldemir <yoldemir@...> wrote:
>> Hello,
>>
>> I am trying to read Analyze 7.5 images using ITK, however I am getting
>> segfault. Here is the relevant code:
>>
>>             typedef unsigned char PixelType;
>>             const unsigned int Dimension = 3;
>>             typedef itk::Image< PixelType, Dimension > ImageType;
>>
>>             typedef itk::ImageSeriesReader< ImageType > ReaderType;
>>
>>             ReaderType::Pointer reader = ReaderType::New();
>>
>>             typedef itk::NumericSeriesFileNames    NameGeneratorType;
>>             NameGeneratorType::Pointer nameGenerator =
>> NameGeneratorType::New();
>>
>>             nameGenerator->SetSeriesFormat(
>> "/root/Desktop/default_10-v1.0.3/default_10-v1.0.3/phantom_01/clean/dwi-%02d.hdr"
>> );
>>
>>             nameGenerator->SetStartIndex( 0 );
>>             nameGenerator->SetEndIndex( 66 );
>>             nameGenerator->SetIncrementIndex( 1 );
>>
>>             reader->SetImageIO( itk::AnalyzeImageIO::New() );
>>
>>             reader->SetFileNames( nameGenerator->GetFileNames() );
>>             reader->Update();
>>
>> I am getting a segmentation fault when the update method is called. Any
>> ideas?
>>
>> Thanks in advance,
>>
>>
>> Ahmet Burak Yoldemi
>> _____________________________________
>> Powered by www.kitware.com
>>
>> Visit other Kitware open-source projects at
>> http://www.kitware.com/opensource/opensource.html
>>
>> Kitware offers ITK Training Courses, for more information visit:
>> http://www.kitware.com/products/protraining.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
>>
>>
>
_____________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html

Kitware offers ITK Training Courses, for more information visit:
http://www.kitware.com/products/protraining.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

Re: Reading Analyze 7.5 images with ITK

by A.Burak Yoldemir :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I added the try/catch block. It gives a segmentation fault, however does not throw an exception. Here is the code and the output:

Code:
            typedef unsigned char PixelType;
            const unsigned int Dimension = 3;
            typedef itk::Image< PixelType, Dimension > ImageType;
           
            typedef itk::ImageSeriesReader< ImageType > ReaderType;
           
            ReaderType::Pointer reader = ReaderType::New();
           
            typedef itk::NumericSeriesFileNames    NameGeneratorType;
            NameGeneratorType::Pointer nameGenerator = NameGeneratorType::New();


            nameGenerator->SetSeriesFormat( "/root/Desktop/default_10-v1.0.3/default_10-v1.0.3/phantom_01/clean/dwi-%02d.hdr" );
   
            nameGenerator->SetStartIndex( 0 );
            nameGenerator->SetEndIndex( 66 );
            nameGenerator->SetIncrementIndex( 1 );
   
            reader->SetImageIO( itk::AnalyzeImageIO::New() );
       
            reader->SetFileNames( nameGenerator->GetFileNames() );
   
            cout << "Before try/catch" << endl;
            try
            {
                cout << "Try1" << endl;
                reader->Update();
                cout << "Try2" << endl;
            }
            catch (itk::ExceptionObject &e)
            {
                std::cerr << e << std::endl;
                return EXIT_FAILURE;
            }


Output:
Before try/catch
Try1
Segmentation fault


Ahmet Burak Yoldemir


On Sun, Nov 8, 2009 at 11:23 PM, Bill Lorensen <bill.lorensen@...> wrote:
Place a try/catch block around the reader->Update() and print the
exception if one is thrown.

 try
   {
   reader->Update();
   }
 catch (itk::ExceptionObject &e)
   {
   std::cerr << e << std::endl;
   return EXIT_FAILURE;
   }


On Sun, Nov 8, 2009 at 3:40 PM, A.Burak Yoldemir <yoldemir@...> wrote:
> Hello,
>
> I am trying to read Analyze 7.5 images using ITK, however I am getting
> segfault. Here is the relevant code:
>
>             typedef unsigned char PixelType;
>             const unsigned int Dimension = 3;
>             typedef itk::Image< PixelType, Dimension > ImageType;
>
>             typedef itk::ImageSeriesReader< ImageType > ReaderType;
>
>             ReaderType::Pointer reader = ReaderType::New();
>
>             typedef itk::NumericSeriesFileNames    NameGeneratorType;
>             NameGeneratorType::Pointer nameGenerator =
> NameGeneratorType::New();
>
>             nameGenerator->SetSeriesFormat(
> "/root/Desktop/default_10-v1.0.3/default_10-v1.0.3/phantom_01/clean/dwi-%02d.hdr"
> );
>
>             nameGenerator->SetStartIndex( 0 );
>             nameGenerator->SetEndIndex( 66 );
>             nameGenerator->SetIncrementIndex( 1 );
>
>             reader->SetImageIO( itk::AnalyzeImageIO::New() );
>
>             reader->SetFileNames( nameGenerator->GetFileNames() );
>             reader->Update();
>
> I am getting a segmentation fault when the update method is called. Any
> ideas?
>
> Thanks in advance,
>
>
> Ahmet Burak Yoldemi
> _____________________________________
> Powered by www.kitware.com
>
> Visit other Kitware open-source projects at
> http://www.kitware.com/opensource/opensource.html
>
> Kitware offers ITK Training Courses, for more information visit:
> http://www.kitware.com/products/protraining.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
>
>


_____________________________________
Powered by www.kitware.com

Visit other Kitware open-source projects at
http://www.kitware.com/opensource/opensource.html

Kitware offers ITK Training Courses, for more information visit:
http://www.kitware.com/products/protraining.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