主要内容

精加工

Resize image

描述

example

B= imresize(A,规模)returns imageBthat is规模times the size of imageA。The input imageA可以是灰度,RGB,二进制图像或分类图像。

IfAhas more than two dimensions, then精加工only resizes the first two dimensions. If规模is between 0 and 1, thenBis smaller thanA。If规模is greater than 1, thenBis larger thanA。By default,精加工uses bicubic interpolation.

example

B= imresize(A,[numrows numcols])returns imageBthat has the number of rows and columns specified by the two-element vector[numrows numcols]

example

[Y,newmap] = imresize(X,map,___)调整索引图像的大小Xwheremapis the colormap associated with the image.

example

___= imresize(___,方法)specifies the interpolation method used.

___= imresize(___,Name,Value)returns the resized image where name-value arguments control various aspects of the resizing operation. Specify name-value arguments after all other input arguments.

例子

collapse all

将图像加载到工作区中。

i = imread('ngc6543a.jpg');

Shrink the image by a factor of two.

J = imresize(I, 0.5);

Display the original image and the resized image.

figure, imshow(I), figure, imshow(J)

图包含一个轴对象。The axes object contains an object of type image.

图包含一个轴对象。The axes object contains an object of type image.

Load an image into the workspace.

i = imread('ngc6543a.jpg');

Shrink the image to 40% of the original size using nearest-neighbor interpolation. This is the fastest method, but it has the lowest quality.

j = imresize(i,0.4,“最近”);

Display the original image and the resized image.

imshow(i)标题('Original Image')

图包含一个轴对象。The axes object with title Original Image contains an object of type image.

imshow(J) title('Resized Image Using Nearest Neighbor Interpolation')

图包含一个轴对象。The axes object with title Resized Image Using Nearest Neighbor Interpolation contains an object of type image.

Read an RGB image into the workspace.

RGB = imread('peppers.png');

Resize the RGB image to have 64 rows.精加工calculates the number of columns automatically.

RGB2 = imresize(RGB,[64 NaN]);

Get the size of the resized image.

sz = size(RGB2)
sz =1×364 86 3

Display the original image and the resized image.

imshow(RGB) title("Original Image")

图包含一个轴对象。The axes object with title Original Image contains an object of type image.

imshow(RGB2)标题("Resized Image with 64 Rows")

图包含一个轴对象。The axes object with title Resized Image with 64 Rows contains an object of type image.

Read an indexed image into the workspace.

[X,map] = imread("corn.tif");

Increase the size of the indexed image by 50%.

[Y,newmap] = imresize(X,map,1.5);

Display the original image and the resized image.

imshow(X,map) title(“原始索引图像和colormap”)

图包含一个轴对象。带有标题原始索引图像的轴对象和colormap包含类型图像的对象。

imshow(y,newmap)标题("Resized Image and Optimized Colormap")

图包含一个轴对象。The axes object with title Resized Image and Optimized Colormap contains an object of type image.

Input Arguments

collapse all

Image to be resized, specified as a numeric array, logical array, or categorical array of any dimension. Input must be nonsparse, and numeric input must be real.

Data Types:single|双倍的|int8|INT16|INT32|uint8|UINT16|uint32|logical|分类

Resize factor, specified as a positive number.精加工将相同的比例因子应用于行和列尺寸。要将不同的调整大小因子应用于每个维度,请使用'Scale'名称值参数。

Data Types:single|双倍的|int8|INT16|INT32|INT64|uint8|UINT16|uint32|uint64

输出图像的行和列尺寸,指定为正数的两元素向量。您可以指定值NaN一个numrowsornumcols。在这种情况下,精加工计算该维度的行数或列的数量自动保留图像的纵横比。

Data Types:single|双倍的|int8|INT16|INT32|INT64|uint8|UINT16|uint32|uint64

索引图像的大小,具体ed as a real, nonsparse numeric array of positive integers.

Data Types:双倍的|uint8|UINT16

Colormap associated with indexed imageX, specified as ac-by-3数字矩阵with values in the range [0, 1]. Each row is a three-element RGB triplet that specifies the red, green, and blue components of a single color of the colormap.

Data Types:双倍的

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

什么时候方法is a character vector or string scalar, it identifies a particular method or named interpolation kernel, listed in the following table.

Method 描述

“最近”

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

"bilinear"

双线性插值;输出像素值是最接近2 by-2社区中像素的加权平均值

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

插值内核 描述
"box" Box-shaped kernel
"triangle" 三角核(相当于"bilinear")
"cubic" Cubic kernel (equivalent to"bicubic")
"lanczos2" Lanczos-2内核
"lanczos3" Lanczos-3内核

什么时候方法is a two-element cell array, it defines a custom interpolation kernel. The cell array has the form {f,w}, wherefis a function handle for a custom interpolation kernel andwis the width of the custom kernel.f(x) must be zero outside the interval-w/2 <=x<w/2。The function handlefcan 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.

有关内置和自定义插值内核的更多信息,请参见Create and Compare Resizing Interpolation Kernels

Data Types:char|string|cell

Name-Value Arguments

Specify optional pairs of arguments asName1=Value1,...,NameN=ValueN, 在哪里Nameis the argument name andValue是相应的值。名称值参数必须在其他参数之后出现,但是对的顺序并不重要。

例子:B = imresize(A,0.5,Antialiasing=false)does not perform antialiasing when shrinking an image.

Before R2021a, use commas to separate each name and value, and encloseNamein quotes.

例子:B = imresize(A,0.5,"Antialiasing",false)does not perform antialiasing when shrinking an image.

Perform antialiasing when shrinking an image, specified astrueorfalse

  • If the interpolation方法is“最近”, then the default value of“抗血症”isfalse

  • If the interpolation方法is"box"输入图像是分类的,然后是“抗血症”isfalse

  • For all other interpolation methods, the default value istrue

Data Types:logical

返回索引图像的优化或原始的colormap,指定为以下值之一。

Value 描述
“原来的” 输出菌落newmapis the same as the input colormapmap
"optimized" 精加工returns a new optimized colormap.

The'colormap'argument is valid only when resizing indexed images.

Data Types:char|string

执行颜色抖动,指定为trueorfalse。In dithering, you apply a form of noise to the image to randomize quantization error and prevent large-scale patterns.

The'Dither'argument is valid only when resizing indexed images.

Data Types:logical

Interpolation method, specified as a character vector or two-element cell array. For details, see方法

Data Types:char|string|cell

Size of the output image, specified as a two-element vector of positive numbers. For details, see[numrows numcols]

Data Types:single|双倍的|int8|INT16|INT32|INT64|uint8|UINT16|uint32|uint64

Resize scale factor, specified as a positive number or two-element vector of positive numbers. If you specify a scalar, then精加工将相同的比例因子应用于行和列尺寸。If you specify a two-element vector, then精加工applies a different scale value to each dimension.

Data Types:single|双倍的|int8|INT16|INT32|INT64|uint8|UINT16|uint32|uint64

Output Arguments

collapse all

Resized image, returned as a numeric, logical, or categorical array of the same data type as the input image,A

Resized indexed image, returned as a numeric array of the same data type as the input indexed image,X

Colormap of the resized indexed imageY,作为一个m-by-3数字矩阵。By default,精加工返回带有调整大小图像的新的优化菌落。要返回与原始colormap相同的菌落,请使用'colormap'名称值参数。

提示

  • If the size of the output image is not an integer, then精加工does not use the scale specified.精加工uses theceilfunction when calculating the output image size.

Extended Capabilities

Version History

Introduced before R2006a