contains
Determine if image contains points in world coordinate system
Description
Examples
Check If Coordinates Fall Within 2-D Image Bounds
Read a 2-D image into the workspace.
I = imread('cameraman.tif');
Create animref2d
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 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 theXWorldLimits
andYWorldLimits
properties of the spatial referencing objectR
。
Check If Coordinates Fall Within 3-D Image Bounds
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 animref3d
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 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
, andZWorldLimits
properties of the spatial referencing objectR
。
Input Arguments
xWorld
—Coordinates along thex-dimension in the world coordinate system
numeric scalar or vector
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
yWorld
—Coordinates along they-dimension in the world coordinate system
numeric scalar or vector
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
zWorld
—Coordinates along thez-dimension in the world coordinate system
numeric scalar or vector
Output Arguments
TF
— Flag indicating whether coordinates exist within the bounds of the image
logical scalar or vector
Version History
Open Example
You have a modified version of this example. Do you want to open this example with your edits?
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(德语)
- España(Español)
- Finland(English)
- France(Français)
- Ireland(English)
- Italia(Italiano)
- Luxembourg(English)
- Netherlands(English)
- Norway(English)
- Österreich(德语)
- Portugal(English)
- Sweden(English)
- Switzerland
- United Kingdom(English)