[Insight-developers] *.nii Endianness

Williams, Norman K norman-k-williams at uiowa.edu
Wed Jul 3 12:06:21 EDT 2013


Hey, I wrote the original NIFTIImageIO.

Looking at the source, NIFTIImageIO doesn't mess with byte swapping at
all; it expects niftilib to handle that byte order issues.

And niftilib's documentation indicates that byte swapping is handled
internally:

nifti_image_read http://bit.ly/14NLSeb
nifti_image_load http://bit.ly/1b7KoQt

As for your patch I can't see in ITK where it ever does anything with the
m_ByteOrder flag.  Are you saying that setting this flag magically makes
ITK reading of your NIfTI files work?

--
Kent Williams norman-k-williams at uiowa.edu






On 7/2/13 3:10 PM, "Matt McCormick" <matt.mccormick at kitware.com> wrote:

>Hi Kevin,
>
>Thanks for the report.  I have created an issue [1] in the issue
>tracker to keep track of the issue.
>
>Thanks,
>Matt
>
>[1] https://issues.itk.org/jira/browse/ITK-3165
>
>On Tue, Jul 2, 2013 at 5:53 PM, Kevin H. Hobbs <hobbsk at ohio.edu> wrote:
>> I'm working on a set of files from ADNI with the extension ".nii".
>>
>> I don't really know the differences between NIFTI and Analyze formats.
>>
>> The values in the images differ when I read them with ITK or Paraview
>> from the values I get when I read them with Freesurfer or nifti_tool.
>>
>> I believe this is an endianness issue and I believe that ITK is ignoring
>> the endianness of the data.
>>
>> My machine runs Fedora 17 on x86_64 and I use ITK from a nightly
>> dashboard build.
>>
>> When I read a particular image of pixel type short, with freesurfer or
>> nifti_tool I see values in { 20, 21 }.
>>
>> When I read that same image in ITK or ParaView I see values in { 5120,
>> 5376 }.
>>
>> octave:13> disp(dec2hex ({20,5120,21,5376}))
>> 0014
>> 1400
>> 0015
>> 1500
>>
>> I looked at the file with hexdump and in the data part I see 0014 and
>> 0015 which are bigendian 20 and 21.
>>
>> I asked google about nifti endianness and the nifti header :
>>
>> http://nifti.nimh.nih.gov/nifti-1/documentation/nifti1fields
>>
>> Endianness of the file is determined by looking at dim[0].
>>
>> The dim field is an array of eight shorts beginning at offset 40.
>>
>> dim[0] holds the dimension of the image and is restricted to integer
>> values from 1 to 7.
>>
>> dim[1] to dim[7] hold the number of pixels along each dimension.
>>
>> According to hexdump the 3 dimensional image has "00 03" at byte offset
>> 40 so it must have been written on a bigendian machine.
>>
>> In my ITK reader I have:
>>
>>   // Reader
>>   typedef itk::ImageFileReader< SImageType >  ReaderType;
>>   ReaderType::Pointer reader = ReaderType::New();
>>   reader->SetFileName( in_file );
>>   reader->Update();
>>   std::cout
>>     << "Read by : "
>>     << reader->GetImageIO()->GetNameOfClass() << std::endl;
>>   std::cout
>>     << "Byte order is : "
>>     << reader->GetImageIO()->GetByteOrderAsString(
>>       reader->GetImageIO()->GetByteOrder() ) << std::endl;
>>
>>
>> and I get :
>>
>> Read by : NiftiImageIO
>> Byte order is : OrderNotApplicable
>>
>> ITK correctly interprets the bigendian dimensions "00a6 0100 0100" as
>> "166 256 256" instead of the rather strangely shaped little endian
>> interpretation "42496 1 1".
>>
>>
>> _______________________________________________
>> 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://kitware.com/products/protraining.php
>>
>> 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-developers
>>
>_______________________________________________
>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://kitware.com/products/protraining.php
>
>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-developers



________________________________
Notice: This UI Health Care e-mail (including attachments) is covered by the Electronic Communications Privacy Act, 18 U.S.C. 2510-2521, is confidential and may be legally privileged.  If you are not the intended recipient, you are hereby notified that any retention, dissemination, distribution, or copying of this communication is strictly prohibited.  Please reply to the sender that you have received the message in error, then delete it.  Thank you.
________________________________


More information about the Insight-developers mailing list