PIL方法记录

1. Image.point() 通过查找表或函数来映射图像(图像的像素级操作)

    def point(self, lut, mode=None):
        """
        Maps this image through a lookup table or function.

        :param lut: A lookup table, containing 256 (or 65536 if
           self.mode=="I" and mode == "L") values per band in the
           image.  A function can be used instead, it should take a
           single argument. The function is called once for each
           possible pixel value, and the resulting table is applied to
           all bands of the image.

           It may also be an :py:class:`~PIL.Image.ImagePointHandler`
           object::

               class Example(Image.ImagePointHandler):
                 def point(self, data):
                   # Return result
        :param mode: Output mode (default is same as input).  In the
           current version, this can only be used if the source image
           has mode "L" or "P", and the output has mode "1" or the
           source image mode is "I" and the output mode is "L".
        :returns: An :py:class:`~PIL.Image.Image` object.
        """

参数:

lut:一个查找表,在图像中每个波段包含256个值(如果self.mode ==“ I”且mode == “L”,则为65336)。可以改用函数,它应使用单个参数。对每个可能的像素值调用一次该函数,并将结果表应用于图像的所有波段。

mode:输出模式(默认与输入相同)。在当前版本中,仅当源图像的模式为“L”或“P”且输出的图像模式为“1”或源图像的模式为“I”且输出模式为“L”时,才可以使用此选项。

返回值:Image对象。
PIL方法记录_第1张图片

# importing Image class from PIL package  
from PIL import Image  
  
# creating a object  
im = Image.open(r"C:\Users\System-Pc\Desktop\home.png")  
  
# using point function 
threshold = 120  
im = im.point(lambda p:p > threshold and 255) 
im.show()

输出:
PIL方法记录_第2张图片

你可能感兴趣的:(CV图像分割,python,开发语言)