数字化填充的等高线图

时间:2017-10-20 07:56:12

标签: contourf digitization

我有一个RGB位图。实际上它是用'jet'色图绘制的一些标量场的等高线图。我需要反转位图并获取源数据。有没有一个随时可用的ond开源工具? Python模块也可以。

1 个答案:

答案 0 :(得分:0)

嗯,正如没有人这样做的,这是一个执行这项工作的懒惰算法:

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()

感谢所有关心的人。