v Using Mean Color As A Feature - Machine Learning

Using Mean Color As A Feature

Preliminaries

# Load image
import cv2
import numpy as np
from matplotlib import pyplot as plt

Load image

# Load image as BGR
image_bgr = cv2.imread('images/plane_256x256.jpg', cv2.IMREAD_COLOR)

Calculate Mean Color Of Each Color Channel

# Calculate the mean of each channel
channels = cv2.mean(image_bgr)

# Swap blue and red values (making it RGB, not BGR)
observation = np.array([(channels[2], channels[1], channels[0])])

Show Values

# Show mean channel values
observation
array([[  90.53204346,  133.11735535,  169.03074646]])

View Mean Image Colors

# Show image
plt.imshow(observation), plt.axis("off")
plt.show()

png