精加工
Resize image
Syntax
描述
returns imageB
= imresize(A
,规模
)B
that is规模
times the size of imageA
。The input imageA
可以是灰度,RGB,二进制图像或分类图像。
IfA
has more than two dimensions, then精加工
only resizes the first two dimensions. If规模
is between 0 and 1, thenB
is smaller thanA
。If规模
is greater than 1, thenB
is larger thanA
。By default,精加工
uses bicubic interpolation.
returns imageB
= imresize(A
,[numrows numcols]
)B
that has the number of rows and columns specified by the two-element vector[numrows numcols]
。
___= imresize(___,
returns the resized image where name-value arguments control various aspects of the resizing operation. Specify name-value arguments after all other input arguments.Name,Value
)
例子
Shrink Image By Factor of Two Using Default Interpolation Method
将图像加载到工作区中。
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)
Shrink Image Using Nearest-Neighbor Interpolation
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')
imshow(J) title('Resized Image Using Nearest Neighbor Interpolation')
Resize RGB Image Specifying Size of Output 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")
imshow(RGB2)标题("Resized Image with 64 Rows")
Resize Indexed 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”)
imshow(y,newmap)标题("Resized Image and Optimized Colormap")
Input Arguments
A
—Image to be resized
numeric array|逻辑阵列|分类array
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
正数
Resize factor, specified as a positive number.精加工
将相同的比例因子应用于行和列尺寸。要将不同的调整大小因子应用于每个维度,请使用'Scale'
名称值参数。
Data Types:single
|双倍的
|int8
|INT16
|INT32
|INT64
|uint8
|UINT16
|uint32
|uint64
[numrows numcols]
—Row and column dimensions of output image
正数的两元素向量
输出图像的行和列尺寸,指定为正数的两元素向量。您可以指定值NaN
一个numrows
ornumcols
。在这种情况下,精加工
计算该维度的行数或列的数量自动保留图像的纵横比。
Data Types:single
|双倍的
|int8
|INT16
|INT32
|INT64
|uint8
|UINT16
|uint32
|uint64
X
—要调整大小的索引图像
真实的,非数字阵列
索引图像的大小,具体ed as a real, nonsparse numeric array of positive integers.
Data Types:双倍的
|uint8
|UINT16
map
—Colormap associated with indexed image
c-by-3数字矩阵
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
"bicubic"
(default) |角色向量|string scalar|两元素单元格数组
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. |
|
双线性插值;输出像素值是最接近2 by-2社区中像素的加权平均值 |
|
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
, 在哪里Name
is 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 encloseName
in quotes.
例子:B = imresize(A,0.5,"Antialiasing",false)
does not perform antialiasing when shrinking an image.
Antialiasing
—Perform antialiasing when shrinking an image
true
|false
Perform antialiasing when shrinking an image, specified astrue
orfalse
。
If the interpolation
方法
is“最近”
, then the default value of“抗血症”
isfalse
。If the interpolation
方法
is"box"
输入图像是分类的,然后是“抗血症”
isfalse
。For all other interpolation methods, the default value is
true
。
Data Types:logical
Dither
—Perform color dithering
true
(default) |false
执行颜色抖动,指定为true
orfalse
。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
Method
—Interpolation method
"bicubic"
(default) |角色向量|cell array
Interpolation method, specified as a character vector or two-element cell array. For details, see方法
。
Data Types:char
|string
|cell
OutputSize
—输出图像的大小
正数的两元素向量
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
Scale
—Resize scale factor
正数|正数的两元素向量
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
B
— Resized image
numeric array | logical array | categorical array
Resized image, returned as a numeric, logical, or categorical array of the same data type as the input image,A
。
Y
— Resized indexed image
numeric array
Resized indexed image, returned as a numeric array of the same data type as the input indexed image,X
。
newmap
- 调整大小索引图像的结肠
m-by-3数字矩阵
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 theceil
function when calculating the output image size.
Extended Capabilities
C/C ++代码生成
Generate C and C++ code using MATLAB® Coder™.
用法注释和限制:
Syntaxes that support indexed images are not supported, including the name-value arguments
'colormap'
and'Dither'
。不支持自定义插值内核。万博1manbetx
所有名称值参数必须是编译时常数。
GPU Code Generation
Generate CUDA® code for NVIDIA® GPUs using GPU Coder™.
用法注释和限制:
'colormap'
and'Dither'
name-value arguments are not supported.Indexed images are not supported.
不支持自定义插值内核。万博1manbetx
所有必须编译时常量名称-值对s.
For certain interpolation kernels, there can be a small numerical mismatch between the results in MATLAB®和生成的代码。
Thread-Based Environment
Run code in the background using MATLAB®背景池
or accelerate code with Parallel Computing Toolbox™ThreadPool
。
This function fully supports thread-based environments. For more information, seeRun MATLAB Functions in Thread-Based Environment。
GPU Arrays
Accelerate code by running on a graphics processing unit (GPU) using Parallel Computing Toolbox™.
用法注释和限制:
gpuArray
input with more than 227不支持元素。万博1manbetxgpuArray
input must be non-sparse.gpuArray
input with underlying type分类
is not supported.GPU上不支持索引图像。万博1manbetx
If you use bicubic interpolation, the output image can have some values slightly outside the range of pixel values in the input image.
There is a slight numerical difference between the results of
精加工
on a CPU and a GPU. These differences occur on the right and bottom borders of the image and are barely noticeable to the naked eye.
有关更多信息,请参阅Run MATLAB Functions on a GPU(Parallel Computing Toolbox)。
Version History
matlab命令
You clicked a link that corresponds to this MATLAB command:
通过在MATLAB命令窗口中输入该命令。Web浏览器不支持MATLAB命令。万博1manbetx
Select a Web Site
Choose a web site to get translated content where available and see local events and offers. Based on your location, we recommend that you select:。
You can also select a web site from the following list:
How to Get Best Site Performance
Select the China site (in Chinese or English) for best site performance. Other MathWorks country sites are not optimized for visits from your location.
Americas
- AméricaLatina(Español)
- Canada(英语)
- United States(英语)
Europe
- 比利时(英语)
- 丹麦(英语)
- Deutschland(Deutsch)
- España(Español)
- Finland(英语)
- France(Français)
- Ireland(英语)
- Italia(Italiano)
- Luxembourg(英语)
- Netherlands(英语)
- Norway(英语)
- Österreich(Deutsch)
- Portugal(英语)
- Sweden(英语)
- Switzerland
- 英国(英语)