Preface:
I have an image of a coin. This is any generic image of a coin that I plug into python, and I want to make this coin a grayscale image. The variable P
represents the array containing the RGB values for the picture of the coin, and I believe that I can turn RGB to grayscale by changing any RGB values under 128
to 0
while turning any RGB values above 128
to 255
.
Error:
I am trying to use a for loop to turn the values in the array generated by P
to 0
, 128
, and 255
. When I do so this way, I encounter the error as:
TypeError: '<' not supported between instances of 'tuple' and 'int' ".
Code:
import numpy as np
import matplotlib.pyplot as plt
P = plt.imread('coin.jpg')
for item in enumerate(P):
if item < 128:
item = 0
elif item > 128:
item = 255