【问题标题】:mean projections along image array axes in pythonpython中沿图像数组轴的平均投影
【发布时间】:2017-02-17 13:14:14
【问题描述】:

有没有一种简单的方法来绘制 2D 数据,该方法是沿图像两侧的 x 轴和 y 轴的像素强度?类似于 seaborn 的 jointplot (doc) 但使用 2D numpy 数组作为输入?或者也许numpy数组可以很容易地转换成可以散点图的形式?

下面是一个丑陋的解决方法,我将图像转换为 x 和 y 坐标。然后,我可以使用jointplot,但图像输出很丑。

img=#some 2d image data
xx=np.zeros(img.sum())
yy=np.zeros(img.sum())
i=0
for x in range(img.shape[0]):
    for y in range(img.shape[1]):
        for c in range(img[x,y]):
            xx[i]=x
            yy[i]=y
            i+=1

import seaborn as sns            
sns.jointplot(yy,xx)

【问题讨论】:

  • 不清楚您对沿 x 或 y 轴的像素强度直方图的期望。你能详细说明一下吗?
  • 我在这里找到了一个很好的解决方案:stackoverflow.com/questions/20525983/…
  • 不像 seaborn 那样光滑,但一个好的开始
  • 您找到的解决方案将图像的均值绘制在每个轴上。这与直方图不同。那么你真正追求的是什么?该解决方案的离散(条形图)版本?
  • 你是对的,我应该说'图像的意思'。我调整了这个问题

标签: python pandas numpy seaborn


【解决方案1】:

受我评论中link 中的建议的启发,我想出了以下美化版本:

from matplotlib import gridspec
img=tmp
fig=plt.figure(figsize=(6, 6))
t = np.arange(img.shape[0])
f = np.arange(img.shape[1])
flim = (f.min(), f.max())
tlim = (t.min(), t.max())


gs = gridspec.GridSpec(2, 2, width_ratios=[5,1], height_ratios=[1,5])
gs.update(hspace=0, wspace=0)
ax = fig.add_subplot(gs[1,0])
axl = fig.add_subplot(gs[1,1], sharey=ax)
axb = fig.add_subplot(gs[0,0], sharex=ax)
plt.setp(axl.get_yticklabels(), visible=False)
plt.setp(axb.get_xticklabels(), visible=False)
plt.setp(axl.get_xticklabels(), visible=False)
plt.setp(axb.get_yticklabels(), visible=False)

ax.imshow(img, origin='lower',aspect='equal')

axl.fill_between(img.mean(1), f)
axb.fill_between(t, img.mean(0))
ax.set_xlim(tlim)
ax.set_ylim(tlim)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2021-09-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-02-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多