MATLAB基础编程(005-01)之Resize an Image with imresize Function 使用imresize函数 调整图像大小

This example shows how to resize an image using the imresize function.

此示例显示如何使用imresize函数调整图像大小。

Specify the Magnification Value

指定放大率值

Read and display an image.

读取并显示图像。

I = imread("circuit.tif");
imshow(I)

Resize the image, using the imresize function. In this example, you specify a magnification factor. To enlarge an image, specify a magnification factor greater than 1.

使用imresize函数调整图像大小。在本例中,指定放大系数。要放大图像,请指定大于1的放大系数。

magnificationFactor = 1.25;
J = imresize(I,magnificationFactor);

Display the enlarged image.

显示放大的图像。

imshow(J)

Specify the Size of the Output Image

指定输出图像的大小

Resize the image again, this time specifying the desired size of the output image, rather than a magnification value. Pass imresize a vector that contains the number of rows and columns in the output image. If the specified size does not produce the same aspect ratio as the input image, the output image will be distorted. If you specify one of the elements in the vector as NaNimresize calculates the value for that dimension to preserve the aspect ratio of the image. To perform the resizing required for multi-resolution processing, use impyramid.


再次调整图像大小,这次指定输出图像的所需大小,而不是放大率值。传递imresize一个向量,该向量包含输出图像中的行数和列数。如果指定的大小不能产生与输入图像相同的纵横比,则输出图像将失真。如果将向量中的一个元素指定为NaN,则imresize将计算该维度的值,以保留图像的纵横比。要执行多分辨率处理所需的调整大小,请使用impyramid。

K = imresize(I,[100 150]);
imshow(K)

Specify the Interpolation Method

指定插值方法

Resize the image again, this time specifying the interpolation method. When you enlarge an image, the output image contains more pixels than the original image. imresize uses interpolation to determine the values of these pixels, computing a weighted average of some set of pixels in the vicinity of the pixel location. imresize bases the weightings on the distance each pixel is from the point. By default, imresize uses bicubic interpolation, but you can specify other interpolation methods or interpolation kernels. See the imresize reference page for a complete list. You can also specify your own custom interpolation kernel. This example use bilinear interpolation.


再次调整图像大小,这次指定插值方法。放大图像时,输出图像包含的像素比原始图像多。imresize使用插值来确定这些像素的值,计算像素位置附近某组像素的加权平均值。imresize将权重基于每个像素与点的距离。默认情况下,imresize使用双三次插值,但您可以指定其他插值方法或插值核。有关完整列表,请参阅imresize参考页。您还可以指定自己的自定义插值内核。本例使用双线性插值。

L = imresize(I,1.5,"bilinear");
imshow(L)

Prevent Aliasing When Shrinking an Image

缩小图像时防止锯齿

Resize the image again, this time shrinking the image. When you reduce the size of an image, you lose some of the original pixels because there are fewer pixels in the output image. This can introduce artifacts, such as aliasing. The aliasing that occurs as a result of size reduction normally appears as stair-step patterns (especially in high-contrast images), or as moire (ripple-effect) patterns in the output image. By default, imresize uses antialiasing to limit the impact of aliasing on the output image for all interpolation types except nearest neighbor. To turn off antialiasing, specify the 'Antialiasing' parameter and set the value to false. Even with antialiasing turned on, resizing can introduce artifacts because information is always lost when you reduce the size of an image.

再次调整图像大小,这次缩小图像。减小图像大小时,会丢失一些原始像素,因为输出图像中的像素较少。这可能会引入伪影,例如别名。由于尺寸减小而产生的锯齿通常在输出图像中显示为阶梯图案(尤其是在高对比度图像中),或显示为莫尔(波纹效应)图案。默认情况下,imresize使用抗锯齿来限制除最近邻之外的所有插值类型的锯齿对输出图像的影响。要关闭抗锯齿,请指定“抗锯齿”参数并将该值设置为false。即使启用了抗锯齿,调整大小也会引入瑕疵,因为减小图像大小时信息总是会丢失。

M = imresize(I,.75,"Antialiasing",false);
imshow(M)

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值