What is the best way to use Numpy to convert an rgb size array of size (x, y, 3) to an array of sizes (x, y, 1) of grayscale values?
I have a function rgbToGrey (rgbArray) that can take an array [r, g, b] and return a gray scale value. I would like to use it together with Numpy to compress the 3rd dimension of my array from size 3 to size 1.
How can i do this?
Note. It would be very easy if I had the original image, and I could use Pillow in grayscale at first, but I donβt have it.
UPDATE:
The function I was looking for was np.dot().
From the answer to this question :
Assuming we convert rgb to gray scale through the formula:
.3r * .6g * .1b = gray,
we can do np.dot(rgb[...,:3], [.3, .6, .1])to get what I'm looking for, a 2d array of gray-only values.
source
share