Python-可视化不同颜色空间中的图像
OpenCV-Python是旨在解决计算机视觉问题的Python绑定库。OpenCV-Python利用了Numpy,这是一个高度优化的库,用于使用MATLAB样式的语法进行数值运算。所有OpenCV数组结构都与Numpy数组相互转换。
示例
# read image as RGB
# Importing cv2 and matplotlib module
import cv2
import matplotlib.pyplot as plt
# reads image as RGB
img = cv2.imread('download.png')
# shows the image
plt.imshow(img)
# read image as GrayScale
# Importing cv2 module
import cv2
# Reads image as gray scale
img = cv2.imread('download.png', 0)
# We can alternatively convert
# image by using cv2color
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# Shows the image
cv2.imshow('image', img)
cv2.waitKey(0)
cv2.destroyAllWindows()
# read image as YCrCb color space
# Import cv2 module
import cv2
# Reads the image
img = cv2.imread('download.png')
# Convert to YCrCb color space
img = cv2.cvtColor(img, cv2.COLOR_BGR2YCrCb)
# Shows the image
cv2.imshow('image', img)
cv2.waitKey(0)
cv2.destroyAllWindows()
# read image as HSV color space
# Importing cv2 module
import cv2
# Reads the image
img = cv2.imread('download.png')
# Converts to HSV color space
img = cv2.cvtColor(img, cv2.COLOR_BGR2HSV)
# Shows the image
cv2.imshow('image', img)
cv2.waitKey(0)
cv2.destroyAllWindows()
# Heat map of image
# Importing matplotlib and cv2
import matplotlib.pyplot as plt
import cv2
# reads the image
img = cv2.imread('download.png')
# plot heat map image
plt.imshow(img, cmap ='hot')
# Spectral map of image
# Importing matplotlib and cv2
import matplotlib.pyplot as plt
import cv2
img = cv2.imread('download.png')
plt.imshow(img, cmap ='nipy_spectral')热门推荐
10 送礼祝福语男性生日简短
11 求助短信生日祝福语简短
12 离别祝福语简短送同事
13 简短古文生日祝福语
14 红包祝福语简短网名
15 新婚祝福语大全简短经典
16 毕业祝福语简短给同学
17 恭喜新郎父母简短祝福语
18 婚礼仪式祝福语简短