Main Content

contains

Determine if image contains points in world coordinate system

Description

example

TF= contains(R,xWorld,yWorld)returns a logical arrayTF。每个元素TF(k) is true if and only if the corresponding point (xWorld(k),yWorld(k)) falls within the bounds of an image associated with 2-D spatial referencing objectR

example

TF= contains(R,xWorld,yWorld,zWorld)indicates whether each point falls within the bounds of an image associated with 3-D spatial referencing objectR

Examples

collapse all

Read a 2-D image into the workspace.

I = imread('cameraman.tif');

Create animref2dspatial referencing object associated with the image.

R = imref2d(size(I))
R = imref2d with properties: XWorldLimits: [0.5000 256.5000] YWorldLimits: [0.5000 256.5000] ImageSize: [256 256] PixelExtentInWorldX: 1 PixelExtentInWorldY: 1 ImageExtentInWorldX: 256 ImageExtentInWorldY: 256 XIntrinsicLimits: [0.5000 256.5000] YIntrinsicLimits: [0.5000 256.5000]

Check if certain world coordinates are in the image.

res = contains(R,[5 8 8],[5 10 257])
res =1x3 logical array1 1 0

This result indicates that the points (5,5) and (8,10) are within the image bounds, and that the point (8, 257) is outside the image bounds. This conclusion is consistent with theXWorldLimitsandYWorldLimitsproperties of the spatial referencing objectR

Read a 3-D image into the workspace. This image consists of 27 frames of 128-by-128 pixel images.

loadmri; D = squeeze(D);

Create animref3dspatial referencing object associated with the image.

R = imref3d(size(D))
R = imref3d with properties: XWorldLimits: [0.5000 128.5000] YWorldLimits: [0.5000 128.5000] ZWorldLimits: [0.5000 27.5000] ImageSize: [128 128 27] PixelExtentInWorldX: 1 PixelExtentInWorldY: 1 PixelExtentInWorldZ: 1 ImageExtentInWorldX: 128 ImageExtentInWorldY: 128 ImageExtentInWorldZ: 27 XIntrinsicLimits: [0.5000 128.5000] YIntrinsicLimits: [0.5000 128.5000] ZIntrinsicLimits: [0.5000 27.5000]

Check if certain 3-D world coordinates are in the image.

res = contains(R,[5 6 6 8],[5 10 10 257],[1 27.5 28 1])
res =1x4 logical array1 1 0 0

This result indicates that the points (5,5,1) and (6,10,27.5) are within the image bounds. The points (6,10,28) and (8,257,1) are outside the image bounds. This conclusion is consistent with theXWorldLimits,YWorldLimits, andZWorldLimitsproperties of the spatial referencing objectR

Input Arguments

collapse all

空间引用对象, specified as animref2dorimref3dobject.Ris associated with an image.

Coordinates along thex-dimension in the world coordinate system, specified as a numeric scalar or vector.

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

Coordinates along they-dimension in the world coordinate system, specified as a numeric scalar or vector.yWorld是一样的长度xWorld

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

Coordinates along thez-dimension in the world coordinate system, specified as a numeric scalar or vector.zWorld是一样的长度xWorldandyWorld

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

Output Arguments

collapse all

Flag indicating whether coordinates exist within the bounds of the image, returned as a logical scalar or vector.TF是一样的长度the input coordinate vectorsxWorld,yWorld, and (when relevant)zWorld

Data Types:logical

Version History

Introduced in R2013a

See Also

|