[Insight-users] Image reader problem
Charles Knox
knoxcharles at qwest.net
Sun May 11 20:14:49 EDT 2008
Hello Bill,
I've some more clues (perhaps). I modified my test program to read TIF
data along with DICOM. When reading a TIF file I get a fault in
itkImageFileReader.txx around line 345. The code there is:
---------------------------------------------------------------------------------------------------------
// Test if the file exist and if it can be open.
// and exception will be thrown otherwise.
try
{
m_ExceptionMessage = "";
this->TestFileExistanceAndReadability();
}
catch(itk::ExceptionObject &err)
{
m_ExceptionMessage = err.GetDescription();
}
// Tell the ImageIO to read the file
//
OutputImagePixelType *buffer =
output->GetPixelContainer()->GetBufferPointer();
m_ImageIO->SetFileName(m_FileName.c_str());
ImageIORegion ioRegion(TOutputImage::ImageDimension);
typedef ImageIORegionAdaptor< TOutputImage::ImageDimension >
ImageIOAdaptor;
// Convert the m_StreamableRegion from ImageRegion type to
ImageIORegion type
ImageIOAdaptor::Convert( this->m_StreamableRegion, ioRegion );
itkDebugMacro (<< "ioRegion: " << ioRegion);
---------------------------------------------------------------------------------------------------------
Execution stops at the call to SetFileName with a NULL pointer for
m_ImageIO:
+ m_ImageIO {m_Pointer=0x00000000 }
itk::SmartPointer<itk::ImageIOBase>
The TIF file name has been stored in itkImageFileReader as:
+ m_FileName "G:\Test
Images\HarvardHead\CT_DICOM\peghead.J.166.tif"
std::basic_string<char,std::char_traits<char>,std::allocator<char> >
Regards,
Charles
My test program's modified reader function is:
---------------------------------------------------------------------------------------------------------
BOOL CDICOMReaderTestDoc::ReadDICOMImage( const LPCTSTR path)
{
/*
*/
std::string spath((char *)path);
itk::GDCMImageIO::Pointer gdcmIO = itk::GDCMImageIO::New();
itk::TIFFImageIO::Pointer tiffIO = itk::TIFFImageIO::New();
::delete [] m_image;
m_image = NULL;
typedef signed short PixelType;
// Set dimensions to 3 to have reader return z-value
const UINT Dimension = 3;
typedef itk::Image< PixelType, Dimension > ImageType;
typedef itk::ImageFileReader< ImageType > ReaderType;
ReaderType::Pointer reader = ReaderType::New();
// First check for a DICOM file or TIF file.
if (tiffIO->CanReadFile(spath.c_str()))
reader->SetImageIO(tiffIO);
else if (gdcmIO->CanReadFile(spath.c_str()))
reader->SetImageIO( gdcmIO );
// CRASHES ON THIS CALL
reader->SetFileName(spath.c_str() );
// Return prematurely to invoke 'reader' destructor
//return FALSE;
try {
reader->Update();
} catch (std::exception &err) {
CString msg(err.what());
AfxMessageBox(msg);
return FALSE;
}
ImageType::Pointer image = reader->GetOutput();
// Image size
ImageType::SizeType size = image->GetLargestPossibleRegion().GetSize();
m_imageSize.cx = size[0];
m_imageSize.cy = size[1];
long bytesPerPixel = sizeof(PixelType);
long nPixels = m_imageSize.cx * m_imageSize.cy;
long nBytes = nPixels * bytesPerPixel;
// Transfer image data into buffer
typedef itk::ImageRegionIterator< ImageType > IteratorType;
IteratorType iter( image, image->GetLargestPossibleRegion() );
PixelType *data = ::new PixelType[nPixels];
PixelType *row = ::new PixelType[m_imageSize.cx];
PixelType *pB = data + nPixels - m_imageSize.cx;
iter.GoToBegin();
// get data and mirror y
for (int j = 0; j < m_imageSize.cy; j++) {
for (int i = 0; i < m_imageSize.cx; i++, ++iter)
*(row + i) = iter.Get();
memcpy((void *)pB, (void *)row, m_imageSize.cx * sizeof(PixelType));
pB -= m_imageSize.cx;
}
::delete [] row;
m_image = ::new BYTE[nPixels];
if (sizeof(PixelType) == 1) {
// DICOM data are going to be 2-bpp
// but just in case...
memcpy( m_image, data, nPixels);
::delete [] data;
return TRUE;
}
// Convert (possibly) signed pixels to unsigned, rescale
// and save image in member variable m_image.
int i;
PixelType min, max, *pd = data, maxgray = ~0;
for ( i = 0; i < nPixels; pd++, i++) {
if (*pd < min)
min = *pd;
if (*pd > max)
max = *pd;
}
long pixel, offset = min, range = max - min;
for ( i = 0, pd = data; i < nPixels; i++) {
pixel = (((long )*pd++ - offset) * (long)maxgray)/range;
m_image[i] = (BYTE)(pixel >> 8);
}
::delete [] data;
return TRUE;
/* Creates a gray level ramp image for view testing.
::delete [] m_image;
m_image = ::new BYTE[512*512];
m_imageSize.SetSize(512, 512);
for (int j = 0; j < 512; j++)
for (int i = 0; i < 512; m_image[512*j+i] = i, i++)
;
return TRUE;
*/}
---------------------------------------------------------------------------------------------------------
Bill Lorensen wrote:
> Charles,
>
> What error occurs before the crash?
>
> Bill
>
>
>
More information about the Insight-users
mailing list