首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >数字化填充等高线图

数字化填充等高线图
EN

Stack Overflow用户
提问于 2017-10-20 07:56:12
回答 1查看 682关注 0票数 1

我有RGB位图。实际上,这是一个标量场的等高线图,用“jet”颜色图绘制。我需要反转位图并获取源数据。有现成的开放源码工具吗?Python模块也可以。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-10-20 21:06:45

嗯,因为没人这么做,这是一种完成任务的简单算法:

代码语言:javascript
复制
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()

感谢所有关心我的人。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/46844650

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档