如何使用 PIL Image.point(table) 方法对 256 灰度图像应用阈值?
我有 8 位灰度 TIFF 图像,我想使用 75% 白色(十进制 190)阈值将其转换为单色。在Image.convert(mode)方法部分,PIL手册说:
“将灰度图像转换为位级图像(模式“1”)时,所有非零值均设置为 255(白色)。要使用其他阈值,请使用点方法。”
Image.point(table) 方法表示它通过给定的表映射每个像素。
im.point(表, 模式) =>图片
<块引用> <块引用>
im.point(函数, 模式) =>图片“通过表格映射图像,并即时转换。在当前版本的 PIL 中,这只能用于将 'L' 和 'P' 图像一步转换为 '1',例如阈值图像。”
如何创建与我需要的 75% 阈值相对应的表(或函数)?
I have 8-bit greyscale TIFF images that I want to convert to Monochrome using a 75% white (decimal 190) threshold. In the Image.convert(mode) method section, the PIL manual says:
"When translating a greyscale image into a bitlevel image (mode "1"), all non-zero values are set to 255 (white). To use other thresholds, use the point method."
The Image.point(table) method says that it maps each pixel through the given table.
im.point(table, mode) => image
im.point(function, mode) => image"Map the image through table, and convert it on fly. In the current version of PIL , this can only be used to convert 'L' and 'P' images to '1' in one step, e.g. to threshold an image."
How do I create the table (or function) that corresponds to the 75% threshold I need?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我在这个答案中找到了完整的解决方案“Write TIFF file in python from String”。该函数必须包含“and 255”
I found the complete solution in this answer "Write TIFF file in python from String". The function must include "and 255"
尝试
im.point(lambda p: p > 190)
并发布结果。Try
im.point(lambda p: p > 190)
and post the results.