Concept

Point Operations (Pillow)

The point() method in image instances can be used to transform each pixel through using a function that is applied to each pixel. This generally follows the below syntax:

output= image.point(lambda i: expression)

For example, the below will select all pixels and multiply them by 1.2:

image.point(lambda i: i * 1.2)

The below will change the threshold of the image to a value of 120.

threshold = 120 image= image.point(lambda p: p > threshold and 255) image.show()

Notice the "and 255" added to the expression used for the argument.. Python returns the last value examined and uses that for pixel manipulation. If p is less than the threshold value, it will not look at the "and 255" part of the expression and thus return 0. If p is greater than the threshold value, then it will look at the "and 255" portion and thus return 255.

0

1

Updated 2021-07-25

Contributors are:

Who are from:

Tags

Python Programming Language

Data Science