将RGB图像转换为索引(标签)数组

时间:2018-10-18 03:49:49

标签: python image numpy

我有很多重复像素的图像。 因此,我想创建标签图像。

例如,我将使用arr_u_rs数组的元素作为标签值

# Load origianl image
im = Image.open(img_path)
arr = np.array(im)

# -------------------------
arr=arr.reshape(-1,3)
# Shape is (921600, 3)

# Remove duplicated pixels
arr_u_rs = np.unique(arr, axis=0)
# Shape is (65566, 3)

我想创建65566个标签
并希望将每个标签分配到原始图像中

例如,

Assign 0 (label) into [0,1,2] pixel
Assign 1 (label) into [3,4,5] pixel
Assign 3 (label) into [12,13,14] pixel from
[[[ 0,  1,  2],
  [ 3,  4,  5],
  [ 0,  1,  2],
  [ 0,  1,  2]],
 [[12, 13, 14],
  [ 0,  1,  2],
  [ 3,  4,  5],
  [ 3,  4,  5]]]

0 个答案:

没有答案