ocsvm_segmentation.py 文件源码

python
阅读 24 收藏 0 点赞 0 评论 0

项目:initialisation-problem 作者: georgedeath 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号