这并没有回答你关于魔杖的问题......但是你可以用 pil 来做这件事很容易......
from PIL import Image
from math import ceil
import q
def CalcLuminosity(RED,GREEN,BLUE):
return int(ceil(0.2126 * RED + 0.7152 * GREEN + 0.0722 * BLUE))
im = Image.open('bird.jpg')
# im.convert("L") will apply the standard luminosity mapping
data = [CalcLuminosity(*im.getpixel((c,r))) for r in range(im.height) for c in range(im.width) ]
#now make our new image using our luminosity values
x = Image.new("L",(im.width,im.height))
image_px = x.load()
for c in range(im.width):
for r in range(im.height):
image_px[c,r] = data[r*im.width+c]
x.save("output.jpg")
或者如果您想根据阈值限制极端情况
#now make our new image using our luminosity values
x = Image.new("L",(im.width,im.height))
image_px = x.load()
for c in range(im.width):
for r in range(im.height):
image_px[c,r] = 0 if data[r*im.width+c] < 120 else 255
x.save("output.jpg")
或者如果你想过滤一个单一的颜色通道
def CalcLuminosityBLUE(RED,GREEN,BLUE):
return BLUE