1

Let's say I have an image which range in value from 0 to 255.

image = np.asarray([[i for i in range(256)] for j in range(256)])

Now if I want to visualize it I usually use

plt.imshow(image, cmap="jet")

But I've googled and found nothing to convert from the visualized image back to actual image value.

My attempt is to map every point in color-space back to its original value, and it is very time consuming. Then I (hopefully) can map every pixel color back it its original space.

cmap = matplotlib.cm.get_cmap('hsv')

# Creating inverse map of cmap
cmap_map = np.zeros((256, 256, 256))
step = 1/(256**3)
for i in tqdm(np.arange(0, 1 + step, step), position=0):
    cmap_map[np.round(np.array(cmap(i)[:-1])*255).astype(dtype=np.int)] = i

Is there a better method to convert? (Noted that cmap should be arbitary)

Wakeme UpNow
  • 523
  • 1
  • 4
  • 22

0 Answers0