簡體   English   中英

將RGB圖像轉換為灰度img

[英]Convert a RGB image to grayscale img

arr = []
for i in range(len(x1)):
    image = x1[i].reshape(150, 150, 3)
    grayscale = image[0:150, 0:150, 1]
    grayscale = grayscale.reshape(22500)
    arr = np.append(arr, np.array(grayscale), axis=0)

print(arr.shape)  # (742500,)

我正在做一個學校項目,並且我創建了更多帶有 RGB 格式的增強數據。 我想在增強后將其轉換為灰度,因為它需要更少的計算。 但是,由於某種原因,我在將重塑后的版本附加到新數組時遇到了問題。 它是 append 一切都在一行而不是單獨的行中,我想要(33,22500)而不是(742500),任何人都可以幫忙嗎?

有幾種方法; 方式1:

arr = []
for i in range(len(x1)):
    image = x1[i].reshape(150,150,3)
    grayscale = image[:150,:150,1]
    grayscale = grayscale.reshape(22500)
    arr.append(grayscale)

arr = np.array(arr)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM