Image.point() method in Python PIL
Let’s learn image.point() method of PIL in Python with simple examples.
Below I have written a program that opens the image that we are using.
#for opening the image we are using from PIL import Image im = Image.open("img2.jpg") im.show()
Output:
Now through examples, we are gonna see how this Image.point( ) method works.
First Example:
from PIL import Image im = Image.open("img2.jpg") # using point function threshold = 120 im = im.point(lambda p: p > threshold and 255) im.show()
Output:
Second Example:
from PIL import Image im = Image.open("img2.jpg") # using point function threshold = 191 im = im.point(lambda p: p > threshold and 255) im.show()
Output:
Third Example:
from PIL import Image im = Image.open("img2.jpg") # using point function threshold = 90 im = im.point(lambda p:p > threshold and 250 ) im.show()
Output:
Since in each program the threshold value is different, therefore they have different outputs. Hence, you can vary the threshold value as your wish and can get the desired output.
Leave a Reply