arr2 = arr.reshape((arr.shape[0] * arr.shape[1], arr.shape[2]))
code, dist = scv.vq(arr2, gradient)
values = code.astype('float') / gradient.shape[0]
values = values.reshape(arr.shape[0], arr.shape[1])
values = values[::-1]
return values
arr = plt.imread('mri_demo.png')
values = colormap2arr(arr, cm.jet)
plt.imshow(values, interpolation='bilinear', cmap=cm.jet, origin='lower',
    extent=[-3, 3, -3, 3])
plt.show()
how to reverse color map image to scalar values