Joseph Drackey

Generation

generate functionTue, 28 Mar 2023

Converts an image to grayscale using the crude average of the r, g, and b

def to_gray(image): # image is a 3d numpy array (x, y, z) = image.shape gray = np.zeros((x, y)) for i in range(x): for j in range(y): gray[i][j] = (image[i][j][0] + image[i][j][1] + image[i][j][2]) / 3 return gray img = np.zeros((2, 2, 3)) # blue image, 2x2 to_gray(img)

Questions about programming?Chat with your personal AI assistant