from PIL import Image
with Image.open("tesla.png")as im:
#show the original image
im.show("Original Image")
#convert into grayscale
grayscaleImg = im.convert("L")
#show the grayscale image
grayscaleImg.show()
from skimage import io
from skimage.color import rgb2gray
# way to load car image from file
car = io.imread('tesla.png')[:,:,:3]
#convert into grayscale
grayscale = rgb2gray(car)
#show the original
io.imshow(car)
io.show()
#show the grayscale
io.imshow(grayscale)
io.show()
import numpy as np
import matplotlib.pyplotas plt
import matplotlib.imageas mpimg
#load the original image
img_rgb = mpimg.imread('tesla.png')[...,:3]
#show the original image
plt.imshow(img_rgb)
plt.show()
#convert the image into grayscale
img_gray = np.dot(img_rgb,[0.299,0.587,0.144])
#show the grayscale image
plt.imshow(img_gray, cmap=plt.get_cmap('gray'))
plt.show()
1.
2.
3.
4.
5.
6.
7.
8.
9.
10.
11.
12.
13.
mahotas
Mahotas 是另一个可以执行各种图像处理操作的 Python 计算机视觉库。它是用 C++设计的,它包含许多提高图像处理速度的算法。此外,它使用 NumPy 数组在矩阵中使用图像。分水岭、凸点计算 hit & miss 卷积和 Sobel 边缘是该库中可用的主要功能。
pip install mahotas
1.
import mahotas
from pylab import imshow, show
#read the image
img = mahotas.imread('tesla.png')
#show original image
imshow(img)
show()
img = img[:,:,0]
grayscale = mahotas.overlay(img)
#show grayscale image
imshow(grayscale)
show()
import SimpleITK as sitk
import matplotlib.pyplotas plt
logo = sitk.ReadImage('tesla.png')
# GetArrayViewFromImage returns an immutable numpy array view to the data.
plt.imshow(sitk.GetArrayViewFromImage(logo))
plt.show()