📜  Mahotas – 调整图像大小

📅  最后修改于: 2022-05-13 01:54:51.412000             🧑  作者: Mango

Mahotas – 调整图像大小

在本文中,我们将了解如何在 mahotas 中调整图像大小。当您将图像从一个像素网格调整到另一个像素网格或将其扭曲时,就会发生图像插值。当您需要增加或减少总像素数时,需要调整图像大小,而在校正镜头失真或旋转图像时可能会发生重新映射。
在本教程中,我们将使用“lena”图像,下面是加载它的命令。

mahotas.demos.load('lena')

下面是莉娜的图片

注意:输入图像应被过滤或应加载为灰色
为了过滤图像,我们将获取图像对象 numpy.ndarray 并在索引的帮助下对其进行过滤,下面是执行此操作的命令

image = image[:, :, 0]

下面是实现

Python3
# importing required libraries
import mahotas
import mahotas.demos
from pylab import gray, imshow, show
import numpy as np
import matplotlib.pyplot as plt
   
# loading image
img = mahotas.demos.load('lena')
 
 
   
# filtering image
img = img.max(2)
 
print("Image")
   
# showing image
imshow(img)
show()
 
# resizing image
new_img = mahotas.imresize(img, [200, 250])
  
 
# showing image
print("Resized Image")
imshow(new_img)
show()


Python3
# importing required libraries
import mahotas
import numpy as np
from pylab import gray, imshow, show
import os
import matplotlib.pyplot as plt
  
# loading image
img = mahotas.imread('dog_image.png')
 
 
# filtering image
img = img[:, :, 0]
   
print("Image")
   
# showing image
imshow(img)
show()
 
# resizing image
new_img = mahotas.imresize(img, [200, 200])
  
 
# showing image
print("Resized Image")
imshow(new_img)
show()


输出 :

Image

Resized Image

另一个例子

Python3

# importing required libraries
import mahotas
import numpy as np
from pylab import gray, imshow, show
import os
import matplotlib.pyplot as plt
  
# loading image
img = mahotas.imread('dog_image.png')
 
 
# filtering image
img = img[:, :, 0]
   
print("Image")
   
# showing image
imshow(img)
show()
 
# resizing image
new_img = mahotas.imresize(img, [200, 200])
  
 
# showing image
print("Resized Image")
imshow(new_img)
show()

输出 :

Image

Resized Image