[Insight-developers] question regarding nifti IO

Hans Johnson hans-johnson at uiowa.edu
Thu Apr 30 13:14:20 EDT 2009


Luis,

The problem is that nifti does not support that larger size.

I agree with Bill that the size should be checked, and if it is greater than
32k, an exception should be thrown.

Hans


On 4/30/09 7:18 AM, "Luis Ibanez" <luis.ibanez at kitware.com> wrote:

> Hi Kent,
> 
> ITK images use the itk::Size<> type to store the
> number of pixels along every dimension.
> 
> The components of itk::Size are of type:
> 
>                  "unsigned long"
> 
> It seems that you can count on it being 32-bits
> 
>    http://en.wikipedia.org/wiki/Long_integer
> 
> 
> although after a search in the C++ standard, I couldn't
> identify a clear definition of the number of bytes expected
> in a "long int"...
> 
> 
>       Luis
> 
> 
> -------------------------------------------------------------------
> On Wed, Apr 29, 2009 at 5:10 PM, kent williams
> <norman-k-williams at uiowa.edu> wrote:
>> OK I'll log it as a bug for Analyze and NIfTI, and fix it ;-)
>> 
>> This will have to happen in WriteImageInformation, as that's the first point
>> in the ImageIO where you can get ahold of the image dimensions.
>> 
>> For ITK, ImageDimensions are at least 32 bits, right?
>> 
>> On 4/29/09 2:52 PM, "Bill Lorensen" <bill.lorensen at gmail.com> wrote:
>> 
>>> I think it's a bug if the imageio does not throw an exception for
>>> execeeding the size.
>>> 
>>> On Wed, Apr 29, 2009 at 2:43 PM, kent williams
>>> <norman-k-williams at uiowa.edu> wrote:
>>>> You¹re absolutely correct ‹ if you happen to look in the NIfTI header (in
>>>> ITK, it¹s Insight/Utilities/nifti/niftilib/nifti1.h)  you will see that the
>>>> image dimensions are stored as an array of shorts.
>>>> 
>>>>                                  /* NIFTI-1 usage         */
>>>>              /*
>>>> ANALYZE 7.5 field(s) */
>>>>  short dim[8];        /*!< Data array dimensions.*/  /* short dim[8];
>>>>        */
>>>> 
>>>> This is not a bug in ITK, this is a basic limitation of the file format.
>>>>  So
>>>> the maximum of any dimension is going to be 32767.
>>>> 
>>>> In other words, if you really want to have an image with any dimension >
>>>> 32767, you will have to use a different image format.  Which rather begs
>>>> the
>>>> question of why you would need to save such a data object to a standard
>>>> image format at all, but I¹m sure you have your reasons.
>>>> 
>>>> 
>>>> On 4/28/09 8:03 PM, "Nicholas Tustison" <ntustison at gmail.com> wrote:
>>>> 
>>>> Developers,
>>>> 
>>>> My colleague, Brian Avants, asked that I post the following question to the
>>>> Insight Developers' list.  Essentially, as he points out below, and I've
>>>> reproduced using my own code, it seems as though 1-D images can't be
>>>> created
>>>> in nifti format where the size exceeds ~30,000 pixels but can be created
>>>> using the mhd format.  Is this behavior known and is there a particular
>>>> reason for it?
>>>> 
>>>> Thanks,
>>>> Nick Tustison
>>>> 
>>>> Begin forwarded message:
>>>> 
>>>> From: brian avants <stnava at gmail.com>
>>>> Date: April 28, 2009 1:48:58 PM EDT
>>>> To: Nicholas Tustison <ntustison at gmail.com>
>>>> Subject: bug nifti writer?
>>>> 
>>>> 
>>>> 
>>>> 
>>>> is this a known/unknown bug?
>>>> 
>>>> only appears to happen if #voxels exceeds about 30,000.
>>>> suggesting datatype problem.
>>>> 
>>>> see below:
>>>> 
>>>> # first, just print the mhd header
>>>> 
>>>> $ PrintHeader zero2.mhd
>>>>  Spacing [1, 1]
>>>>  Origin [0, 0]
>>>>  Direction
>>>> 1 0
>>>> 0 1
>>>>  Size
>>>> [1, 65536]
>>>> 
>>>> # convert to nifti
>>>>  $ MultiplyImages 2 zero2.mhd 1 zero2.nii
>>>> 
>>>> # print nifti header
>>>> $ PrintHeader zero2.nii
>>>>  Spacing [1, 1]
>>>>  Origin [0, 0]
>>>>  Direction
>>>> 1 0
>>>>  0 1
>>>> 
>>>>  Size
>>>> [1, 1]
>>>> 
>>>> # size is wrong in terms of the header info
>>>> # but not in terms of the raw data ...
>>>> $ ls -l zero2.nii
>>>> -rw-r--r--  1 user  user  262496 Apr 28 13:37 zero2.nii
>>>> 
>>>> $ ls -l zero2.raw
>>>> -rw-r--r--  1 user  user  262144 Mar 25  2008 zero2.raw
>>>> 
>>>> # if i convert zero2.nii to mhd the size is wrong
>>>> ls -l zero3.raw
>>>> -rw-r--r--  1   user  user  4 Apr 28 13:42 zero3.raw
>>>> 
>>>> 
>>>> 
>>>> 
>>>> 
>>>> ________________________________
>>>> _______________________________________________
>>>> Powered by www.kitware.com
>>>> 
>>>> Visit other Kitware open-source projects at
>>>> http://www.kitware.com/opensource/opensource.html
>>>> 
>>>> 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
>>>> 
>>>> 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
>> 
>> 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
> 
> 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



More information about the Insight-developers mailing list