You are here : matlabImage Processingimresize

imresize() - Image Processing

B = imresize(A,scale) returns
image B that is scale times
the size of A. The input image A can
be a grayscale, RGB, or binary image. If scale is
from 0 through 1.0, B is smaller than A.
If scale is greater than 1.0, B is
larger than A. By default, imresize uses
bicubic interpolation.exampleB = imresize(A,outputSize) returns
image B that has the number of rows and columns
specified by outputSize, a two-element vector of
the form [numrows numcols]. example[Y,newmap]
= imresize(X,map,___) resizes
the indexed image X where map is
the colormap associated with the image. By default, imresize returns
a new, optimized colormap (newmap) with the resized
image. To return a colormap that is the same as the original colormap,
use the 'Colormap' parameter. example___ = imresize(___,method) specifies
the interpolation method used. ___ = imresize(___,Name,Value,...) you
can control various aspects of the resizing operation by specifying
parameter/value pairs with any of the previous syntaxes.examplegpuarrayB = imresize(gpuarrayA,scale) performs
the resize operation on a GPU. The input image and the output image
are gpuArrays. When used with gpuArrays, imresize only
supports cubic interpolation and always performs antialiasing. For
cubic interpolation, the output image might have some values slightly
outside the range of pixel values in the input image. This syntax
requires the Parallel Computing Toolbox™.Code Generation support:
YesMATLAB Function Block support:
Yes


Syntax

B = imresize(A,scale) exampleB = imresize(A,outputSize) example[Y,newmap]
= imresize(X,map,___) example___ = imresize(___,method) example___ = imresize(___,Name,Value,...)gpuarrayB = imresize(gpuarrayA,scale) example


Example

Resize Image Specifying Scale FactorOpen This Example
Read image into the workspace.I = imread('rice.png');
Resize the image, specifying scale factor and using default interpolation method and antialiasing.J = imresize(I, 0.5);
Display the original and the resized image.figure
imshow(I)
title('Original Image')
figure
imshow(J)
title('Resized Image')


Resize Image on GPURead image into the workspace in a gpuArray.I = im2double(gpuArray(imread('rice.png')));
Resize the image, performing the operation on a GPU.J = imresize(I, 0.5);
Display the original image and the resized image.figure
imshow(I)
title('Original')
figure
imshow(J)
title('Resized Image')Resize Image Specifying Scale Factor and Interpolation MethodOpen This Example
Read image into the workspace.I = imread('rice.png');
Resize the image, specifying scale factor and the interpolation method.J = imresize(I, 0.5, 'nearest');
Display the original and the resized image.figure
imshow(I)
title('Original Image')
figure
imshow(J)
title('Resized Image Using Nearest-Neighbor')


Resize Indexed ImageOpen This Example
Read image into the workspace.[X, map] = imread('trees.tif');
Resize the image, specifying a scale factor. By default, imresize returns an optimized color map with the resized indexed image.[Y, newmap] = imresize(X, map, 0.5);
Display the original image and the resized image.figure
imshow(X,map)
title('Original Image')
figure
imshow(Y,newmap)
title('Resized Image')


Resize RGB Image Specifying Size of Output ImageOpen This Example
Read image into the workspace.RGB = imread('peppers.png');
Resize the image, specifying that the output image have 64 rows. Let imresize calculate the number of columns necessary to preserve the aspect ratio.RGB2 = imresize(RGB, [64 NaN]);
Display the original image and the resized image.figure
imshow(RGB)
title('Original Image')
figure
imshow(RGB2)
title('Resized Image')


Resize RGB Image on GPURead image into the workspace in a gpuArray.RGB = gpuArray(im2single(imread('peppers.png')));Resize the image, performing the operation on a GPU.RGB2 = imresize(RGB, 0.5);
Display the original image and the resized image.figure
imshow(RGB)
title('Original')
figure
imshow(RGB2)
title('Resized Image')


Output / Return Value


Limitations


Alternatives / See Also


Reference