matlab:imresize函数

imresize

Resize image

collapse all in page

Syntax

  • B = imresize(A,scale)

    example
  • B = imresize(A,outputSize)

    example
  • [Y,newmap] = imresize(X,map,___)

    example
  • ___ = imresize(___,method)

    example
  • ___ = imresize(___,Name,Value,...)

  • gpuarrayB = imresize(gpuarrayA,scale)

    example

Description

example

B = imresize(A,scale) 缩放图像A 至scale倍。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.

example

B = 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.

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

Code Generation support: Yes

MATLAB Function Block support: Yes

Examples

collapse all

Resize Image Specifying Scale Factor

Open 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 GPU

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

Resize Image Specifying Scale Factor and Interpolation Method

Open 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 Image

Open 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 Image

Open 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 GPU

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

A — Image to be resizedreal, nonsparse numeric or logical array

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

Example: I2 = imresize(I,0.5);

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

scale — Resize factorreal, numeric scalar

Resize factor, specified as a real, numeric scalar.

Example: I2 = imresize(I,0.5);

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

outputSize — Row and column dimensions of output imagetwo-element numeric vector

Row and column dimensions of output image, specified as a two-element vector of the form [numrows numcols]. 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.

Example: I2 = imresize(I,[50 NaN]);

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

X — Indexed image to be resizedreal, nonsparse numeric array

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

map — Colormap associated with indexed imagem-by-3 numeric array

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

Example:

Data Types: double

method — Interpolation method'bicubic' (default) | string | two-element cell array

Interpolation method, specified as a string that identifies a general method or a named interpolation kernel, listed in the following table. Method can also be a two-element cell array, of the form {f,w}, that specifies a custom interpolation kernel. 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.

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 default); the output pixel value is a weighted average of pixels in the nearest 4-by-4 neighborhood

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

 

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

Data Types: char | cell

gpuarrayA — Image to be resized on a GPUgpuArray

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

'Antialiasing' — Perform antialiasing when shrinking an imagetrue | false

Perform antialiasing when shrinking an image, specified as 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.

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

Data Types: logical

'Colormap' — Return optimized colormap'optimized' (default) | 'original'

Return optimized colormap, specified as the string '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.

Example: [X2, map2] = imresize(X,map,0.75,'Colormap','original');

Data Types: char

'Dither' — Perform color ditheringtrue (default) | false

Perform color dithering, specified as the logical Boolean value true or false. (Indexed images only).

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

Data Types: logical

'Method' — Interpolation method'bicubic' (default) | string | cell array

Interpolation method, specified as a text string or two-element cell array. For details, see method.

Example: I2 = imresize(I,0.5,'Method','nearest');

Data Types: char | cell

'OutputSize' — Size of output imagetwo-element numeric vector

Size of the output image, specified as a two-element vector of the form [numrows numcols].

Example: [X2, newmap] = imresize(X,map,'OutputSize',[150 150]);

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

'Scale' — Resize scale factornumeric scalar or two-element vector of positive values

Resize scale factor, specified as a numeric scalar or two-element vector of positive values.

Example: [X2, newmap] = imresize(X,map,'scale',1.25);

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

Output Arguments

collapse all

B — Resized imagereal, nonsparse numeric array

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

Y — Resized indexed imagereal, nonsparse numeric array

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

newmap — Optimized colormapm-by-3 numeric array

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

gpuarrayB — Resized imagegpuArray

Resized image, returned as a gpuArray.

More About

collapse all

Code Generation

This function supports the generation of C code using MATLAB® Coder™. For more information, see Code Generation for Image Processing.

When generating code, note the following:

  • Indexed input images are not supported. This includes the imresize(X,map,...) syntaxes and the parameters 'Colormap' and 'Dither'.

  • Custom interpolation kernels are not supported.

  • All parameter-value pairs must be compile-time constants.

MATLAB Function Block

You can use this function in the MATLAB Function Block in Simulink.

When using this function with the MATLAB Function Block, note the following:

  • Scale and Method input argument values must be compile-time constants.

  • The numrows and numcols values of the OutputSize parameter must be compile-time constants.

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.

  • For bicubic interpolation and user-specified interpolation kernels, the output image may have some values slightly outside the range of pixel values in the input image.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值