影像作為資料:變更影像
若要修改影像,你可以直接修改陣列中的數值。對彩色影像而言,你可以只改變其中一個色彩通道的數值,而不影響其他顏色,方法是針對陣列的最後一個維度進行索引。
你在前一個練習匯入的影像已可透過 data 取得。
本練習屬於課程
使用 Keras 進行影像建模
練習說明
- 修改磚牆影像,將影像左上角(10×10 像素)替換為紅色方塊。
- 視覺化顯示修改後的影像。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Set the red channel in this part of the image to 1
data[____] = ____
# Set the green channel in this part of the image to 0
data[____] = ____
# Set the blue channel in this part of the image to 0
data[____] = ____
# Visualize the result
____
____