Locked History Attachments

ChangeRequests/4692

1. MITK coordinates were not consistently center-based (ITK and DICOM are center-based)

1.1. Actual behavior

Since Oct 2009, the idea in MITK was to use center-based world-coordinates and edge-/corner-based index coordinates.

1.2. Expected behavior

Index and world-coordinates should both be center-based to match the behavior in ITK and the definition in DICOM.

A test should check that ITK is really center-based.

2. Cause of the bug

MITK index coordinates are continuous (float/double) by default. Obviously, to actually access a pixel/voxel in the data array of an image, an integer index is needed. The conversion between the continuous index coordinates and the integer index was done by truncation at some places. To get the correct result, 0.5 was always added to the continuous index - which results in correct results when a truncation to an integer is done afterwards, but makes the coordinate system inconsistent when used as it is.

BTW: ITK used inconsistent world/index-coordinates until rev. 3.16.

3. Proposed solution

The solution is to consistently use center-based coordinates in the index and world-coordinate system. Rounding (instead of truncation) is needed to convert to integer indices.

There are (already) to versions of the methods to convert from world to index coodinates:

  • mitk::Geometry3D::WorldToIndex(const mitk::Point3D& pt_mm, mitk::Point3D& pt_units): this produces continuous index coordinates. Maybe mitk::ContinuousIndex3D should be used as data type for pt_units in the future, but this will cause a lot of legacy problems.

  • mitk::Geometry3D::WorldToIndex(const mitk::Point3D& pt_mm, itk::Index< VIndexDimension > &index): this produces integer indices (by rounding!) and should be used whenever integer are needed, e.g., in case that a voxel needs to be accessed via a data array.

Additionally, since ITK does support rotated coordinate systems since rev. 3.10 the methods mitk::Geometry3D::WorldToItkPhysicalPoint and mitk::Geometry3D::ItkPhysicalPointToWorld are deprecated and - until removal - should apply the complete transformation to deliver correct itk-physical-points.

4. Affected classes

  • mitk::Geometry3D
  • mitk::PlaneGeometry

The following classes access voxels via continuous indices and/or incorrect trunctation:

  • mitk::SliceNavigationController

  • mitk::Image::GetPixelValueByWorldCoordinate

  • mitk::Image::GetPixelValueByIndex

  • mitk::BoundingObject::FitGeometry

  • QmitkVtkLineProfileWidget

5. How will the bugfix get tested?

  • mitkGeometry3DTest checks that ITK is center-based and that mitk::Geometry3D consistently uses center-based coordinates.
  • mitkImageTest tests the pixel access methods of mitk::Image and consistency between them and itk::Image-based access.