Main Content

worldToIntrinsic

Map points from patient coordinates to intrinsic coordinates

Since R2022b

Description

[I,J,K] = worldToIntrinsic(R,X,Y,Z) maps points from the patient coordinate system to the intrinsic coordinate system using the spatial referencing information, R. The intrinsic coordinates I, J, and K are defined by axes aligned with the row, column, and slice subscripts of the image data array, respectively. The patient coordinates X, Y, and Z are defined by the real-world patient coordinate system axes.

For a point, n, if the input coordinates (Xn, Yn, Zn) fall outside the image bounds, worldToIntrinsic extrapolates In, Jn, and Kn outside the image bounds in the intrinsic coordinate system.

example

Examples

collapse all

Map 3-D patient coordinates from a chest CT volume, saved as a directory of DICOM files, to intrinsic coordinates. The volume is part of a data set containing three CT volumes. The size of the entire data set is approximately 81 MB. Download the data set from the MathWorks® website, then unzip the folder.

zipFile = matlab.internal.examples.downloadSupportFile("medical","MedicalVolumeDICOMData.zip");
filepath = fileparts(zipFile);
unzip(zipFile,filepath)

Specify the directory of the DICOM files for the first CT volume in the data set.

dataFolder = fullfile(filepath,"MedicalVolumeDICOMData","LungCT01"); 

Create a medical volume object that contains the image and spatial metadata for the CT volume.

medVol = medicalVolume(dataFolder);

The VolumeGeometry property of the medical volume object contains a medicalref3d object that specifies the spatial referencing for the volume. Extract the medicalref3d object for the chest CT.

R = medVol.VolumeGeometry;

Select three sample points, and store their (x, y, z) patient coordinates, in millimeters. For example, the first point has patient coordinates of (100, 101, –200), in mm. The third point is outside the image boundary.

X = [100 100 190];
Y = [101 101.2 -190];
Z = [-200 -100 -300];

Convert the world coordinates to intrinsic coordinates. The worldToIntrinsic function extrapolates the intrinsic coordinates of the third point outside the image boundary. The output vectors provide the (i, j, k) intrinsic coordinates, in voxels. Note that the intrinsic coordinate system is continuous, and the intrinsic coordinates can have noninteger values.

If you receive a warning that an approximate mapping is being used, then the image volume is nearly but not perfectly affine. This might be due to small numeric precision errors in how the data was encoded in the file, or due to the discrete step sizes of motors used to move the patient through the scanner. If an approximate mapping is used, you might expect small errors, on the order of millimeters in patient coordinates.

[I,J,K] = worldToIntrinsic(R,X,Y,Z)
Warning: An approximate world to intrinsic mapping is being used.
I = 1×3

  394.2652  394.2652  517.8040

J = 1×3

  395.6379  395.9124   -3.8043

K = 1×3

  154.0894  342.5072  -34.3283

Input Arguments

collapse all

Spatial referencing information, specified as a medicalref3d object.

Coordinates along the x-dimension in the patient coordinate system, specified as a numeric array.

X, Y, and Z must be the same size.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Coordinates along the y-dimension in the patient coordinate system, specified as a numeric array.

X, Y, and Z must be the same size.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Coordinates along the z-dimension in the patient coordinate system, specified as a numeric array.

X, Y, and Z must be the same size.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Output Arguments

collapse all

Coordinates along the i-dimension in the intrinsic coordinate system, returned as a numeric array. The i-axis is aligned with the first dimension of the spatial volume specified by R. I is the same size as X.

Data Types: double

Coordinates along the j-dimension in the intrinsic coordinate system, returned as a numeric array. The j-axis is aligned with the second dimension of the spatial volume specified by R. J is the same size as X.

Data Types: double

Coordinates along the k-dimension in the intrinsic coordinate system, returned as a numeric array. The k-axis is aligned with third dimension of the spatial volume specified by R. K is the same size as X.

Data Types: double

Version History

Introduced in R2022b