I am working with .png
files, having pixels values 1
and 255
.
I have to map pixel values 255
to 0
and, in other cases, pixels with values 1
to 2
.
I tried:
for img_name in good_imgs:
img = Image.open(img_name)
pixels = img.load()
for i in range(img.size[0]):
for j in range(img.size[1]):
if pixels[i,j] == 255:
pixels[i,j] = 0
img.save(img_name)
for img_name in bad_imgs:
img = Image.open(img_name)
pixels = img.load()
for i in range(img.size[0]):
for j in range(img.size[1]):
if pixels[i,j] == 255:
pixels[i,j] = 0
elif pixels[i,j] == 1:
pixels[i,j] == 2
img.save(img_name)
but the images saved in this way, have the same pixels values as the originals.
What is wrong with the above code? How can I change pixels values in this kind of images?
Updtate:
I have noticed that if I modified the pixel of a single image, the pixels are mapped correctly, i.e. now I suppose the issue is about saving images with img.save()