Python PIL根据图像的颜色删除图像的各个部分 [英] Python PIL remove sections of an image based on its colour

查看:302
本文介绍了Python PIL根据图像的颜色删除图像的各个部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在python中使用PIL根据像素RGB值删除部分图像.从文档看来,该功能点可以满足我的需求.但是,我很难遵循文档.如果我想将所有蓝色值小于100的像素都更改为白色,那是最简单的方法呢?

I am trying to use PIL in python to remove parts of images based on the pixels RGB values. From the documentation it would seem that the function point could do what I'm looking for. However I am having a hard time following the documentation. If i wanted to change all the pixels that have a blue value of less than 100 to white what would be the easiest way to achieve this?

推荐答案

类似以下的方法将起作用:

Something like the following would work:

source = im.split()
mask = source[2].point(lambda i: i < 100 and 255)
im = Image.merge(im.mode, source)

请参见点操作下的 PIL指南.欲了解更多信息,请访问强"标题.

See the PIL Tutorial under the Point Operations heading for more information.

这篇关于Python PIL根据图像的颜色删除图像的各个部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆