Joseph Drackey

Generation

generate functionTue, 28 Mar 2023

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

def convertToGray(img): # loop over each pixel for r in range(img.shape[0]): for c in range(img.shape[1]): # get the avg of the r, g, b values avg = int((img[r, c, 0] + img[r, c, 1] + img[r, c, 2])/3) # set the pixel to the avg value img[r, c] = [avg, avg, avg] return img

Questions about programming?Chat with your personal AI assistant