sizesMatch
Determine if object and image are size-compatible
Syntax
Description
Examples
Check If 2-D Grayscale Image and 2-D Spatial Referencing Object Are Size-Compatible
Read a 2-D grayscale image into the workspace. View the size of the image.
I = imread('cameraman.tif');
size(I)
ans = 1×2
256 256
Create an imref2d
spatial referencing object with the same dimensions as 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]
Confirm that the size of the image matches the ImageSize
property of the object.
res = sizesMatch(R,I)
res = logical
1
Read another 2-D grayscale image that has a different size. View the size of this image.
I2 = imread('coins.png');
size(I2)
ans = 1×2
246 300
Check if the size of this image matches the size of the original spatial referencing object.
res2 = sizesMatch(R,I2)
res2 = logical
0
The result is false, as expected.
Check If 2-D RGB Image and 2-D Spatial Referencing Object Are Size-Compatible
Read an RGB image into the workspace. View the size of the image.
I = imread('peppers.png');
size(I)
ans = 1×3
384 512 3
Create an imref2d
spatial referencing object with the same dimensions as the image. The object does not retain information about the third dimension of the image array.
R = imref2d(size(I))
R = imref2d with properties: XWorldLimits: [0.5000 512.5000] YWorldLimits: [0.5000 384.5000] ImageSize: [384 512] PixelExtentInWorldX: 1 PixelExtentInWorldY: 1 ImageExtentInWorldX: 512 ImageExtentInWorldY: 384 XIntrinsicLimits: [0.5000 512.5000] YIntrinsicLimits: [0.5000 384.5000]
Check if the size of the image is compatible with the ImageSize
property of the object.
res = sizesMatch(R,I)
res = logical
1
Check If 3-D Image Array and 3-D Spatial Referencing Object Are Size-Compatible
Read a 3-D volume into the workspace. This image consists of 27 frames of 128-by-128 pixel grayscale images.
load mri;
D = squeeze(D);
D = ind2gray(D,map);
size(D)
ans = 1×3
128 128 27
Create an imref3d
spatial referencing object associated with the volume.
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]
Confirm that the size of the volume matches the ImageSize
property of the object.
res = sizesMatch(R,D)
res = logical
1
The sizes match, as expected.
Read another image that has a different size. This image a 3-D array representing an RGB image.
I = imread('peppers.png');
size(I)
ans = 1×3
384 512 3
Check if the size of this image matches the size of the original spatial referencing object.
res2 = sizesMatch(R,I)
res2 = logical
0
The result is false, as expected.
Input Arguments
A
— Input image
numeric m-by-n or
m-by-n-by-p
array
Input image, specified as a numeric m-by-n or m-by-n-by-p array.
Data Types: single
| double
| int8
| int16
| int32
| int64
| uint8
| uint16
| uint32
| uint64
| logical
Output Arguments
TF
— Flag indicating size compatibility
logical scalar
Flag indicating size compatibility, returned as a logical scalar.
TF
is True
if the size of the
image A
is consistent with the referencing object
R
. When R
is:
An
imref2d
spatial referencing object,TF
returns true whenR.ImageSize == [size(A,1) size(A,2)]
.Note
The dimensionality of
A
does not need to match the dimensionality of animref2d
spatial referencing object. For example, an RGB image can be consistent with animref2d
object. In this case,sizesMatch
ignores the third image dimension.An
imref3d
spatial referencing object,TF
returns true whenR.ImageSize == size(A)
.A
must be a 3-D array.
Data Types: logical
Version History
Introduced in R2013a
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 (한국어)