Jul-11-2020, 12:58 PM
(This post was last modified: Jul-11-2020, 12:58 PM by chesschaser.)
Hi guys!
I've been trying to invert the pixel colours of an image of Harry Potter for about 2 days now. I have a list of RGB tuples that make up each pixel of the image. I want to convert each of those tuples to a list so I can edit them. I've tried list comprehension and it didn't work. I've tried mapping and it didn't work either. I also tried this:
This is my code:
I've been trying to invert the pixel colours of an image of Harry Potter for about 2 days now. I have a list of RGB tuples that make up each pixel of the image. I want to convert each of those tuples to a list so I can edit them. I've tried list comprehension and it didn't work. I've tried mapping and it didn't work either. I also tried this:
from PIL import Image import PIL.ImageOps image = Image.open('your_image.png') inverted_image = PIL.ImageOps.invert(image) inverted_image.save('new_name.png')And that didn't work.
This is my code:
from PIL import Image import numpy as np im = Image.open('harrypotter.png') pixels = list(im.getdata()) width, height = im.size pixels = [pixels[i * width:(i + 1) * width] for i in range(height)] pixels_list = list(pixels) for i in range(0, len(pixels_list)): for k in range(0, len(pixels_list[i][i])): pixels_list[i][i][k] = pixels_list[i][i][k] - (pixels_list[i][i][k] * 2) array = np.array(pixels_list, dtype = np.uint8) new_image = Image.fromarray(array) new_image.show()I would be grateful if anyone could help