I am trying to extract features of multiple images located in a specific folder ('image'). I want to insert this features (grayscale, R,G,B, alpha, height and width) into a table using tabulate package. The main issue is to iterate over the folder and extract the average values of the single Red, Green, Blue channels and, also to obtain the value of gray (if an image is present in that scale). After that, I would like to insert all information into the table. I am not able to do any of this operation. I've tried a this code, but it gives me many pixels values. I'd like to get the average value, so JUST ONE NUMBER for each channel. Please, anybody can help?
import os
import numpy as np
import cv2
for img in os.listdir(image_path):
img = cv2.imread(os.path.join(image_path, img))
r,g,b = cv2.split(img)
rgb_img = cv2.merge((r,g,b))
x,y,z = np.shape(img)
red = np.zeros((x,y,z),dtype=int)
green = np.zeros((x,y,z),dtype=int)
blue = np.zeros((x,y,z),dtype=int)
for i in range(0,x):
for j in range(0,y):
red[i][j][0] = rgb_img[i][j][0]
green[i][j][1]= rgb_img[i][j][1]
blue[i][j][2] = rgb_img[i][j][2]
I don't know any method else, can anybody suggests one? I would really appreciate. Thank you
