[Insight-users] Analyze reader crash for some scalar types

Mathieu Coursolle mcoursolle at rogue-research.com
Thu Feb 5 10:10:35 EST 2009


Hi ITK users,

I am using ITK to read some Analyze files. I use the itkAnalyzeImageIO  
class to do so.
Until now, I was always reading the image as double, because I though  
all data types
can be represented by double.

However, this has a cost in memory. Some of my images are 8 bits, so I  
do not want to
use 8 times the memory needed. So once the image is loaded, I check  
the component type,
and then cast my image into that type with success.

I then realise that ReadFileInformation could be use to get the scalar  
type before the image is
read, so I use read the image in its scalar type directly. However,  
that change caused some files
that were supported before to crash my application.

Here is the code that reads my image. The scalar type is UCHAR, and  
that is the type found by
ReadImageInformation as well. The following code works fine when the  
templated scalar type
is double, but crashes when the type is uint8 (See code below).

Am I missing something here?

The code and backtrace are at the end of the mail. I tried that code  
with the latest ITK release, and ITK CVS.
I built ITK on MAC OSX 10.5.6 (intel).

Thanks,

Mathieu

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

	// Open the file with the ITK reader.
	// Create the image reader.
	typedef itk::Image<uint8_t, 3> ITK3DImage;
	typedef itk::ImageFileReader<ITK3DImage> ITK3DReader;
	ITK3DReader::Pointer reader = ITK3DReader::New();
	reader->SetFileName("/Volumes/Data/DATA/Analyse/ 
espagnol_15_1_20061128_095602_1_mri_byte.hdr");
	
	// Create and set the Image IO type.
	itk::AnalyzeImageIO::Pointer imageIO = itk::AnalyzeImageIO::New();
	reader->SetImageIO(imageIO);
	
	try
	{
		reader->Update();  // CRASH
	}
	catch (...)
	{
	}
	
	ITK3DImage::Pointer image = reader->GetOutput();
	assert (image);

     return 0;
}

The backtrace is:

#0 0xffe008c7 in ??
0000001 0x5fbfc7a0 in ??
0000002 0x81620192 in fread
0000003 0x81620192 in fread
0000004 0x812fc3ed in gzread
0000005 0x0044d528 in itk::AnalyzeImageIO::Read at  
itkAnalyzeImageIO.cxx:728
0000006 0x000dfd61 in itk::ImageFileReader<itk::Image<unsigned char,  
3u>, itk::DefaultConvertPixelTraits<unsigned char> >::GenerateData at  
itkImageFileReader.txx:398

____________________
Mathieu Coursolle, M.Ing.		
Rogue Research Inc.
www.rogue-research.com







-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.itk.org/pipermail/insight-users/attachments/20090205/add0227b/attachment.htm>


More information about the Insight-users mailing list