I extracted an object from an image, so now I have a masked image with a tennis ball and a black background.
I want to extract the color features from the tennis ball alone via a histogram. This is the code I have so far, but by the looks of the histogram, the black background dominates the any of the other colors, which makes the histogram ineffective:
from PIL import Image
from pylab import *
# Import image and convert to gray
image = Image.open("res_300.png")
im = image.convert('L')
im_array = array(im)
# Create a new figure
figure()
gray()
# Show contours with origin upper left corner
contour(im, origin='image')
axis('equal')
axis('off')
# Create histogram
figure()
hist(im_array.flatten(), 128)
show()
Is there a way to draw the histogram from the tennis ball BGR color features while disregarding the black background?
I'm a python rookie. Thank you.