Skip to content

Instantly share code, notes, and snippets.

@dolaameng
Created April 14, 2017 03:42
Show Gist options
  • Save dolaameng/03dde943e7a4abc8edec4aa8bd7d0550 to your computer and use it in GitHub Desktop.
Save dolaameng/03dde943e7a4abc8edec4aa8bd7d0550 to your computer and use it in GitHub Desktop.
color_hist
def color_hist(img, nbins=32, bins_range=(0, 256)):
# Compute the histogram of the color channels separately
channel1_hist = np.histogram(img[:,:,0], bins=nbins, range=bins_range)
channel2_hist = np.histogram(img[:,:,1], bins=nbins, range=bins_range)
channel3_hist = np.histogram(img[:,:,2], bins=nbins, range=bins_range)
# Concatenate the histograms into a single feature vector
hist_features = np.concatenate((channel1_hist[0], channel2_hist[0], channel3_hist[0]))
# Return the individual histograms, bin_centers and feature vector
return hist_features
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment