Created
January 10, 2019 22:56
-
-
Save andrisgauracs/d876674a486f6c02123389e763f57dc3 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Courtesy of https://www.pyimagesearch.com/2014/05/26/opencv-python-k-means-color-clustering/ | |
| def centroid_histogram(clt): | |
| # grab the number of different clusters and create a histogram | |
| # based on the number of pixels assigned to each cluster | |
| numLabels = np.arange(0, len(np.unique(clt.labels_)) + 1) | |
| (hist, _) = np.histogram(clt.labels_, bins=numLabels) | |
| # normalize the histogram, such that it sums to one | |
| hist = hist.astype("float") | |
| hist /= hist.sum() | |
| # return the histogram | |
| return hist |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment