contains

Determine if image contains points in world coordinate system

Description

example

TF = contains(R,xWorld,yWorld) returns a logical array TF. Each element 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 object R.

example

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

Examples

collapse all

Read a 2-D image into the workspace.

I = imread('cameraman.tif');

Create an imref2d spatial 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 array

   1   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 the XWorldLimits and YWorldLimits properties of the spatial referencing object R.

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

load mri;
D = squeeze(D);

Create an imref3d spatial 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 array

   1   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 the XWorldLimits, YWorldLimits, and ZWorldLimits properties of the spatial referencing object R.

Input Arguments

collapse all

Spatial referencing object, specified as an imref2d or imref3d object. R is associated with an image.

Coordinates along the x-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 the y-dimension in the world coordinate system, specified as a numeric scalar or vector. yWorld is the same length as xWorld.

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

Coordinates along the z-dimension in the world coordinate system, specified as a numeric scalar or vector. zWorld is the same length as xWorld and yWorld.

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 is the same length as the input coordinate vectors xWorld, yWorld, and (when relevant) zWorld.

Data Types: logical

See Also

|

Introduced in R2013a