[英]Edit RGB values in an image dependant on each pixel's red value
我想要做的是獲取圖像的每個像素並使綠色和藍色值與每個像素的紅色值相匹配。
我已經嘗試在 Paint.net 中轉換為黑白,但它會平均 RGB 值並且沒有給我正確的黑色/灰色陰影。
我剛剛開始學習 Python,我不知道從哪里開始學習這樣的東西。 我認為有一個不同的程序可以讓我做到這一點,但我不知道在哪里看。
from PIL import Image
import requests
from io import BytesIO
response = requests.get('https://www.ricoh-imaging.co.jp/english/products/q-s1/ex/img/bod_mainImg_01.jpg')
img = Image.open(BytesIO(response.content)).resize((400, 300)).convert('RGB') # make sure to be in RGB format
img
然后轉換為 numpy 數組,您可以輕松地將紅色 (0) 通道復制到綠色和藍色通道(1 和 2)。
import numpy as np
arr = np.array(img)
arr[:,:,1] = arr[:,:,0]
arr[:,:,2] = arr[:,:,0]
Image.fromarray(arr)
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.