def color_hist(im, colBins):
"""
Get color histogram descriptors for RGB and LAB space.
Input: im: (h,w,c): 0-255: np.uint8: RGB
Output: descriptor: (colBins*6,)
"""
assert im.ndim == 3 and im.shape[2] == 3, "image should be rgb"
arr = np.concatenate((im, color.rgb2lab(im)), axis=2).reshape((-1, 6))
desc = np.zeros((colBins * 6,), dtype=np.float)
for i in range(3):
desc[i * colBins:(i + 1) * colBins], _ = np.histogram(
arr[:, i], bins=colBins, range=(0, 255))
desc[i * colBins:(i + 1) * colBins] /= np.sum(
desc[i * colBins:(i + 1) * colBins]) + (
np.sum(desc[i * colBins:(i + 1) * colBins]) < 1e-4)
i += 1
desc[i * colBins:(i + 1) * colBins], _ = np.histogram(
arr[:, i], bins=colBins, range=(0, 100))
desc[i * colBins:(i + 1) * colBins] /= np.sum(
desc[i * colBins:(i + 1) * colBins]) + (
np.sum(desc[i * colBins:(i + 1) * colBins]) < 1e-4)
for i in range(4, 6):
desc[i * colBins:(i + 1) * colBins], _ = np.histogram(
arr[:, i], bins=colBins, range=(-128, 127))
desc[i * colBins:(i + 1) * colBins] /= np.sum(
desc[i * colBins:(i + 1) * colBins]) + (
np.sum(desc[i * colBins:(i + 1) * colBins]) < 1e-4)
return desc
评论列表
文章目录