sizesMatch
Determine if object and image are size-compatible
Syntax
Description
Examples
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.
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
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
Output Arguments
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.
选择网站
选择网站以获取翻译的可用内容,以及查看当地活动和优惠。根据您的位置,我们建议您选择:。
您也可以从以下列表中选择网站:
如何获得最佳网站性能
选择中国网站(中文或英文)以获得最佳网站性能。其他 MathWorks 国家/地区网站并未针对您所在位置的访问进行优化。
美洲
- América Latina (Español)
- Canada (English)
- United States (English)
欧洲
- 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)