I am attempting to calculate the mean RGB values for the an image using python. I found an acceptable method using numpy here.
How to find the average colour of an image in Python with OpenCV?
I am able to calculate the mean RGB values using the example image in the above answer, but I am not able to calculate the mean RGB values of my image (bellow).
import os
import cv2
import numpy as np
path = ('C:/images')
img = cv2.imread(path + '/1049.jpg', 0)
img = np.array(img)
average = img.mean(axis=0).mean(axis =0)
print(average)
I get the following error.
Traceback (most recent call last):
File "c:/Users/isaac_madsen/Google Drive/Rhizoc_2018/image_stats.py", line 21, in <module>
average = img.mean(axis=0).mean(axis =0)
File "C:\Users\isaac_madsen\AppData\Local\Continuum\anaconda3\lib\site-packages\numpy\core\_methods.py", line 57, in _mean
rcount = _count_reduce_items(arr, axis)
File "C:\Users\isaac_madsen\AppData\Local\Continuum\anaconda3\lib\site-packages\numpy\core\_methods.py", line 50, in _count_reduce_items
items *= arr.shape[ax]
IndexError: tuple index out of range
I found this answer to a similar question on asymmetric arrays, but I am unsure how to implement the solution in my particular case, or if I am actually dealing with an asymmetric array.