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?NaN,?imresize?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。
?
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參考頁。您還可以指定自己的自定義插值內核。本例使用雙線性插值。
?
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)?
總結
以上是生活随笔為你收集整理的MATLAB基础编程(005-01)之Resize an Image with imresize Function 使用imresize函数 调整图像大小的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Typora+PicGo+Gitee+坚
- 下一篇: 我是如何在一周内准备完所有保研材料并成功