[Insight-users] VectorImage Orientation from NRRD

Gordon Kindlmann gk at bwh.harvard.edu
Tue Oct 14 21:43:27 EDT 2008


Hello,

I don't know about how VectorImages work in relation to  
OrientedImages as compared to regular Images, that may be the core of  
the problem here, and hopefully others can clarify that.

One thing to keep in mind is that NRRD files can name which world  
space the image orientation is defined in.  ITK, as best I  
understand, decrees that 3D image orientation is always in LPS,  
similar in semantics to the space in which DICOM defines image  
orientation.  Thus, around line 448 of Insight/Code/IO/ 
itkNrrdImageIO.cxx there's code which flips the first two  
coefficients of the space directions, and around line 502 is the  
corresponding code for the space origin.  This code kicks in when the  
NRRD file is declaring RAS.  I think this is what leads to the origin  
not being what you expected ([-125, -124.1, 79.3] instead of [125,  
124.1, 79.3] as in the file).

As for the spacing- I'd say its right: the spacings as far as ITK is  
concerned are supposed to be (I think!) positive, and its the job of  
the (unit-length) direction cosines to indicate how the samples are  
arranged along the axes.

Let me know what you think.

best,
Gordon


On Oct 14, 2008, at 7:13 PM, Daniel Betz wrote:

> Hello,
> I have a problem regarding VectorImage orientation. This is the file I
> want to load:
>
> <file namic01-dwi_compressed.nhdr>
> NRRD0005
> # Complete NRRD file format specification at:
> # http://teem.sourceforge.net/nrrd/format.html
> content: NAMIC01
> type: short
> dimension: 4
> space: right-anterior-superior
> sizes: 256 256 36 14
> thicknesses: NaN NaN 3 NaN
> space directions: (-0.9375,0,0) (0,-0.9375,0) (0,0,-3) none
> centerings: cell cell cell ???
> kinds: space space space list
> endian: little
> encoding: gzip
> space units: "mm" "mm" "mm"
> space origin: (125,124.1,79.3)
> measurement frame: (0,-1,0) (1,0,0) (0,0,-1)
> data file: namic01-dwi_compressed.raw.gz
> modality:=DWMRI
> DWMRI_b-value:=800
> DWMRI_gradient_0000:= 0 0 0
> DWMRI_gradient_0001:= 0 0 0
> DWMRI_gradient_0002:= -0.8238094 -0.4178235 -0.3830949
> DWMRI_gradient_0003:= -0.5681645 0.5019867 -0.6520725
> DWMRI_gradient_0004:= 0.4296590 0.1437401 0.8914774
> DWMRI_gradient_0005:= -0.0482123 0.6979894 0.7144833
> DWMRI_gradient_0006:= 0.8286872 -0.0896669 -0.5524829
> DWMRI_gradient_0007:= 0.9642489 -0.2240180 0.1415627
> DWMRI_gradient_0008:= -0.1944068 0.9526976 -0.2336092
> DWMRI_gradient_0009:= 0.1662157 0.6172332 -0.7690224
> DWMRI_gradient_0010:= -0.3535898 -0.9178798 -0.1801968
> DWMRI_gradient_0011:= -0.7404186 -0.5774342 0.3440203
> DWMRI_gradient_0012:= -0.2763061 0.0476582 0.9598873
> DWMRI_gradient_0013:= 0.6168819 -0.7348858 -0.2817793
> </file>
>
> The file contains DWI data and the orientation in the file is LPI  
> which
> after applying the "space directions" becomes RAS orientation.
>
> I condensed my problem to this little program:
>
> <code>
> #include <itkImage.h>
> #include <itkVectorImage.h>
> #include <itkImageFileReader.h>
> #include <itkNrrdImageIO.h>
>
> int main( int argc, char ** argv )
> {
>   typedef itk::VectorImage< unsigned short int, 3 >  
> DWIVectorImageType;
>   typedef itk::ImageFileReader< DWIVectorImageType >  
> DWIVectorImageReaderType;
>   typedef itk::MetaDataDictionary DictionaryType;
>
>   DWIVectorImageReaderType::Pointer dwireaderPtr =
>     DWIVectorImageReaderType::New();
>   dwireaderPtr->SetFileName("namic01-dwi_compressed.nhdr");
>   dwireaderPtr->Update();
>
>   DWIVectorImageType::Pointer dwiVectorImage = dwireaderPtr- 
> >GetOutput();
>   std::cout << dwiVectorImage << std::endl;
>   DWIVectorImageType::IndexType index = {{ 134, 112, 11 }};
>   DWIVectorImageType::PointType point;
>   dwiVectorImage->TransformIndexToPhysicalPoint(index, point);
>   std::cout << index << " => " << point << std::endl;
>   std::cout << index << ": " << dwiVectorImage->GetPixel(index) <<  
> std::endl;
> }
> </code>
>
> The output of this program is:
>
> <screen>
> VectorImage (0x80fd920)
>   RTTI typeinfo:   itk::VectorImage<unsigned short, 3u>
>   Reference Count: 3
>   Modified Time: 130
>   Debug: Off
>   Observers:
>     none
>   Source: (0x80fb228)
>   Source output index: 0
>   Release Data: Off
>   Data Released: False
>   Global Release Data: Off
>   PipelineMTime: 10
>   UpdateMTime: 131
>   LargestPossibleRegion:
>     Dimension: 3
>     Index: [0, 0, 0]
>     Size: [256, 256, 36]
>   BufferedRegion:
>     Dimension: 3
>     Index: [0, 0, 0]
>     Size: [256, 256, 36]
>   RequestedRegion:
>     Dimension: 3
>     Index: [0, 0, 0]
>     Size: [256, 256, 36]
>   Spacing: [0.9375, 0.9375, 3]
>   Origin: [-125, -124.1, 79.3]
>   Direction:
> 1 0 0
> 0 1 0
> 0 0 -1
>
>   VectorLength: 14
>   PixelContainer:
>     ImportImageContainer (0x80fda50)
>       RTTI typeinfo:   itk::ImportImageContainer<unsigned long,  
> unsigned
> short>
>       Reference Count: 1
>       Modified Time: 128
>       Debug: Off
>       Observers:
>         none
>       Pointer: 0xb2dc7008
>       Container manages memory: true
>       Size: 33030144
>       Capacity: 33030144
>
> [134, 112, 11] => [0.625, -19.1, 112.3]
> [134, 112, 11]: [333, 315, 159, 224, 204, 259, 135, 93, 252, 269,  
> 194, 145,
> 247, 162]
> </screen>
>
> Let's forget the "TransformIndexToPhysicalPoint does not use  
> direction"
> problem. But origin and spacing are both wrong, so I can't even  
> calculate
> the world coodinates by myself. My object is translated to the  
> wrong place
> and besides that in the wrong space. After applying direction it  
> would be
> in LPS space, but it should be RAS space.
>
> Is this a bug ? How can I load the NRRD file correctly into an
> itk::VectorImage ?
>
> Thanks in advance,
> Daniel Betz
> _______________________________________________
> Insight-users mailing list
> Insight-users at itk.org
> http://www.itk.org/mailman/listinfo/insight-users



More information about the Insight-users mailing list