I am trying to create a program that removes only the "r" and "b" of an image's rgb values, leaving an image of varying shades of green. Here is my code:
import matplotlib.pyplot as plt
from PIL import Image
im = Image.open('Image.jpg')
rgb_im = im.convert('RGB')
width, height = rgb_im.size
for x in range(width):
for y in range(height):
r, g, b = rgb_im.getpixel((x, y))
im[x][y] = [0, g, 0, 255]
fig, ax = plt.subplots(1, 1)
ax.imshow(im, interpolation='none')
fig.show()
I am very new to programming and don't understand why my code is throwing this error:
AttributeError: __getitem__
Could anyone explain how to fix this or recommend a better solution?
AttributeError: __getitem__