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
imref2dspatial referencing object,TFreturns true whenR.ImageSize == [size(A,1) size(A,2)].Note
The dimensionality of
Adoes not need to match the dimensionality of animref2dspatial referencing object. For example, an RGB image can be consistent with animref2dobject. In this case,sizesMatchignores the third image dimension.An
imref3dspatial referencing object,TFreturns true whenR.ImageSize == size(A).Amust 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.
Sélectionner un site web
Choisissez un site web pour accéder au contenu traduit dans votre langue (lorsqu'il est disponible) et voir les événements et les offres locales. D’après votre position, nous vous recommandons de sélectionner la région suivante : .
Vous pouvez également sélectionner un site web dans la liste suivante :
Comment optimiser les performances du site
Pour optimiser les performances du site, sélectionnez la région Chine (en chinois ou en anglais). Les sites de MathWorks pour les autres pays ne sont pas optimisés pour les visites provenant de votre région.
Amériques
- 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)