📜  Mahotas – 将图像加载为灰色

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

Mahotas – 将图像加载为灰色

在本文中,我们将看到如何在 mahotas 中将图像加载为灰色,在 mahotas 中有很多可用的图像,我们使用 mahotas.demos.load 方法来加载它们,在本教程中我们将使用“luispedro”图像,下面是加载它的命令。

mahotas.demos.load('luispedro')

下面是 luispedro 图像

为此,我们将使用 mahotas.demos.load 方法

示例 1:

Python3
# importing required libraries
import mahotas
import mahotas.demos
import numpy as np
from pylab import imshow, gray, show
from os import path
 
# loading the image
photo = mahotas.demos.load('luispedro')
 
# showing original image
print("Original Image")
imshow(photo)
show()
 
# loading image as grey
photo = mahotas.demos.load('luispedro', as_grey = True)
 
# showing image
print("Image loaded as grey")
imshow(photo)
show()


Python3
# importing required libraries
import mahotas
import mahotas.demos
import numpy as np
from pylab import imshow, gray, show
from os import path
 
# loading the image
photo = mahotas.demos.load('luispedro')
 
# showing original image
print("Original Image")
imshow(photo)
show()
 
# loading image as grey
photo = mahotas.demos.load('luispedro', as_grey = True)
 
# converting image type to unit8
# because as_grey returns floating values
photo = photo.astype(np.uint8)
 
# calling gray method
gray()
 
# showing image
print("Image loaded as grey")
imshow(photo)
show()


输出 :

示例 2:

Python3

# importing required libraries
import mahotas
import mahotas.demos
import numpy as np
from pylab import imshow, gray, show
from os import path
 
# loading the image
photo = mahotas.demos.load('luispedro')
 
# showing original image
print("Original Image")
imshow(photo)
show()
 
# loading image as grey
photo = mahotas.demos.load('luispedro', as_grey = True)
 
# converting image type to unit8
# because as_grey returns floating values
photo = photo.astype(np.uint8)
 
# calling gray method
gray()
 
# showing image
print("Image loaded as grey")
imshow(photo)
show()

输出 :