2016-12-21 9 views
-3

Ich habe die folgenden RGB-BildimRGBplt.imshow zeigt Farbbilder für Graustufenbilder in IPython

import cv2 
import matplotlib.pyplot as plt 

#Loading the RGB image 
imRGB = cv2.imread('*path*') 

imRGB.shape 
>>(128L, 128L, 3L) 

#plotting 
plt.imshow(imRGB) 

imRGB

ich diese in ein Graustufenbild umwandeln imGray

imGray = cv2.cvtColor(imRGB, cv2.COLOR_BGR2GRAY) 

imGray.shape 
>>(128L, 128L) 

#plotting 
plt.imshow(imGray) 

imGray


Frage: Warum wird das Graustufenbild imGray wird farbig dargestellt?

Antwort

2

ImRGB war eine 3D-Matrix (Höhe x Breite x 3).
Jetzt ist ImGray eine 2D-Matrix, in der es keine Farben gibt, nur einen "Leuchtkraft" -Wert. So verwendete Matplotlib standardmäßig eine Colormap.

Lesen Sie this page und versuchen Sie, eine Graustufen-Colormap oder eine andere Colormap anzuwenden, überprüfen Sie die Ergebnisse.

plt.imshow(imGray, cmap="gray") 

Verwenden Sie this page as reference für Colormaps. Einige Colormap konnte nicht funktionieren, wenn es auftritt, versuchen Sie eine andere Colormap.

Verwandte Themen