2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

[python]matplotlibを用いた画像表示の基礎

Last updated at Posted at 2020-02-18

#画像表示
OpenCVで読み込んで, それをmatplotlibで表示したいときのメモとなります.
まずは, 失敗例から.

import cv2
from matplotlib import pyplot as plt
img = cv2.imread("Pasta.jpg") #BGRで取得.
plt.imshow(img)
plt.show()

[原因]:OpenCVのimreadは色情報をBGRで取得するが, それをmatplotllibでRGB表示させているから.
screenshot.png
なので, 一度OpenCVで取得したBGRをRGBに変換し, それをmatplotllibでRGB表示させることで正常に画像表示できる.

import cv2
from matplotlib import pyplot as plt
img = cv2.imread("Pasta.jpg") #BGRで取得.
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB) #BGRをRGBに変換.
plt.imshow(img)
plt.show()

Qita用.jpg

余談ですが, 画像のグレースケール表示に関しては自分の下の記事にあります.
https://qiita.com/Daiki_P/items/844bc3a4b271e6ae179b

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?