Skip to content

Instantly share code, notes, and snippets.

@stefanv
Created November 26, 2012 04:24
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save stefanv/4146612 to your computer and use it in GitHub Desktop.
Save stefanv/4146612 to your computer and use it in GitHub Desktop.
Reverse colormap
from skimage import io as sio
import skimage
import numpy as np
import matplotlib
import matplotlib.pyplot as plt
img = skimage.img_as_float(sio.imread('im2.tif'))
jet = plt.cm.jet
jet._init()
lut = jet._lut[..., :3]
z = img - lut[:, None, None, :]
z *= z
d = z.sum(axis=-1)
out = d.argmin(axis=0)
f, (ax0, ax1, ax2) = plt.subplots(1, 3)
ax0.imshow(img, cmap=plt.cm.gray)
ax1.imshow(out, cmap=plt.cm.gray)
ax2.imshow(out, cmap=plt.cm.jet)
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment