簡體   English   中英

數字化填充的輪廓圖

[英]Digitize a filled contour plot

我有一個RGB位圖。 實際上,這是使用“噴射”色圖繪制的某些標量場的輪廓圖。 我需要反轉位圖並獲取源數據。 是否有一個現成的ond開源工具? Python模塊也可以。

嗯,就像沒人做的那樣,這是一個懶惰的算法,可以完成這項工作:

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

感謝所有關心的人。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM