contains

Determine if affine image volume contains points specified in patient coordinate system

Since R2022b

Description

example

tf = contains(R,xyzWorld) returns a logical vector, tf, that indicates whether each of the specified 3-D coordinates points xyzWorld falls within the bounds of the affine medical image volume defined by R.

Examples

collapse all

Determine if a chest CT volume, saved as a directory of DICOM files, contains a set of coordinates specified in the patient coordinate system. 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.

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;

Specify the patient coordinates, in millimeters, of three sample points.

xyzWorld = [-100 -100 -200; 0 0 -100; 300 200 -80]
xyzWorld = 3×3

-100  -100  -200
0     0  -100
300   200   -80

Check whether the sample points are inside the image boundary. The values of tf indicate that the third point lies outside the image.

tf = contains(R,xyzWorld)
tf = 3×1 logical array

1
1
0

Input Arguments

collapse all

Spatial referencing information, specified as a medicalref3d object. R must specify an affine image volume. An image volume is affine if these conditions are met:

• All slices are parallel to each other.

• The spacing between slices in each dimension is uniform.

• The upper-left voxels of all slices are collinear.

• No two slices are coincident, meaning no two slices are located at the same position in space.

Patient coordinates of points to query, specified as an n-by-3 numeric matrix, where n is the number of points. The patient coordinates are in real-world units defined by the patient coordinate system.

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

Output Arguments

collapse all

Image volume contains the specified points, returned as an n-element logical vector, where n is the number of points. A value of 1 (true) indicates that the corresponding xyzWorld point exists in the image volume, and a value of 0 (false) indicates that it does not.

Version History

Introduced in R2022b