I have an image represented by a numpy.array matrix nxm of triples (r,g,b) and I want to convert it into grayscale, , using my own function.
My attempts fail converting the matrix nxmx3 to a matrix of single values nxm, meaning that starting from an array [r,g,b] I get [gray, gray, gray] but I need gray.
i.e. Initial colour channel : [150 246 98].
After converting to gray : [134 134 134].
What I need : 134
How can I achieve that?
My code:
def grayConversion(image):
height, width, channel = image.shape
for i in range(0, height):
for j in range(0, width):
blueComponent = image[i][j][0]
greenComponent = image[i][j][1]
redComponent = image[i][j][2]
grayValue = 0.07 * blueComponent + 0.72 * greenComponent + 0.21 * redComponent
image[i][j] = grayValue
cv2.imshow("GrayScale",image)
return image

