我有RGB位图。实际上,这是一个标量场的等高线图,用“jet”颜色图绘制。我需要反转位图并获取源数据。有现成的开放源码工具吗?Python模块也可以。
发布于 2017-10-20 21:06:45
嗯,因为没人这么做,这是一种完成任务的简单算法:
import numpy as np
import scipy.misc
import matplotlib.pyplot as plt
## The digitized field will be scaled to range (0,1)
scale = np.linspace(0.0, 1.0, 300)
## Palette is a curve in RGB space
jet = plt.cm.get_cmap('jet')
palette = 255.0 * np.array([ jet(s)[:3] for s in scale ])
## Read the field as RGB image
field_0 = scipy.misc.imread('field.png')[:,:,:3]
ny, nx, _ = field_0.shape
## Use Euclidian norm to find a closest point in the palette
dist = lambda v : np.array([ np.linalg.norm(p - v) for p in palette ])
field = np.array([ [ scale[np.argmin(dist(field_0[i,j]))]
for j in range(nx) ]
for i in range(ny)[::-1] ])
## Plot
fig, ax = plt.subplots(1, 2)
ax[0].imshow(field_0)
ax[1].contourf(field, cmap='gray')
plt.show()感谢所有关心我的人。
https://stackoverflow.com/questions/46844650
复制相似问题