Skip to content

Instantly share code, notes, and snippets.

@Jojozzc
Created March 10, 2019 07:34
Show Gist options
  • Save Jojozzc/ac60ef836ed85843270220f3db52730d to your computer and use it in GitHub Desktop.
Save Jojozzc/ac60ef836ed85843270220f3db52730d to your computer and use it in GitHub Desktop.
image helper
def color_kinds(img):
color_set = set()
if np.ndim(img) == 2:
channel_num = 1
elif np.ndim(img) >= 3:
channel_num = np.size(img, np.ndim(img) - 1)
else:
print('unknow img format')
return color_set
print('img real channel:{}'.format(channel_num))
for i in range(np.shape(img)[0]):
for j in range(np.shape(img)[1]):
color_str = ''
if channel_num == 1:
color_str = str(img[i][j])
else:
for c in range(channel_num):
color_str = color_str + ' ' + str(img[i][j][c])
color_set.add('({})'.format(color_str))
return color_set
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment