I am quite new to python, therefore I might risk a duplicate (but I don't know how to ask the web yet).
I have coded the following method. It converts an array(ROWS,COLS,3) to array(ROWS,COLS,1)
def convert_greyscale( rgb ):
rgb_greyscale = np.zeros( (rgb.shape[0],rgb.shape[1]), dtype=np.uint8)
for row in range(0, rgb.shape[0]:
for col in range(0, rgb.shape[1]):
rgb_greyscale[row][col] = int(0.2126 * rgb[row][col][0] + 0.7152 * rgb[row][col][1] + 0.0722 * rgb[row][col][2])
return rgb_greyscale
Sadly I wasn't able to reproduce it shorter. There is already a post where someone already mentioned a solution with np.dot, however it is not the same result as my small function.
How can I rewrite this code using more efficient (lambda) or at least more elegant expressions?
And is this method efficient?