Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 将图像清理为仅黑色_Python_Image Processing_Python Imaging Library - Fatal编程技术网

Python 将图像清理为仅黑色

Python 将图像清理为仅黑色,python,image-processing,python-imaging-library,Python,Image Processing,Python Imaging Library,我有一个形象 我想一个像素一个像素地看一下那个图像,任何不是黑色的像素都应该变成白色。我该怎么做 (Python) 谢谢 您可能希望签出以下库: 特别是: im.getpixel(xy) => value or tuple 及 您可能希望签出以下库: 特别是: im.getpixel(xy) => value or tuple 及 最有效的方法是使用点函数 def only_black(band): if band > 0: return 255

我有一个形象

我想一个像素一个像素地看一下那个图像,任何不是黑色的像素都应该变成白色。我该怎么做

(Python)


谢谢

您可能希望签出以下库:

特别是:

im.getpixel(xy) => value or tuple


您可能希望签出以下库:

特别是:

im.getpixel(xy) => value or tuple


最有效的方法是使用点函数

def only_black(band):
    if band > 0:
        return 255
    return 0
result = im.convert('L').point(only_black)
这就是政府对此的看法:

转换为双层图像时 (模式“1”),源图像是第一个 转换成黑白的。 大于127的结果值为 然后设置为白色,则图像为白色 犹豫不决。要使用其他阈值,请使用 点法


最有效的方法是使用点函数

def only_black(band):
    if band > 0:
        return 255
    return 0
result = im.convert('L').point(only_black)
这就是政府对此的看法:

转换为双层图像时 (模式“1”),源图像是第一个 转换成黑白的。 大于127的结果值为 然后设置为白色,则图像为白色 犹豫不决。要使用其他阈值,请使用 点法


您应该使用
功能,该功能正是为此而存在的

converter= ( (0,) + 255*(255,) ).__getitem__
def black_or_white(img):
    return img.convert('L').point(converter)

您应该使用
功能,该功能正是为此而存在的

converter= ( (0,) + 255*(255,) ).__getitem__
def black_or_white(img):
    return img.convert('L').point(converter)

putpixel函数知道起来很慢!我从来没有使用过PIL,我只是回忆起在使用Python时曾遇到过它。putpixel函数非常慢!我从来没有使用过PIL,我只是回忆起在使用Python时曾在其中运行过。考虑到对于“L”映像,转换器函数最多调用256次(查看image.point文档),它比Nadia建议的要快,但没有那么快:)考虑到对于“L”image converter函数最多调用256次(查看image.point文档),它比Nadia建议的快,但没有那么快:),因为唯一的_black函数的band参数将是整数0≤band因为唯一的_black函数的band参数将是整数0≤乐队