開始使用免費開始

直方圖

在這個練習中,你將分析影像中的紅色含量。為此,我們會針對下方影像的紅色通道計算直方圖:

Woman smiling
影像已載入為 image

從影像中擷取資訊是影像增強的基本步驟。透過這樣的方式,你可以調整紅色與藍色的比例,讓影像看起來更冷或更暖。

你會使用 hist() 來顯示紅色的 256 種不同強度,並使用 ravel() 將這些色彩值轉成單一扁平維度的陣列。

Matplotlib 已預先載入為 plt,Numpy 為 np

記住,如果我們想取得影像的綠色通道,可以這樣做:

green = image[:, :, 1]

本練習屬於課程

Python 影像處理

檢視課程

練習說明

  • 使用切片取得紅色通道。
  • 繪製直方圖並將 bins 設為 256 的範圍。別忘了對色彩通道使用 .ravel()

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

# Obtain the red channel
red_channel = image[____, ____, ____]

# Plot the red histogram with bins in a range of 256
plt.____(____.____, bins=____)

# Set title and show
plt.title('Red Histogram')
plt.show()
編輯並執行程式碼