我正在尝试在Python中使用PIL根据像素RGB值删除图像的部分。从文档上来看,函数point似乎可以做到我想要的。然而,我很难理解文档内容。如果我想将所有蓝色值小于100的像素更改为白色,最简单的方法是什么?
我正在尝试在Python中使用PIL根据像素RGB值删除图像的部分。从文档上来看,函数point似乎可以做到我想要的。然而,我很难理解文档内容。如果我想将所有蓝色值小于100的像素更改为白色,最简单的方法是什么?
import Mahotas as mh
import numpy as np
fname = "/home/stuff/images/my_image.jpg"
image = mh.imread(fname)
# Make a copy to play with the indices.
img = np.copy(image)
# Replace places with 3rd coordinate less than 100 with the white-color
# vector [255, 255, 255].
inds = img[:,:,2] < 100
img[inds] = [255,255,255]
source = im.split()
mask = source[2].point(lambda i: i < 100 and 255)
im = Image.merge(im.mode, source)
更多信息请参见点操作标题下的PIL教程。