[ITK-users] Reading an Image in ITK, help plz!!

Khojaste, Amir amir.khojaste at sunnybrook.ca
Fri May 1 12:33:38 EDT 2015


Hey guys,

I am new to developping with ITK,VTK and will appreciate if someone can pull me off from this problem! Sorry I have included VTK mailing list here too, I have not gotten my answer in ITK mailing list yet so was thinking maybe VTK users faced the same problem too.

The following is the simplest piece of code that is simply reading an Image using "itkImageFileReader". I have built my ITK in debug mode using Cmake and VS2008. The Hello World program is running just fine but when I try to add couple of lines of code to read an image I get the following error:

Unhandled exception at 0x000000013fcedb03 in HelloWorld.exe: 0xC0000005: Access violation reading location 0xffffffffffffffff.

I am confused and don't know if this is the problem with Linking/my Cmakelists.txt or whatever else! I can read the image if I build the ITK examples and then use the codes there. This has made me even more confused!

In the Call Stack the code goes to the lines 118 to 120 of "itkImageFileReader.txx" if which I think should't.

if ( m_UserSpecifiedImageIO == false ) //try creating via factory
    {
    m_ImageIO = ImageIOFactory::CreateImageIO( m_FileName.c_str(), ImageIOFactory::ReadMode );
}


Any help?!


/***** Code

#include "itkImage.h"
#include "itkImageFileWriter.h"
#include "itkImageFileReader.h"
#include "itkCropImageFilter.h"
#include "itksys/SystemTools.hxx"

typedef unsigned char          PixelType;
const unsigned int             Dimension = 3;

typedef itk::Image< PixelType, Dimension >   ImageType;
typedef itk::ImageFileReader<ImageType> ReaderType;

int main(int argc, char *argv[])
{

  ReaderType::Pointer reader = ReaderType::New();
  reader->SetFileName( argv[1] );

  reader->Update(); // This line will crash
  system("pause");

  return EXIT_SUCCESS;

}


/*==== CMakeLists.txt

# This is the root ITK CMakeLists file.
CMAKE_MINIMUM_REQUIRED(VERSION 2.4)
IF(COMMAND CMAKE_POLICY)
  CMAKE_POLICY(SET CMP0003 NEW)
ENDIF(COMMAND CMAKE_POLICY)


# This project is designed to be built outside the Insight source tree.
PROJECT(HelloWorld)

# Find ITK.
FIND_PACKAGE(ITK REQUIRED)
INCLUDE(${ITK_USE_FILE})

ADD_EXECUTABLE(HelloWorld HelloWorld.cxx )

TARGET_LINK_LIBRARIES(HelloWorld ${ITK_LIBRARIES})

This e-mail is intended only for the named recipient(s) and may contain confidential, personal and/or health information (information which may be subject to legal restrictions on use, retention and/or disclosure).  No waiver of confidence is intended by virtue of communication via the internet.  Any review or distribution by anyone other than the person(s) for whom it was originally intended is strictly prohibited.  If you have received this e-mail in error, please contact the sender and destroy all copies.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://public.kitware.com/pipermail/insight-users/attachments/20150501/fb6fd183/attachment.html>


More information about the Insight-users mailing list