def extract_colour_histogram(image, labels, n_bins=8, use_lab=False):
ih, iw, _ = image.shape
n_labels = labels.max()+1
_range = np.array([[0, 256], [0, 256], [0, 256]], dtype='float') # for rgb histograms
if use_lab:
image = rgb2lab(image)
_range[:] = [[0,100],[-500*25/29, 500*25/29], [-200*25/29, 200*25/29]]
hist = np.zeros((n_labels, n_bins**3))
mask = np.zeros((ih, iw), dtype='bool')
for i in range(n_labels):
mask[:] = labels == i
yy, xx = mask.nonzero()
pixels = image[yy, xx, :]
hist[i, :] = np.histogramdd(sample=pixels, bins=n_bins, range=_range)[0].flat
return hist
ocsvm_segmentation.py 文件源码
python
阅读 24
收藏 0
点赞 0
评论 0
评论列表
文章目录