disp.py 文件源码

python
阅读 27 收藏 0 点赞 0 评论 0

项目:hart 作者: akosiorek 项目源码 文件源码
def _tile_vertical(imgs, glimpses, boxes, n_objects, fig_size, img_size, colors):
    # prepare figure
    yy, xx = imgs.shape[0], 1 + n_objects
    fig_y, fig_x = fig_size
    img_y, img_x = img_size

    sy, sx = yy * img_y, n_objects + img_x
    gs = gridspec.GridSpec(sy, sx)
    fig = plt.figure(figsize=(sx * fig_x, sy * fig_y))

    axes = np.empty((yy, xx), dtype=object)
    ii = 0
    for i in xrange(yy):
        axes[i, 0] = plt.subplot(gs[i * img_y:(i + 1) * img_y, :img_x])

    for i in xrange(yy):
        for j in xrange(1, xx):
            axes[i, j] = plt.subplot(gs[i * img_y:(i + 1) * img_y, j + img_x - 1])

    # plot
    for r in xrange(yy):
        axes[r, 0].imshow(imgs[r], 'gray')

        for n in xrange(n_objects):
            for (k, v), color in izip(boxes.iteritems(), colors):
                y, x, h, w = boxes[k]
                bbox = Rectangle((x[r, n], y[r, n]), w[r, n], h[r, n],
                                 edgecolor=color, facecolor='none', label=k)
                axes[r, 0].add_patch(bbox)

        for c in xrange(1, xx):
            axes[r, c].imshow(glimpses[r, c - 1], 'gray')

    # TODO: improve
    len_bbox = len(boxes)
    if len_bbox > 1:
        x_offset = .25 * len_bbox
        axes[-1, 0].legend(bbox_to_anchor=(x_offset, -.75),
                           ncol=len_bbox, loc='lower center')

    return fig, axes
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号