matplotlib
官網http://matplotlib.org/index.html
Pyplot tutorial
http://matplotlib.org/users/pyplot_tutorial.html
Matplotlib 教程 (中文)
http://liam0205.me/2014/09/11/matplotlib-tutorial-zh-cn/
Matplotlib Examples
http://matplotlib.org/examples/
API content
http://matplotlib.org/api/index.html
class
http://matplotlib.org/api/colors_api.html?highlight=colors#matplotlib.colors.ListedColormap
Note:OpenCV讀圖是BRG模式,而OpenCV則是RGB,所以彩色圖在這兩者之間直接轉換會有問題。
Color image loaded by OpenCV is in BGR mode. But Matplotlib displays in RGB mode. So color images will not be displayed correctly in Matplotlib if image is read with OpenCV. Please see the exercises for more details.
範例:
import cv2
from matplotlib import pyplot as plt
img = cv2.imread('image.jpg')
print(img)
b,g,r = cv2.split(img)
img2 = cv2.merge([r,g,b])
plt.subplot(121);plt.imshow(img) # expects distorted color
plt.subplot(122);plt.imshow(img2) # expect true color
plt.show()
cv2.imshow('bgr image',img) # expects true color
cv2.imshow('rgb image',img2) # expects distorted color
cv2.waitKey(0)
cv2.destroyAllWindows()
matplotlib.pyplot.
plot
(*args, **kwargs)
plot(x, y) # plot x and y using default line style and color plot(x, y, 'bo') # plot x and y using blue circle markers plot(y) # plot y using x as index array 0..N-1 plot(y, 'r+') # ditto, but with red plusses
a.plot(x1, y1, 'g^', x2, y2, 'g-')
matplotlib.colors
A module for converting numbers or color arguments to RGB or RGBA
class matplotlib.colors.
ListedColormap
(colors, name='from_list', N=None)
http://matplotlib.org/api/colors_api.html?highlight=colors#matplotlib.colors.ListedColormap
matplotlib,imshow
Display an image on the axes.
imshow
(X, cmap=None, norm=None, aspect=None, interpolation=None, alpha=None, vmin=None, vmax=None, origin=None,extent=None, shape=None, filternorm=1, filterrad=4.0, imlim=None, resample=None, url=None, **kwargs)Note:OpenCV讀圖是BRG模式,而OpenCV則是RGB,所以彩色圖在這兩者之間直接轉換會有問題。
Color image loaded by OpenCV is in BGR mode. But Matplotlib displays in RGB mode. So color images will not be displayed correctly in Matplotlib if image is read with OpenCV. Please see the exercises for more details.
範例:
原圖
彩色OpenCV讀,matplotlib寫
import cv2
from matplotlib import pyplot as plt
img = cv2.imread('image.jpg',0)
plt.imshow(img, interpolation = 'bicubic')
plt.xticks([]), plt.yticks([]) # to hide tick values on X and Y axis
plt.show()
from matplotlib import pyplot as plt
img = cv2.imread('image.jpg',0)
plt.imshow(img, interpolation = 'bicubic')
plt.xticks([]), plt.yticks([]) # to hide tick values on X and Y axis
plt.show()
Out:
灰階OpenCV讀,matplotlib寫
利用cv2.split() 來把b、g、r拆解,在以r、g、b格式合併即可解決:
import numpy as npimport cv2
from matplotlib import pyplot as plt
img = cv2.imread('image.jpg')
print(img)
b,g,r = cv2.split(img)
img2 = cv2.merge([r,g,b])
plt.subplot(121);plt.imshow(img) # expects distorted color
plt.subplot(122);plt.imshow(img2) # expect true color
plt.show()
cv2.imshow('bgr image',img) # expects true color
cv2.imshow('rgb image',img2) # expects distorted color
cv2.waitKey(0)
cv2.destroyAllWindows()
沒有留言:
張貼留言