0

I have been tasked with applying the mean aggregation function to find the average of values across different channels in my photo and putting the result in new array.

What ends up happening is that I get a big gray photo instead of a grayscale photo.

I think I need to find the mean of each channel but am unsure of how to proceed.

Here is my code I have.

New_Greece_Gray_Scale = np.array(mpimg.imread('Greece.jpg'))
print("Total mean:", New_Greece_Gray_Scale.mean())

New_Greece_Gray_Scale[:,:,0] = 161.93223291599233
New_Greece_Gray_Scale[:,:,1] = 161.93223291599233
New_Greece_Gray_Scale[:,:,2] = 161.93223291599233

fig, ax = plt.subplots(figsize=(12, 18))
ax.imshow(New_Greece_Gray_Scale)
ax.set(xticks=[], yticks=[])

plt.show()

Greece_image.shape
Christoph Rackwitz
  • 11,317
  • 4
  • 27
  • 36
  • 1
    [numpy.mean](https://numpy.org/doc/stable/reference/generated/numpy.mean.html#numpy-mean) has an `axis` argument. Look for examples, how to use it. – Rotem Sep 16 '22 at 08:28
  • Does this answer your question? [Calculate mean across dimension in a 2D array](https://stackoverflow.com/questions/15819980/calculate-mean-across-dimension-in-a-2d-array) – Jody Klymak Sep 17 '22 at 22:56

0 Answers0