matplotlib 影像作為 numpy 陣列
我們可以使用以下步驟將影像轉換為 numpy 陣列 -
從目錄中讀取影像;將它轉換為 numpy 陣列。
使用 imshow() 方法顯示影像。
使用 show() 方法顯示它。
示例
from matplotlib import pyplot as plt
plt.rcParams["figure.figsize"] = [7.00, 3.50]
plt.rcParams["figure.autolayout"] = True
im = plt.imread("bird.jpg")
print("Numpy array of the image is: ", im)
im = plt.imshow(im)
plt.show()輸出
當我們執行程式碼時,它將在一個繪圖中顯示“bird.jpg”,並在控制檯中顯示其 numpy 陣列。

Numpy array of the image is: [[[162 162 170] [162 162 170] [160 163 170] ... [ 97 98 92] [ 98 100 95] [ 94 96 91]] [[159 159 167] [159 159 167] [157 160 167] ... [ 94 95 89] [ 95 97 92] [ 92 94 89]] [[157 158 163] [157 158 163] [154 157 164] ... [ 93 94 89] [ 95 95 93] [ 95 95 93]] ... [[163 163 165] [163 163 165] [164 164 164] ... [187 165 151] [158 131 112] [133 105 84]] [[163 163 165] [163 163 165] [163 163 163] ... [160 134 117] [143 112 92] [127 96 75]] [[164 164 166] [163 163 165] [163 163 163] ... [145 116 98] [129 98 78] [124 92 71]]]
廣告
資料結構
網路
RDBMS
作業系統
Java
iOS
HTML
CSS
Android
Python
C 程式設計
C++
C#
MongoDB
MySQL
Javascript
PHP