imresize
Resizes an image by a scale factor or to a given size.
Category: Graphics > Images
Syntax
B = imresize(A, scale)
Scales both dimensions by scale.
B = imresize(A, [numrows numcols])
Resizes to the exact size; use NaN for one entry to keep the aspect ratio.
B = imresize(___, method)
Chooses the interpolation: 'nearest', 'bilinear' or 'bicubic' (the default).
Description
'nearest' copies the closest pixel and keeps exact values, which suits label images and masks. 'bilinear' and 'bicubic' blend neighboring pixels and give smooth results for photographs. Because new values are computed, results are clamped to the range of integer classes.
Input arguments
A- Grayscale, RGB or binary image.
scale- Positive factor; values below 1 shrink the image.
method- Interpolation method name.
Output arguments
B- Resized image of the same class as
A. Sizes are rounded up to whole pixels.
Example
Shrink and enlarge
A = magic(4);
imresize(A, [2 2], 'nearest')
size(imresize(ones(10, 20), 0.5))
size(imresize(ones(10, 20), [5 NaN]))
imresize([1 2; 3 4], 2, 'nearest')
Output
ans = 2×2
11 8
14 1
ans = 1×2
5 10
ans = 1×2
5 10
ans = 4×4
1 1 2 2
1 1 2 2
3 3 4 4
3 3 4 4