MantisBT - ITK
View Issue Details
0008470ITKpublic2009-02-04 16:272010-11-13 13:01
Ivan Macia 
Mathieu Malaterre 
normalmajoralways
closedfixed 
ITK-3-10 
ITK-3-12 
backlog
0008470: Trying to load 2D images in coronal or sagittal orientation always throws exception in ITK-3.10.1
Posted here, no answer :(
http://www.itk.org/mailman/private/insight-developers/2009-January/011575.html [^]

Since version 3.10.1 (and probably 3.10) I am unable to load a single slice
from a 3D coronal or sagittal volume (we do this for previewing or loading,
without actually loading the whole volume). ImageBase
::ComputeIndexToPhysicalPointMatrices() complains that the determinant is
zero.

This is quite critical because we cannot make our software work with
ITK-3.10 and above without changing this code. Either our exception handling
or Qt's is always catching this exception and we cannot continue with the
loading.
This seems to be related to the fact that for a 2D image, m_Direction is 2x2
where it should be 3x3. It seems that previous versions didn't throw an
exception so they were working anyway.

Having a deeper look, I try to load an image where ImageIO (GDCMImageIO)
reads the following for the direction:

0.252 0.968 0.0
0.0 0.0 -1.0
-0.0968 0.252 0.0

However, when converting from the direction stored in ImageIO to
ImageBase::m_Direction (see ImageFileReader::GenerateOutputInformation() )
the resulting matrix is

0.252 0.968
0.0 0.0

For this, the present code in
ImageBase::ComputeIndexToPhysicalPointMatrices() and
Image::ComputeIndexToPhysicalPointMatrices() throws an exception because the
determinant is zero

 if (vnl_determinant(this->m_Direction.GetVnlMatrix()) == 0.0)
    {
    itkExceptionMacro(<< "Bad direction, determinant is 0. Direction is " <<
this->m_Direction);
    }

I have seen a discussion about this in Mantis issue [0005573]:
"Image::DirectionType should be Nx3 rather than NxN", however the discussion
was centered on 4D images. IMHO, leaving the 4D world apart, a single slice
of a volume lies in a 3D world so m_Direction should be 3x3.
No tags attached.
Issue History
2009-02-04 16:27Ivan MaciaNew Issue
2009-02-21 08:56Bradley LowekampAssigned To => Bradley Lowekamp
2009-02-21 08:56Bradley LowekampStatusnew => assigned
2009-02-21 08:58Bradley LowekampNote Added: 0015282
2009-02-21 08:58Bradley LowekampStatusassigned => confirmed
2009-02-21 09:21Bradley LowekampNote Added: 0015283
2009-02-23 11:54Bradley LowekampStatusconfirmed => assigned
2009-02-23 11:54Bradley LowekampAssigned ToBradley Lowekamp => Luis Ibanez
2009-03-01 13:44Luis IbanezNote Added: 0015473
2009-03-01 13:45Luis IbanezNote Added: 0015474
2009-03-01 13:45Luis IbanezStatusassigned => closed
2009-03-01 13:45Luis IbanezResolutionopen => fixed
2009-03-01 13:45Luis IbanezFixed in Version => ITK-3-12
2009-03-25 09:05Hans JohnsonNote Added: 0015797
2009-03-25 09:05Hans JohnsonStatusclosed => feedback
2009-03-25 09:05Hans JohnsonResolutionfixed => reopened
2010-10-26 05:56Mathieu MalaterreStatusfeedback => assigned
2010-10-26 05:56Mathieu MalaterreAssigned ToLuis Ibanez => Mathieu Malaterre
2010-11-09 17:56Mathieu MalaterreNote Added: 0023114
2010-11-09 17:57Mathieu MalaterreSprint Status => backlog
2010-11-09 17:57Mathieu MalaterreStatusassigned => closed
2010-11-09 17:57Mathieu MalaterreResolutionreopened => fixed
2010-11-13 13:00Mathieu MalaterreStatusclosed => feedback
2010-11-13 13:00Mathieu MalaterreResolutionfixed => reopened
2010-11-13 13:01Mathieu MalaterreStatusfeedback => closed
2010-11-13 13:01Mathieu MalaterreResolutionreopened => fixed

Notes
(0015282)
Bradley Lowekamp   
2009-02-21 08:58   
I was able to reproduce the bug with the following:


Can anyone please try to reproduce this error? You can find 2 DICOM files, one sagittal, one coronal that fail here
http://www.yousendit.com/download/U0d3K3BKQk5tMEtGa1E9PQ [^]
(0015283)
Bradley Lowekamp   
2009-02-21 09:21   
This is the problematic code in ImageFileReader, it also should check the degenerate case when the det is 0:

// TODO: actually figure out what to do about dir cosines in 2d.
  // don't allow degenerate direction cosines
  // This is a pure punt; it will prevent the exception being
  // thrown, but doesn't do the right thing at all -- replacing e.g
  // [0, 0, -1] with [0, 1] doesn't make any real sense.
  // On the other hand, programs that depend on 2D Direction Cosines
  // are pretty much guaranteed to be disappointed if they expect anything
  // meaningful in the direction cosines anyway.
  if(TOutputImage::ImageDimension == 2)
    {
    if(direction[0][0] == 0.0 && direction[1][0] == 0)
      {
      if(direction[0][1] == 0.0)
        {
        direction[0][0] = 1.0;
        }
      if(direction[1][1] == 0.0)
        {
        direction[1][0] = 1.0;
        }
      }
    else if(direction[0][1] == 0.0 && direction[1][1] == 0)
      {
      if(direction[0][0] == 0.0)
        {
        direction[1][0] = 1.0;
        }
      if(direction[1][0] == 0.0)
        {
        direction[1][1] = 1.0;
        }
      }
    }
(0015473)
Luis Ibanez   
2009-03-01 13:44   
A fix has been committed (now included in ITK 3.12).

Two new methods were added to ImageIOBase,
and they were overloaded in itkAnalyzeImageIO.

http://www.itk.org/cgi-bin/viewcvs.cgi/Code/IO/itkImageIOBase.cxx?root=Insight&r1=1.82&r2=1.83 [^]
http://www.itk.org/cgi-bin/viewcvs.cgi/Code/IO/itkImageIOBase.h?root=Insight&r1=1.50&r2=1.51 [^]
http://www.itk.org/cgi-bin/viewcvs.cgi/Code/IO/itkAnalyzeImageIO.cxx?root=Insight&r1=1.93&r2=1.94 [^]
http://www.itk.org/cgi-bin/viewcvs.cgi/Code/IO/itkAnalyzeImageIO.h?root=Insight&r1=1.21&r2=1.22 [^]

These methods implement the preferred way of initializing direction cosines when the image instantiated in memory is of dimension lower than the image stored in the input file.
(0015474)
Luis Ibanez   
2009-03-01 13:45   
All tests passed in the Dashboard after this changes.

The fixes are included in ITK 3.12.
(0015797)
Hans Johnson   
2009-03-25 09:05   
The original bug fix caused failure for 3D images with direction cosigns of [1 0 0;0 0 -1; 0 1 0] which is a valid orientation for the analyze filter.

This was fixed with code submitted in
/cvsroot/Insight/Insight/Code/IO/itkAnalyzeImageIO.cxx,v <-- itkAnalyzeImageIO.cxx
new revision: 1.95; previous revision: 1.94
(0023114)
Mathieu Malaterre   
2010-11-09 17:56   
I believe this bug has been fixed.