Documentation

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.

imresize

Syntax

B = imresize(A,scale)
B = imresize(A,[numrows numcols])
[Y,newmap] = imresize(X,map,___)
___ = imresize(___,method)
___ = imresize(___,Name,Value)
gpuarrayB = imresize(gpuarrayA,scale)
gpuarrayB = imresize(gpuarrayA,[numrows numcols])

Description

example

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 A has more than two dimensions, imresize only resizes the first two dimensions. 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.

example

B = imresize(A,[numrows numcols]) returns image B that has the number of rows and columns specified by the two-element vector [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) returns the resized image where Name,Value pairs control various aspects of the resizing operation.

example

gpuarrayB = 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™.

example

gpuarrayB = imresize(gpuarrayA,[numrows numcols]) performs the resize operation on a GPU, where [numrows numcols] specifies the size of the output image.

Examples

collapse all

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')

Read 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')

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')

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')

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')

Read 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')

Input Arguments

collapse all

Image to be resized, specified as a real, nonsparse numeric array.

Data Types: single | double | int8 | int16 | int32 | uint8 | uint16 | uint32 | logical

Resize factor, specified as a real, numeric scalar.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Row and column dimensions of output image, specified as a two-element numeric vector of positive values. Either numrows or numcols can be NaN, in which case imresize computes the number of rows or columns automatically to preserve the image aspect ratio.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Indexed image to be resized, specified as a real, nonsparse numeric array.

Example: [X2, newmap] = imresize(X,map,0.75);

Data Types: double | uint8 | uint16

Colormap associated with indexed image, m-by-3 numeric array.

Data Types: double

Interpolation method, specified as a character vector or two-element cell array.

The character vector identifies a particular method or named interpolation kernel, listed in the following table.

MethodDescription

'nearest'

Nearest-neighbor interpolation; the output pixel is assigned the value of the pixel that the point falls within. No other pixels are considered.

'bilinear'

Bilinear interpolation; the output pixel value is a weighted average of pixels in the nearest 2-by-2 neighborhood

'bicubic'

Bicubic interpolation; the output pixel value is a weighted average of pixels in the nearest 4-by-4 neighborhood

    Note:   Bicubic interpolation can produce pixel values outside the original range.

Interpolation KernelDescription
'box'Box-shaped kernel
'triangle'Triangular kernel (equivalent to 'bilinear')
'cubic'Cubic kernel (equivalent to 'bicubic')
'lanczos2'Lanczos-2 kernel
'lanczos3'Lanczos-3 kernel

The a two-element cell array defines a customer interpolation kernel of the form {f,w}. In this cell array, f is a function handle for a custom interpolation kernel and w is the width of the custom kernel. f(x) must be zero outside the interval -w/2 <= x < w/2. The function handle f can be called with a scalar or a vector input. For user-specified interpolation kernels, the output image can have some values slightly outside the range of pixel values in the input image.

Data Types: char | cell

Image to be resized on a GPU, specified as a gpuArray.

Example: gpuarrayB = imresize(gpuarrayA,0.5);

Name-Value Pair Arguments

Specify optional comma-separated pairs of Name,Value arguments. Name is the argument name and Value is the corresponding value. Name must appear inside single quotes (' '). You can specify several name and value pair arguments in any order as Name1,Value1,...,NameN,ValueN.

Example: I2 = imresize(I,0.5,'Antialiasing',false);

collapse all

Perform antialiasing when shrinking an image, specified as the comma-separated pair consisting of 'Antialiasing' and the logical Boolean value true or false. The default value depends on the interpolation method. If the method is nearest-neighbor ('nearest'), the default is false. For all other interpolation methods, the default is true.

Data Types: logical

Return optimized colormap, specified as the comma-separated pair consisting of 'Colormap' and the character vector 'optimized' or 'original'. (Indexed images only). If set to 'original', the output colormap (newmap) is the same as the input colormap (map). If set to 'optimized', imresize returns a new optimized colormap.

Data Types: char

Perform color dithering, specified as the comma-separated pair consisting of 'Dither' and the logical Boolean value true or false. (Indexed images only).

In dithering, you apply a form of noise to the image to randomize quantization error and prevent large-scale patterns.

Data Types: logical

Interpolation method, specified as the comma-separated pair consisting of 'Method' and a character vector or two-element cell array. For details, see method.

Data Types: char | cell

Size of the output image, specified as the comma-separated pair consisting of 'OutputSize' and a two-element vector of the form [numrows numcols].

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Resize scale factor, specified as the comma-separated pair consisting of 'Scale' and a positive numeric scalar or two-element vector of positive values.

Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

Output Arguments

collapse all

Resized image, returned as a real, nonsparse numeric array, the same class as the input image.

Resized indexed image, returned as a real, nonsparse numeric array, the same class as the input image.

Optimized colormap, returned as an m-by-3 numeric array.

Resized image, returned as a gpuArray.

Tips

  • The function imresize changed in version 5.4 (R2007a). Previous versions of the Image Processing Toolbox™ used a different algorithm by default. If you need the same results produced by the previous implementation, use the function imresize_old.

  • There is a slight numerical difference between the results of imresize on the CPU and the GPU. These differences occur on the right and bottom borders of the image and barely noticeable to the naked eye.

  • If the size of the output image is not an integer, imresize does not use the scale specified. imresize uses ceil when calculating the output image size.

Extended Capabilities

Introduced before R2006a

Was this topic helpful?