worldToSubscript
Description
[
maps points from the patient coordinate system to the nearest subscript indices
row
,col
,slice
] = worldToSubscript(R
,X
,Y
,Z
)row
, col
, and slice
, using
the spatial referencing information, R
.
For a point, n, if the input coordinates
(X
n,
Y
n,
Z
n) fall outside the image bounds,
worldToSubscript
extrapolates
row
n,
col
n, and
slice
n outside the image bounds in the
intrinsic coordinate system and rounds to the nearest integer values.
Examples
Map 3-D Patient Coordinates to Image Subscripts
Map 3-D patient coordinates from a chest CT volume, saved as a directory of DICOM files, to image subscripts. 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 row, column, and slice indices. The worldToSubscript
function rounds the transformed world coordinates to integer values. The function extrapolates the subscripts of the point outside the image boundary.
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.
[row,col,slice] = worldToSubscript(R,X,Y,Z)
Warning: An approximate world to intrinsic mapping is being used.
row = 1×3
394 394 518
col = 1×3
396 396 -4
slice = 1×3
154 343 -34
Input Arguments
R
— Spatial referencing information
medicalref3d
object
Spatial referencing information, specified as a medicalref3d
object.
X
— Coordinates along x-dimension in patient coordinate system
numeric array
Y
— Coordinates along y-dimension in patient coordinate system
numeric array
Z
— Coordinates along z-dimension in patient coordinate system
numeric array
Output Arguments
row
— Row subscript indices
positive integer array
Row subscript indices, returned as a positive integer array.
row
is the same size as X
.
Data Types: double
col
— Column subscript indices
positive integer array
Column subscript indices, returned as a positive integer array.
col
is the same size as X
.
Data Types: double
slice
— Slice subscript indices
positive integer array
Slice subscript indices, returned as a positive integer array.
slice
is the same size as X
.
Data Types: double
Version History
Introduced in R2022b
See Also
MATLAB Command
You clicked a link that corresponds to this MATLAB command:
Run the command by entering it in the MATLAB Command Window. Web browsers do not support MATLAB commands.
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select: .
You can also select a web site from the following list
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- América Latina (Español)
- Canada (English)
- United States (English)
Europe
- Belgium (English)
- Denmark (English)
- Deutschland (Deutsch)
- España (Español)
- Finland (English)
- France (Français)
- Ireland (English)
- Italia (Italiano)
- Luxembourg (English)
- Netherlands (English)
- Norway (English)
- Österreich (Deutsch)
- Portugal (English)
- Sweden (English)
- Switzerland
- United Kingdom (English)
Asia Pacific
- Australia (English)
- India (English)
- New Zealand (English)
- 中国
- 日本Japanese (日本語)
- 한국Korean (한국어)