I am trying to change the value of the pixels of an image using Image from PIL library. As you can see in my code the first thing i do is load the image and convert it to a gray scale. Next I get the data of the pixels and load it to a list and normalize that list. After that i read again the list and make the changes with the conditions i need, but now i dont know how to apply this changes to the images. What should I do? from PIL import Image
img_path = "image01.png"
img = Image.open(img_path).convert('L')
pixel_values = list(img.getdata())
print(pixel_values[10:15])
# Normalizamos la imagen
for i in range(len(pixel_values)):
pixel_values[i] = pixel_values[i]/255
print(pixel_values[10:15])
# Modificamos los valores de los pixeles (blanco = 1 y negro = 0)
max_black = 0.05
for i in range(len(pixel_values)):
if pixel_values[i] <= max_black:
pixel_values[i] = 0
else:
pixel_values[i] = 1
print(pixel_values[10:15])
# Update
img2 = Image.new('L', img.size)
img2.putdata(pixel_values)
img2.save(".\\prueba_2\\image01_new.png")