Which source does each end of a compositing mask select?
composite mixes two images pixel by pixel. White selects the first image and black the second.
Pixel experiment and interpretation
Check polarity with two solid strips and a two-point mask before swapping a background. Reversed inputs erase the intended foreground.
from PIL import Image
def row(values):
return Image.frombytes('L', (len(values), 1), bytes(values))
list(Image.composite(row([80,80]),row([10,10]),row([0,255])).tobytes())Result [10, 80]
中文
蒙版的黑白端分别选择哪张输入图?
composite 按掩膜逐像素混合两张图,白色取第一张,黑色取第二张。
像素实验与适用边界
做前景替换前先用两种纯色和一个两点掩膜测试极性。颠倒输入会把原本要保留的区域挖掉。
from PIL import Image
def row(values):
return Image.frombytes('L', (len(values), 1), bytes(values))
list(Image.composite(row([80,80]),row([10,10]),row([0,255])).tobytes())结果 [10, 80]