Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import cv2
- import numpy as np
- # Minimum percentage of pixels of same hue to consider dominant colour
- MIN_PIXEL_CNT_PCT = (1.0/20.0)
- image = cv2.imread('colourblobs.png')
- image_hsv = cv2.cvtColor(image, cv2.COLOR_BGR2HSV)
- h,_,_ = cv2.split(image_hsv)
- bins = np.bincount(h.flatten())
- peaks = np.where(bins > (h.size * MIN_PIXEL_CNT_PCT))[0]
- for i,peak in enumerate(peaks):
- mask = cv2.inRange(h, peak, peak)
- blob = cv2.bitwise_and(image, image, mask=mask)
- cv2.imwrite("colourblobs-%d-hue_%03d.png" % (i, peak), blob)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement