[Insight-users] A bug in itkAnalyzeImageIO?

Hans Johnson hans-johnson at uiowa.edu
Sat Feb 9 12:58:16 EST 2008


Jian,

The problem is actually much more complicated than that.  Both NIFTI and
Analyze use the same file name extensions, and it is impossible during the
write phase to determine which one to use.

The default behavior of ITK is to write a 2 file nifti (NIFTI_FTYPE_2) file
when presented with an ³.hdr² or ³.img² file extension.  In this case the
.hdr file will have 352 bytes and will conform to the NIFTI 2 file standard
that supports using quaternions for defining the orientation, and the file
will be supported by SPM, FSL, and many other packages.

You should also note that to use the legacy Analyze7.5 file writer it must
be explicitly specified to the ITK IO mechanism.  In this case the
orientation will be defined by the 6 codes.

The last time I checked, both MRIcro and the analyze75read have different
interpretations of the Analyze75 .hdr format.  I believe that MRIcro does
not respect orientation.


If you look at line 957of itkNiftiImageIO.cxx there is a little
documentation describing that the itkNiftiIO filter will write out Nifti-1
formatted images.

============
When a user requests writing a file with a ³.hdr² or ³.img² file extension,
the request is ambiguous as the the desired type.  For many of the
functional imaging tools (AFNI, FSL, SPM, BRAINSFit, BRAINS2,....) they have
agreed to adopt the nifti-1 standard conventions for the file header
information in order to bring some level of consistency across applications.

If you change line 952 from ³    this->m_NiftiImage->nifti_type =
NIFTI_FTYPE_NIFTI1_2;² to ³ this->m_NiftiImage->nifti_type =
NIFTI_FTYPE_ANALYZE;² then I belive that a 348 byte header consistent with
the MayoClinic definition of the dsr
(http://www.mayo.edu/bir/PDF/ANALYZE75.pdf) will be written to disk.

=============
Desired TODO list:  All the the itkAnalyzeIO functionality has been back
ported to the external niftilib libraries that are used as the basis for the
itkNiftiIO.  The entire functionality of the itkAnalyzeIO can be done with
the nifti filter using the NIFTI_FTYPE_ANALYZE flag for writing.  This would
preserve backwards compatibility and make maintenance much easier in the
future.  The only thing that would need to be figured out is how to trigger
the legacy mode (NIFTI_FTYPE_ANALYZE) rather than the nifti mode
(NIFTI_FTYPE_NIFTI_2).

I hope this helps,
Hans

-- 
Hans J. Johnson, Ph.D.
Hans-johnson at uiowa.edu

278 GH
The University of Iowa
Iowa City, IA 52241
(319) 353 8587



From: Bill Lorensen <bill.lorensen at gmail.com>
Date: Fri, 8 Feb 2008 18:27:02 -0500
To: Jian Wu <eewujian at yahoo.com>
Cc: <insight-users at itk.org>, Hans Johnson <hans-johnson at uiowa.edu>, kent
williams <nkwmailinglists at gmail.com>
Subject: Re: [Insight-users] A bug in itkAnalyzeImageIO?

Jian,
 
This looks like a bug to me. Can you make a bug report following the
instructions in:
http://itk.org/Wiki/ITK_Procedure_for_Contributing_Bug_Fixes
 
Thanks,
 
Bill
On Fri, Feb 8, 2008 at 5:46 PM, Jian Wu <eewujian at yahoo.com> wrote:
> Hi, Bill,
> I updated Nifti codes from CVS and got the same errors. But I found out what
> caused the problem. The data type of input image is unsigned short, which is
> not supported by Analyze 7.5. If the image was saved as Analyze format without
> type casting, the converted image could not be opened by the standard Analyze
> image reader. It would be nice if the NiftiImageIO could give a warning or an
> error message to prevent it from happening.
> 
> Jian
> 
> ----- Original Message ----
> From: Bill Lorensen <bill.lorensen at gmail.com>
> To: Jian Wu <eewujian at yahoo.com>
> Cc: insight-users at itk.org; Hans Johnson <hans-johnson at uiowa.edu>; kent
> williams <nkwmailinglists at gmail.com>
> Sent: Thursday, February 7, 2008 11:34:09 PM
> Subject: Re: [Insight-users] A bug in itkAnalyzeImageIO?
> 
> Jian,
>  
> There were a bunch of changes in the nifti code recently. Can you update and
> retry?
>  
> Bill
> 
> On Thu, Feb 7, 2008 at 5:43 PM, Jian Wu <eewujian at yahoo.com> wrote:
>> Hi, Bill,
>> 
>> Thanks for the prompt reply. Actually, I have tried to use itkNiftiImageIO.
>> Without explicitly specifying an ImageIO class, the ITK would use
>> itkNiftiImageIO by default if the images have the extension of 'hdr' or
>> 'img'. I tried and failed in the first place. That's why I tried to
>> explicitly use itkAnalyzeImageIO later. When itkNiftiImageIO was used, the
>> Matlab reader gave me exactly the same error message. Even worse, the
>> converted analyze image could not be opened by MIRcro. A simple test code is
>> attached here, very similar to the previous one.
>> 
>> Jian
>> 
>> Command line:
>> ImageReadWrite brainweb1e1a10f20.mha brainweb1e1a10f20.img
>> 
>> 
>> Source Code:
>> /*=========================================================================
>> 
>>   Program:   Insight Segmentation & Registration Toolkit
>>   Module:    ImageReadWrite.cxx,v $
>> 
>> 
>> =========================================================================*/
>> #if defined(_MSC_VER)
>> #pragma warning ( disable : 4786 )
>> #endif
>> 
>> #ifdef __BORLANDC__
>> #define ITK_LEAN_AND_MEAN
>> #endif
>> 
>> #include "itkImageFileReader.h"
>> #include "itkImageFileWriter.h"
>> #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 = 3;
>>   typedef itk::Image< PixelType, Dimension >    ImageType;
>> 
>>   typedef itk::ImageFileReader< ImageType >  ReaderType;
>>   typedef itk::ImageFileWriter< ImageType >  WriterType;
>> 
>>   ReaderType::Pointer reader = ReaderType::New();
>>   WriterType::Pointer writer = WriterType::New();
>> 
>>   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;
>> }
>> 
>> 
>> 
>> ----- Original Message ----
>> From: Bill Lorensen <bill.lorensen at gmail.com>
>> To: Jian Wu <eewujian at yahoo.com>
>> Cc: insight-users at itk.org; Hans Johnson <hans-johnson at uiowa.edu>; kent
>> williams <nkwmailinglists at gmail.com>
>> Sent: Thursday, February 7, 2008 2:50:30 PM
>> Subject: Re: [Insight-users] A bug in itkAnalyzeImageIO?
>> 
>> Jian,
>> Can you please try the same program with itkNiftiImageIO instead of
>> itkAnalyzeImageIO? The nifti reader/writer should produce valid analyze
>> files. We are looking at replacing itkAnalyzeImageIO's implementation with
>> itkNiftiImageIO. Nifti is a file format with a substantial and active
>> community. If we do this, we will keep the Analyze API.
>> 
>> Thanks,
>> 
>> Bill
>> 
>> On Thu, Feb 7, 2008 at 2:25 PM, Jian Wu <eewujian at yahoo.com> wrote:
>>> Hi,
>>> I'm doing image format conversion from other image types to Analyze 7.5. The
>>> program did not give me any error message. However I doubt it may not handle
>>> the image header information properly. The images I generated in Analyze 7.5
>>> format can be viewed using MRIcro image viewer. But when I tried to opened
>>> it using Matlab function analyze75read, it gave me an error message
>>> "Reference to non-existent field 'ImgDataType'." I studies the ITK source
>>> code and found out the line 1128 of itkAnalyzeImageIO.cxx states:
>>>    switch( this->m_Hdr.dime.datatype)
>>> Here "this->m_Hdr" has not been filled with proper image information yet
>>> when the input image is not in Analyze image format. I think
>>> "this->m_ComponentType" should be referred instead. My test code is attached
>>> here. I used "brainweb1e1a10f20.mha" as the input image.
>>> 
>>> Jian
>>> 
>>> Command line:
>>> ImageReadWriteAnalyze brainweb1e1a10f20.mha brainweb1e1a10f20.img
>>> 
>>> Source Code:
>>> 
>>> /*=========================================================================
>>> 
>>>  Program:   Insight Segmentation & Registration Toolkit
>>>  Module:    $ ImageReadWriteAnalyze.cxx $
>>>  Language:  C++
>>>  Date:      $Date: 2008/02/07 $
>>>  Version:   $Revision: 1.0 $
>>>  Author:     Jian Wu
>>> 
>>> =========================================================================*/
>>> #if defined(_MSC_VER)
>>> #pragma warning ( disable : 4786 )
>>> #endif
>>> 
>>> #ifdef __BORLANDC__
>>> #define ITK_LEAN_AND_MEAN
>>> #endif
>>> 
>>> #include "itkImageFileReader.h"
>>> #include "itkImageFileWriter.h"
>>> #include "itkAnalyzeImageIO.h"
>>> 
>>> #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 = 3;
>>>  typedef itk::Image< PixelType, Dimension >    ImageType;
>>> 
>>>  typedef itk::ImageFileReader< ImageType >  ReaderType;
>>>  typedef itk::ImageFileWriter< ImageType >  WriterType;
>>>  typedef itk::AnalyzeImageIO                 ImageIOType;
>>> 
>>> 
>>>  ReaderType::Pointer reader = ReaderType::New();
>>>  WriterType::Pointer writer = WriterType::New();
>>>  ImageIOType::Pointer analyzeIO = ImageIOType::New();
>>> 
>>>  const char * inputFilename  = argv[1];
>>>  const char * outputFilename = argv[2];
>>> 
>>>  reader->SetFileName( inputFilename  );
>>>  writer->SetFileName( outputFilename );
>>> 
>>>  writer->SetInput( reader->GetOutput() );
>>>  writer->SetImageIO( analyzeIO );
>>> 
>>>  try
>>>    {
>>>    writer->Update();
>>>    }
>>>  catch( itk::ExceptionObject & err )
>>>    {
>>>    std::cerr << "ExceptionObject caught !" << std::endl;
>>>    std::cerr << err << std::endl;
>>>    return EXIT_FAILURE;
>>>    }
>>> 
>>>  return EXIT_SUCCESS;
>>> }
>>> 
>>> 
>>> 
>>> 
>>> 
>>> 
>>>      
>>> ____________________________________________________________________________
>>> ________
>>> Looking for last minute shopping deals?
>>> Find them fast with Yahoo! Search.
>>> http://tools.search.yahoo.com/newsearch/category.php?category=shopping
>>> _______________________________________________
>>> Insight-users mailing list
>>> Insight-users at itk.org
>>> http://www.itk.org/mailman/listinfo/insight-users
>> 
>> 
>> 
>> 
>> Never miss a thing. Make Yahoo your homepage.
>> <http://us.rd.yahoo.com/evt=51438/*">http://www.yahoo.com/r/hs>
>> <http://www.yahoo.com/r/hs>
> 
> 
> 
> 
> Looking for last minute shopping deals? Find them fast with Yahoo! Search.
> <http://us.rd.yahoo.com/evt=51734/*">http://tools.search.yahoo.com/newsearch/c
> ategory.php?category=shopping>
> <http://tools.search.yahoo.com/newsearch/category.php?category=shopping>
> 


-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://public.kitware.com/pipermail/insight-users/attachments/20080209/ebf16a56/attachment.html


More information about the Insight-users mailing list