Does editing a copied image alter the master pixels?
copy creates independent pixels. Later in-place edits on the copy leave the master pixels intact.
Pixel experiment and interpretation
Copy a review image before marking it. Ordinary variable assignment gives the master a second name, allowing the same write to contaminate the baseline.
from PIL import Image
def row(values):
return Image.frombytes('L', (len(values), 1), bytes(values))
master=row([11])
mark=master.copy()
mark.putpixel((0,0),200)
(master.getpixel((0,0)),mark.getpixel((0,0)))Result (11, 200)
中文
修改一份图像副本会改动原始样本吗?
copy 创建独立的像素副本,之后在副本上原位写入不会改动原像素。
像素实验与适用边界
给审阅图打上标记前先复制。普通变量赋值会让两个名字指向同一图像,同样的写入就会污染基线。
from PIL import Image
def row(values):
return Image.frombytes('L', (len(values), 1), bytes(values))
master=row([11])
mark=master.copy()
mark.putpixel((0,0),200)
(master.getpixel((0,0)),mark.getpixel((0,0)))结果 (11, 200)