如何使用 PIL Image.point(table) 方法对 256 灰度图像应用阈值?

发布于 2024-11-17 09:09:56 字数 496 浏览 7 评论 0原文

我有 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

倚栏听风 2024-11-24 09:09:56

我在这个答案中找到了完整的解决方案“Write TIFF file in python from String”。该函数必须包含“and 255”

threshold = 191  
im = im.point(lambda p: p > threshold and 255)  

I found the complete solution in this answer "Write TIFF file in python from String". The function must include "and 255"

threshold = 191  
im = im.point(lambda p: p > threshold and 255)  
因为看清所以看轻 2024-11-24 09:09:56

尝试 im.point(lambda p: p > 190) 并发布结果。

Try im.point(lambda p: p > 190) and post the results.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文