将传感器强度值转换为 python 中的像素强度
Transform sensor intensity values to pixel intensity in python
我有一个大小为 88 的矢量 A= [n1,n2,...,n88] 矢量的每个值都有一个传感器电压强度读数,范围从 0 到 1。我想转换这些强度值到像素强度值,如下图所示:
该图像具有 280 x 420 像素,其中 88 个传感器均匀分布。白色代表读数为 0,黑色代表读数为 1。
有人可以告诉我如何使用 matplotlib 在 Python 中实现这个吗?
谢谢。
from pylab import figure, show, rand, colorbar
from matplotlib.patches import Ellipse
from matplotlib.collections import PatchCollection
from matplotlib import cm
#dummy data
A = rand(88)
#todo: are the i and j loops in the right order for the data?
spots = [Ellipse(xy=(i*475/11. + 18,j*275/8. + 16 + 16*(i%2 > 0)),
width=20, height=25)
for i in range(11) for j in range(8)]
fig = figure()
ax = fig.add_subplot(111, aspect='equal')
p = PatchCollection(spots, cmap=cm.cubehelix_r)
p.set_array(A)
p.set_edgecolor('face')
ax.add_collection(p)
colorbar(p)
ax.set_xlim(0, 420)
ax.set_ylim(280, 0)
show()
我有一个大小为 88 的矢量 A= [n1,n2,...,n88] 矢量的每个值都有一个传感器电压强度读数,范围从 0 到 1。我想转换这些强度值到像素强度值,如下图所示:
from pylab import figure, show, rand, colorbar
from matplotlib.patches import Ellipse
from matplotlib.collections import PatchCollection
from matplotlib import cm
#dummy data
A = rand(88)
#todo: are the i and j loops in the right order for the data?
spots = [Ellipse(xy=(i*475/11. + 18,j*275/8. + 16 + 16*(i%2 > 0)),
width=20, height=25)
for i in range(11) for j in range(8)]
fig = figure()
ax = fig.add_subplot(111, aspect='equal')
p = PatchCollection(spots, cmap=cm.cubehelix_r)
p.set_array(A)
p.set_edgecolor('face')
ax.add_collection(p)
colorbar(p)
ax.set_xlim(0, 420)
ax.set_ylim(280, 0)
show()