Coordinate Systems
The imfusion
package refers to different coordinate systems when dealing with images (imfusion.Image
, imfusion.SharedImage
and imfusion.SharedImageSet
).
This page provides an overview on the different coordinate systems and available conversions between them.
Generally, there are three right-handed coordinate systems for images.
![_images/CoordinateSystemHierarchy.png](_images/CoordinateSystemHierarchy.png)
Image coordinate system hierarchy
The image API provides different interfaces and helper functions for converting between the three main coordinate systems.
Pixel and Image coordinates are handled by the base imfusion.Image
interface.
The transformation to convert from and to world coordinates is only part of the imfusion.SharedImage
interface.
![_images/CoordinateSystemCodeRelationship_Python.png](_images/CoordinateSystemCodeRelationship_Python.png)
Conversion between coordinate systems and the corresponding class interfaces
Pixel Coordinates
The pixel coordinate system maps directly to the pixels of an image. One unit corresponds to one pixel in the image. In general, the framework supports both OpenCV and OpenGL conventions where the zero pixel is located. By default (OpenCV-style), the (0, 0) pixel is in the upper left corner. This is the case for most common formats (PNG, MHD, Dicom) as well as all ultrasound or X-ray images. However, for specific applications, images with pixel data stored with respect to the bottom left corner can also be found.
![_images/PixelCoordinates.png](_images/PixelCoordinates.png)
Pixel Coordinates for an image of 5x4 pixels (top-down convention)
Data Coordinates (Image Coordinates)
The data coordinate system is the local coordinate system of every data element and uses millimeter as unit.
For images, where the term image coordinate system is also commonly used, the origin of this coordinate system is always placed in the center of the image.
A centered origin also improves the numerical stability in the context of many optimization problems, including image registration.
Pixel coordinates can be converted to image coordinates and back by using the imfusion.Image.pixel_to_image()
and imfusion.Image.image_to_pixel()
methods. The conversion between pixels and millimeters depends on the imfusion.Image.spacing
attribute. The spacing defines the space in millimeter between two pixels.
![_images/ImageCoordinates.png](_images/ImageCoordinates.png)
Image Coordinates of the previous image with a horizontal spacing of 0.2mm and a vertical one of 0.1mm
World Coordinates
Finally, there is the world coordinate system.
World coordinates are also defined in millimeters but the origin is the same for all data.
The world transformation is mainly relevant for 3D data because most 2D images won’t have a transformation matrix.
For images, direct conversions to pixel space are available in the form of imfusion.SharedImage.world_to_pixel()
and imfusion.SharedImage.pixel_to_world()
methods.
Besides, imfusion.SharedImage.world_to_image_matrix
is the matrix that transforms world coordinates to image coordinates.
The renderers/views employ a right-handed coordinate system with the following conventions wrt. patient space:
X: right to left (patient).
Y: front to back.
Z: feet to head.