Пример #1
0
 def _distplot(dists, color, label, distkey, plot_type=plot_type):
     data = sorted(dists)
     ax = df2.gca()
     min_ = distkey2_min[distkey]
     max_ = distkey2_max[distkey]
     if plot_type == 'plot':
         df2.plot(data, color=color, label=label, yscale='linear')
         #xticks = np.linspace(np.min(data), np.max(data), 3)
         #yticks = np.linspace(0, len(data), 5)
         #ax.set_xticks(xticks)
         #ax.set_yticks(yticks)
         ax.set_ylim(min_, max_)
         ax.set_xlim(0, len(dists))
         ax.set_ylabel('distance')
         ax.set_xlabel('matches indexes (sorted by distance)')
         df2.legend(loc='lower right')
     if plot_type == 'pdf':
         df2.plot_pdf(data, color=color, label=label)
         ax.set_ylabel('pr')
         ax.set_xlabel('distance')
         ax.set_xlim(min_, max_)
         df2.legend(loc='upper left')
     df2.dark_background(ax)
     df2.small_xticks(ax)
     df2.small_yticks(ax)
Пример #2
0
 def _distplot(dists, color, label, distkey, plot_type=plot_type):
     data = sorted(dists)
     ax = df2.gca()
     min_ = distkey2_min[distkey]
     max_ = distkey2_max[distkey]
     if plot_type == 'plot':
         df2.plot(data, color=color, label=label, yscale='linear')
         #xticks = np.linspace(np.min(data), np.max(data), 3)
         #yticks = np.linspace(0, len(data), 5)
         #ax.set_xticks(xticks)
         #ax.set_yticks(yticks)
         ax.set_ylim(min_, max_)
         ax.set_xlim(0, len(dists))
         ax.set_ylabel('distance')
         ax.set_xlabel('matches indexes (sorted by distance)')
         df2.legend(loc='lower right')
     if plot_type == 'pdf':
         df2.plot_pdf(data, color=color, label=label)
         ax.set_ylabel('pr')
         ax.set_xlabel('distance')
         ax.set_xlim(min_, max_)
         df2.legend(loc='upper left')
     df2.dark_background(ax)
     df2.small_xticks(ax)
     df2.small_yticks(ax)
Пример #3
0
def test_shape(ori=0, skew=0, xscale=1, yscale=1, pnum=(1, 1, 1), fnum=1):
    df2.figure(fnum=fnum, pnum=pnum)
    kpts, sifts = test_keypoint(ori=ori,
                                skew=skew,
                                xscale=xscale,
                                yscale=yscale)
    ax = df2.gca()
    square_axis(ax)
    mpl_keypoint.draw_keypoints(ax,
                                kpts,
                                sifts=sifts,
                                ell_color=df2.ORANGE,
                                ori=True,
                                rect_color=df2.DARK_RED,
                                ori_color=df2.DEEP_PINK,
                                eig_color=df2.PINK,
                                rect=True,
                                eig=True,
                                bin_color=df2.RED,
                                arm1_color=df2.YELLOW,
                                arm2_color=df2.BLACK)

    kptsstr = '\n'.join(ktool.get_kpts_strs(kpts))
    #print(kptsstr)
    df2.upperleft_text(kptsstr)

    title = 'xyscale=(%.1f, %.1f),\n skew=%.1f, ori=%.2ftau' % (
        xscale, yscale, skew, ori / TAU)
    df2.set_title(title)
    df2.dark_background()
    return kpts, sifts
Пример #4
0
def show_name(ibs, nid, nid2_aids=None, in_image=True, fnum=0, sel_aids=[], subtitle='',
              annote=False, **kwargs):
    print('[viz] show_name nid=%r' % nid)
    aid_list = ibs.get_name_aids(nid)
    name = ibs.get_name_text((nid,))
    ibsfuncs.ensure_annotation_data(ibs, aid_list, chips=(not in_image or annote), feats=annote)
    print('[viz] show_name=%r aid_list=%r' % (name, aid_list))
    nAids = len(aid_list)
    if nAids > 0:
        nRows, nCols = ph.get_square_row_cols(nAids)
        print('[viz*] r=%r, c=%r' % (nRows, nCols))
        #gs2 = gridspec.GridSpec(nRows, nCols)
        pnum_ = df2.get_pnum_func(nRows, nCols)
        fig = df2.figure(fnum=fnum, pnum=pnum_(0), **kwargs)
        fig.clf()
        # Trigger computation of all chips in parallel
        for px, aid in enumerate(aid_list):
            show_chip(ibs, aid=aid, pnum=pnum_(px), annote=annote, in_image=in_image)
            if aid in sel_aids:
                ax = df2.gca()
                df2.draw_border(ax, df2.GREEN, 4)
            #plot_aid3(ibs, aid)
        if isinstance(nid, np.ndarray):
            nid = nid[0]
        if isinstance(name, np.ndarray):
            name = name[0]
    else:
        df2.imshow_null(fnum=fnum, **kwargs)

    figtitle = 'Name View nid=%r name=%r' % (nid, name)
    df2.set_figtitle(figtitle)
Пример #5
0
def annotate_matches(ibs, qres, aid2,
                     offset1=(0, 0),
                     offset2=(0, 0),
                     xywh2=(0, 0, 0, 0),
                     xywh1=(0, 0, 0, 0),
                     **kwargs):
    # TODO Use this function when you clean show_matches
    in_image    = kwargs.get('in_image', False)
    show_query  = kwargs.get('show_query', True)
    draw_border = kwargs.get('draw_border', True)
    draw_lbl    = kwargs.get('draw_lbl', True)

    printDBG('[viz] annotate_matches()')
    aid1 = qres.qaid
    truth = ibs.get_match_truth(aid1, aid2)
    truth_color = vh.get_truth_color(truth)
    # Build title
    title = vh.get_query_text(ibs, qres, aid2, truth, **kwargs)
    # Build xlbl
    ax = df2.gca()
    ph.set_plotdat(ax, 'viztype', 'matches')
    ph.set_plotdat(ax, 'qaid', aid1)
    ph.set_plotdat(ax, 'aid1', aid1)
    ph.set_plotdat(ax, 'aid2', aid2)
    if draw_lbl:
        name1, name2 = ibs.get_annot_names([aid1, aid2])
        lbl1 = repr(name1)  + ' : ' + 'q' + vh.get_aidstrs(aid1)
        lbl2 = repr(name2)  + ' : ' +  vh.get_aidstrs(aid2)
    else:
        lbl1, lbl2 = None, None
    if vh.NO_LBL_OVERRIDE:
        title = ''
    df2.set_title(title, ax)
    # Plot annotations over images
    if in_image:
        bbox1, bbox2 = vh.get_bboxes(ibs, [aid1, aid2], [offset1, offset2])
        theta1, theta2 = ibs.get_annot_thetas([aid1, aid2])
        # HACK!
        if show_query:
            df2.draw_bbox(bbox1, bbox_color=df2.ORANGE, lbl=lbl1, theta=theta1)
        bbox_color2 = truth_color if draw_border else df2.ORANGE
        df2.draw_bbox(bbox2, bbox_color=bbox_color2, lbl=lbl2, theta=theta2)
    else:
        xy, w, h = df2._axis_xy_width_height(ax)
        bbox2 = (xy[0], xy[1], w, h)
        theta2 = 0
        if draw_border:
            df2.draw_border(ax, truth_color, 4, offset=offset2)
        if draw_lbl:
            # Custom user lbl for chips 1 and 2
            (x1, y1, w1, h1) = xywh1
            (x2, y2, w2, h2) = xywh2
            df2.absolute_lbl(x1 + w1, y1, lbl1)
            df2.absolute_lbl(x2 + w2, y2, lbl2)
        # No matches draw a red box
    if aid2 not in qres.aid2_fm or len(qres.aid2_fm[aid2]) == 0:
        if draw_border:
            df2.draw_boxedX(bbox2, theta=theta2)
Пример #6
0
    def append_button(self, text, divider=None, rect=None, callback=None,
                      size='9%', location='bottom', ax=None, **kwargs):
        """ Adds a button to the current page """

        if rect is not None:
            new_ax = df2.plt.axes(rect)
        if rect is None and divider is None:
            if ax is None:
                ax = df2.gca()
            divider = df2.ensure_divider(ax)
        if divider is not None:
            new_ax = divider.append_axes(location, size=size, pad=.05)
        if callback is not None:
            color, hovercolor = u'.85', u'.95'
        else:
            color, hovercolor = u'.88', u'.88'
            #color, hovercolor = u'.45', u'.45'
        #if isinstance(text, six.text_type):
        new_but = mpl.widgets.Button(
            new_ax, text, color=color, hovercolor=hovercolor)
        #elif isinstance(text, (list, tuple)):
        #    labels = [False] * len(text)
        #    labels[0] = True
        #    new_but = mpl.widgets.CheckButtons(new_ax, text, labels)
        #else:
        #    raise ValueError('bad input')

        if callback is not None:
            new_but.on_clicked(callback)
        else:
            button_text = new_but.ax.texts[0]
            button_text.set_color('.6')
            #button_text.set_color('r')
            #ut.embed()
            #print('new_but.color = %r' % (new_but.color,))
        #else:
        # TODO: figure ou how to gray out these buttons
        #    new_but.color = u'.1'
        #    new_but.hovercolor = u'.1'
        #    new_but.active = False
        #    print('new_but.color = %r' % (new_but.color,))
        ph.set_plotdat(new_ax, 'viztype', 'button')
        ph.set_plotdat(new_ax, 'text', text)
        #ph.set_plotdat(new_ax, 'parent_axes', ax)
        if ax is not None:
            child_axes = ph.get_plotdat(ax, 'child_axes', [])
            child_axes.append(new_ax)
            ph.set_plotdat(ax, 'child_axes', child_axes)
        for key, val in six.iteritems(kwargs):
            ph.set_plotdat(new_ax, key, val)
        # Keep buttons from losing scrop
        tup = (new_but, new_ax)
        self.scope.append(tup)
        return tup
Пример #7
0
    def test_shape(ori=0, skew=0, xscale=1, yscale=1, pnum=(1, 1, 1), fnum=1):
        df2.figure(fnum=fnum, pnum=pnum)
        kpts, sifts = test_keypoint(ori=ori, skew=skew, xscale=xscale, yscale=yscale)
        ax = df2.gca()
        square_axis(ax)
        mpl_keypoint.draw_keypoints(ax, kpts, sifts=sifts, ell_color=df2.ORANGE, ori=True,
                                    rect_color=df2.DARK_RED,
                                    ori_color=df2.DEEP_PINK, eig_color=df2.PINK,
                                    rect=True, eig=True, bin_color=df2.RED,
                                    arm1_color=df2.YELLOW, arm2_color=df2.BLACK)

        kptsstr = '\n'.join(ktool.get_kpts_strs(kpts))
        #print(kptsstr)
        df2.upperleft_text(kptsstr)

        title = 'xyscale=(%.1f, %.1f),\n skew=%.1f, ori=%.2ftau' % (xscale, yscale, skew, ori / TAU)
        df2.set_title(title)
        df2.dark_background()
        return kpts, sifts
Пример #8
0
def show_multiple_chips(ibs,
                        aid_list,
                        in_image=True,
                        fnum=0,
                        sel_aids=[],
                        subtitle='',
                        annote=False,
                        **kwargs):
    """
    CommandLine:
        python -m ibeis.viz.viz_name --test-show_multiple_chips --show --no-inimage
        python -m ibeis.viz.viz_name --test-show_multiple_chips --show --db NNP_Master3 --aids=6435,9861,137,6563,9167,12547,9332,12598,13285 --no-inimage --notitle
        python -m ibeis.viz.viz_name --test-show_multiple_chips --show --db NNP_Master3 --aids=137,6563,12547,9332,12598,13285 --no-inimage --notitle --adjust=.05
        python -m ibeis.viz.viz_name --test-show_multiple_chips --show --db NNP_Master3 --aids=6563,9332,13285,12598 --no-inimage --notitle --adjust=.05 --rc=1,4
        python -m ibeis.viz.viz_name --test-show_multiple_chips --show --db PZ_Master0 --aids=1288 --no-inimage --notitle --adjust=.05
        python -m ibeis.viz.viz_name --test-show_multiple_chips --show --db PZ_Master0 --aids=4020,4839 --no-inimage --notitle --adjust=.05

        python -m ibeis.viz.viz_name --test-show_multiple_chips --db NNP_Master3 --aids=6524,6540,6571,6751 --no-inimage --notitle --adjust=.05 --diskshow

        python -m ibeis.viz.viz_name --test-show_multiple_chips --db PZ_MTEST -a default:index=0:4 --show
        --aids=1 --doboth --show --no-inimage

        python -m ibeis.viz.viz_name --test-show_multiple_chips --db PZ_MTEST --aids=1 --doboth --show --no-inimage
        python -m ibeis.viz.viz_name --test-show_multiple_chips --db PZ_MTEST --aids=1 --doboth --rc=2,1 --show --no-inimage
        python -m ibeis.viz.viz_name --test-show_multiple_chips --db PZ_MTEST --aids=1 --doboth --rc=2,1 --show --notitle --trydrawline --no-draw_lbls
        python -m ibeis.viz.viz_name --test-show_multiple_chips --db PZ_MTEST --aids=1,2 --doboth  --show --notitle --trydrawline

        python -m ibeis.viz.viz_name --test-show_multiple_chips --db PZ_MTEST --aids=1,2,3,4,5 --doboth --rc=2,5 --show --chrlbl --trydrawline --qualtitle --no-figtitle --notitle
        --doboth
        --doboth --show

        python -m ibeis.viz.viz_name --test-show_multiple_chips --db NNP_Master3 --aids=15419 --doboth --rc=2,1 --show --notitle --trydrawline --no-draw_lbls

    Example:
        >>> # DISABLE_DOCTEST
        >>> from ibeis.viz.viz_name import *  # NOQA
        >>> import ibeis
        >>> ibs, aid_list, in_image = testdata_multichips()
        >>> if True:
        >>>     import matplotlib as mpl
        >>>     from ibeis.scripts.thesis import TMP_RC
        >>>     mpl.rcParams.update(TMP_RC)
        >>> fnum = 0
        >>> sel_aids = []
        >>> subtitle = ''
        >>> annote = False
        >>> fig = show_multiple_chips(ibs, aid_list, in_image, fnum, sel_aids, subtitle, annote)
        >>> ut.quit_if_noshow()
        >>> fig.canvas.draw()
        >>> ut.show_if_requested()
    """
    fnum = pt.ensure_fnum(fnum)
    nAids = len(aid_list)
    if nAids == 0:
        fig = df2.figure(fnum=fnum, pnum=(1, 1, 1), **kwargs)
        df2.imshow_null(fnum=fnum, **kwargs)
        return fig
    # Trigger computation of all chips in parallel
    ibsfuncs.ensure_annotation_data(ibs,
                                    aid_list,
                                    chips=(not in_image or annote),
                                    feats=annote)

    print('[viz_name] * annot_vuuid=%r' %
          ((ibs.get_annot_visual_uuids(aid_list), )))
    print('[viz_name] * aid_list=%r' % ((aid_list, )))

    DOBOTH = ut.get_argflag('--doboth')

    rc = ut.get_argval('--rc', type_=list, default=None)
    if rc is None:
        nRows, nCols = ph.get_square_row_cols(nAids * (2 if DOBOTH else 1))
    else:
        nRows, nCols = rc
    notitle = ut.get_argflag('--notitle')
    draw_lbls = not ut.get_argflag('--no-draw_lbls')
    show_chip_kw = dict(annote=annote,
                        in_image=in_image,
                        notitle=notitle,
                        draw_lbls=draw_lbls)
    #print('[viz_name] * r=%r, c=%r' % (nRows, nCols))
    #gs2 = gridspec.GridSpec(nRows, nCols)
    pnum_ = df2.get_pnum_func(nRows, nCols)
    fig = df2.figure(fnum=fnum, pnum=pnum_(0), **kwargs)
    fig.clf()
    ax_list1 = []
    for px, aid in enumerate(aid_list):
        print('px = %r' % (px, ))
        _fig, _ax1 = viz_chip.show_chip(ibs,
                                        aid=aid,
                                        pnum=pnum_(px),
                                        **show_chip_kw)
        print('other_aids = %r' % (ibs.get_annot_contact_aids(aid), ))
        ax = df2.gca()
        ax_list1.append(_ax1)
        if aid in sel_aids:
            df2.draw_border(ax, df2.GREEN, 4)
        if ut.get_argflag('--chrlbl') and not DOBOTH:
            ax.set_xlabel('(' + chr(ord('a') - 1 + px) + ')')
        elif ut.get_argflag('--numlbl') and not DOBOTH:
            ax.set_xlabel('(' + str(px + 1) + ')')
        #plot_aid3(ibs, aid)

    # HACK to show in image and not in image
    if DOBOTH:
        #ut.embed()
        #ph.get_plotdat_dict(ax_list1[1])
        #ph.get_plotdat_dict(ax_list2[1])
        ax_list2 = []

        show_chip_kw['in_image'] = not show_chip_kw['in_image']
        start = px + 1
        for px, aid in enumerate(aid_list, start=start):
            _fig, _ax2 = viz_chip.show_chip(ibs,
                                            aid=aid,
                                            pnum=pnum_(px),
                                            **show_chip_kw)
            ax = df2.gca()
            ax_list2.append(_ax2)

            if ut.get_argflag('--chrlbl'):
                ax.set_xlabel('(' + chr(ord('a') - start + px) + ')')
            elif ut.get_argflag('--numlbl'):
                ax.set_xlabel('(' + str(px - start + 1) + ')')

            if ut.get_argflag('--qualtitle'):
                qualtext = ibs.get_annot_quality_texts(aid)
                ax.set_title(qualtext)

            if aid in sel_aids:
                df2.draw_border(ax, df2.GREEN, 4)

        if in_image:
            ax_list1, ax_list2 = ax_list2, ax_list1

        if ut.get_argflag('--trydrawline'):
            # Unfinished
            #ut.embed()
            # Draw lines between corresponding axes
            # References:
            # http://stackoverflow.com/questions/17543359/drawing-lines-between-two-plots-in-matplotlib
            import matplotlib as mpl
            import vtool as vt
            # !!!
            #http://matplotlib.org/users/transforms_tutorial.html

            #invTransFigure_fn1 = fig.transFigure.inverted().transform
            #invTransFigure_fn2 = fig.transFigure.inverted().transform
            #print(ax_list1)
            #print(ax_list2)
            assert len(ax_list1) == len(ax_list2)

            for ax1, ax2 in zip(ax_list1, ax_list2):
                #_ = ax1.get_window_extent().transformed(fig.dpi_scale_trans.inverted())
                #bbox1 = (0, 0, _.width * fig.dpi, _.height * fig.dpi)

                # returns in figure coordinates
                #bbox1 = df2.get_axis_bbox(ax=ax1)
                #if bbox1[-1] < 0:
                #    # Weird bug
                #    bbox1 = bbox1[1]
                print('--')
                print('ax1 = %r' % (ax1, ))
                print('ax2 = %r' % (ax2, ))
                chipshape = ph.get_plotdat(ax1, 'chipshape')
                #_bbox1 = ax1.get_window_extent().transformed(fig.dpi_scale_trans.inverted())
                #bbox1 = (0, 0, _bbox1.width * fig.dpi, _bbox1.height * fig.dpi)
                bbox1 = (0, 0, chipshape[1], chipshape[0])

                aid_ = ph.get_plotdat(ax2, 'aid')
                aid_list_ = ph.get_plotdat(ax2, 'aid_list')
                index = aid_list_.index(aid_)
                annotation_bbox_list = ph.get_plotdat(ax2,
                                                      'annotation_bbox_list')
                bbox2 = annotation_bbox_list[index]

                print('bbox1 = %r' % (bbox1, ))
                print('bbox2 = %r' % (bbox2, ))

                vert_list1 = np.array(vt.verts_from_bbox(bbox1))
                vert_list2 = np.array(vt.verts_from_bbox(bbox2))

                print('vert_list1 = %r' % (vert_list1, ))
                print('vert_list2 = %r' % (vert_list2, ))
                #for vx in [0, 1, 2, 3]:
                for vx in [0, 1]:
                    vert1 = vert_list1[vx].tolist()
                    vert2 = vert_list2[vx].tolist()
                    print('  ***')
                    print('  * vert1 = %r' % (vert1, ))
                    print('  * vert2 = %r' % (vert2, ))

                    coordsA = coordsB = 'data'
                    #coords = 'axes points'
                    #'axes fraction'
                    #'axes pixels'
                    #coordsA = 'axes pixels'
                    #coordsB = 'data'
                    #'figure fraction'
                    #'figure pixels'
                    #'figure pixels'
                    #'figure points'
                    #'polar'
                    #'offset points'

                    con = mpl.patches.ConnectionPatch(xyA=vert1,
                                                      xyB=vert2,
                                                      coordsA=coordsA,
                                                      coordsB=coordsB,
                                                      axesA=ax1,
                                                      axesB=ax2,
                                                      linewidth=1,
                                                      color='k')
                    #, arrowstyle="-")

                    #ut.embed()
                    #con.set_zorder(None)
                    ax1.add_artist(con)
                    #ax2.add_artist(con)

                    #ut.embed()

                    #verts2.T[1] -= bbox2[-1]
                    #bottom_left1, bottom_right1 = verts1[1:3].tolist()
                    #bottom_left2, bottom_right2 = verts2[1:3].tolist()

                ##transAxes1 = ax1.transData.inverted()
                #transAxes1_fn = ax1.transData.transform
                #transAxes2_fn = ax2.transData.transform

                #transAxes1_fn = ut.identity
                #transAxes2_fn = ut.identity

                #coord_bl1 = transFigure.transform(transAxes1.transform(bottom_left1))
                #coord_br1 = transFigure.transform(transAxes1.transform(bottom_right1))
                #coord_bl1 = invTransFigure_fn1(transAxes1_fn(bottom_left1))
                #print('bottom_left2 = %r' % (bottom_left2,))
                #coord_bl1 = (5, 5)
                #coord_bl2 = invTransFigure_fn2(transAxes2_fn(bottom_left2))
                #print('coord_bl2 = %r' % (coord_bl2,))

                #coord_br1 = invTransFigure_fn1(transAxes1_fn(bottom_right1))
                #coord_br2 = invTransFigure_fn2(transAxes2_fn(bottom_right2))
                ##print('coord_bl1 = %r' % (coord_bl1,))

                #line_coords1 = np.vstack([coord_bl1, coord_bl2])
                #line_coords2 = np.vstack([coord_br1, coord_br2])
                #print('line_coords1 = %r' % (line_coords1,))

                #line1 = mpl.lines.Line2D((line_coords1[0]), (line_coords1[1]), transform=fig.transFigure)
                #line2 = mpl.lines.Line2D((line_coords2[0]), (line_coords2[1]), transform=fig.transFigure)

                #xs1, ys1 = line_coords1.T
                #xs2, ys2 = line_coords2.T

                #linekw = dict(transform=fig.transFigure)
                #linekw = dict()

                #print('xs1 = %r' % (xs1,))
                #print('ys1 = %r' % (ys1,))

                #line1 = mpl.lines.Line2D(xs1, ys1, **linekw)
                #line2 = mpl.lines.Line2D(xs2, ys2, **linekw)  # NOQA
                #shrinkA=5, shrinkB=5, mutation_scale=20, fc="w")

                #ax2.add_artist(con)

                #fig.lines.append(line1)
                #fig.lines.append(line2)

        pass
    return fig
Пример #9
0
def show_descriptors_match_distances(orgres2_distance, fnum=1, db_name='', **kwargs):
    disttype_list = orgres2_distance.itervalues().next().keys()
    orgtype_list = orgres2_distance.keys()
    (nRow, nCol) = len(orgtype_list), len(disttype_list)
    nColors = nRow * nCol
    color_list = df2.distinct_colors(nColors)
    df2.figure(fnum=fnum, docla=True, doclf=True)
    pnum_ = lambda px: (nRow, nCol, px + 1)
    plot_type = utool.get_arg('--plot-type', default='plot')

    # Remember min and max val for each distance type (l1, emd...)
    distkey2_min = {distkey: np.uint64(-1) for distkey in disttype_list}
    distkey2_max = {distkey: 0 for distkey in disttype_list}

    def _distplot(dists, color, label, distkey, plot_type=plot_type):
        data = sorted(dists)
        ax = df2.gca()
        min_ = distkey2_min[distkey]
        max_ = distkey2_max[distkey]
        if plot_type == 'plot':
            df2.plot(data, color=color, label=label, yscale='linear')
            #xticks = np.linspace(np.min(data), np.max(data), 3)
            #yticks = np.linspace(0, len(data), 5)
            #ax.set_xticks(xticks)
            #ax.set_yticks(yticks)
            ax.set_ylim(min_, max_)
            ax.set_xlim(0, len(dists))
            ax.set_ylabel('distance')
            ax.set_xlabel('matches indexes (sorted by distance)')
            df2.legend(loc='lower right')
        if plot_type == 'pdf':
            df2.plot_pdf(data, color=color, label=label)
            ax.set_ylabel('pr')
            ax.set_xlabel('distance')
            ax.set_xlim(min_, max_)
            df2.legend(loc='upper left')
        df2.dark_background(ax)
        df2.small_xticks(ax)
        df2.small_yticks(ax)

    px = 0
    for orgkey in orgtype_list:
        for distkey in disttype_list:
            dists = orgres2_distance[orgkey][distkey]
            if len(dists) == 0:
                continue
            min_ = dists.min()
            max_ = dists.max()
            distkey2_min[distkey] = min(distkey2_min[distkey], min_)
            distkey2_max[distkey] = max(distkey2_max[distkey], max_)

    for count, orgkey in enumerate(orgtype_list):
        for distkey in disttype_list:
            printDBG('[allres-viz] plotting: %r' % ((orgkey, distkey),))
            dists = orgres2_distance[orgkey][distkey]
            df2.figure(fnum=fnum, pnum=pnum_(px))
            color = color_list[px]
            title = distkey + ' ' + orgkey
            label = 'P(%s | %s)' % (distkey, orgkey)
            _distplot(dists, color, label, distkey, **kwargs)
            if count == 0:
                ax = df2.gca()
                ax.set_title(distkey)
            px += 1

    subtitle = 'the matching distances between sift descriptors'
    title = '(sift) matching distances'
    if db_name != '':
        title = db_name + ' ' + title
    df2.set_figtitle(title, subtitle)
    df2.adjust_subplots_safe()
Пример #10
0
    def append_button(self,
                      text,
                      divider=None,
                      rect=None,
                      callback=None,
                      size='9%',
                      location='bottom',
                      ax=None,
                      **kwargs):
        """ Adds a button to the current page """

        if rect is not None:
            new_ax = df2.plt.axes(rect)
        if rect is None and divider is None:
            if ax is None:
                ax = df2.gca()
            divider = df2.ensure_divider(ax)
        if divider is not None:
            new_ax = divider.append_axes(location, size=size, pad=.05)
        if callback is not None:
            color, hovercolor = u'.85', u'.95'
        else:
            color, hovercolor = u'.88', u'.88'
            #color, hovercolor = u'.45', u'.45'
        #if isinstance(text, six.text_type):
        new_but = mpl.widgets.Button(new_ax,
                                     text,
                                     color=color,
                                     hovercolor=hovercolor)
        #elif isinstance(text, (list, tuple)):
        #    labels = [False] * len(text)
        #    labels[0] = True
        #    new_but = mpl.widgets.CheckButtons(new_ax, text, labels)
        #else:
        #    raise ValueError('bad input')

        if callback is not None:
            new_but.on_clicked(callback)
        else:
            button_text = new_but.ax.texts[0]
            button_text.set_color('.6')
            #button_text.set_color('r')
            #ut.embed()
            #print('new_but.color = %r' % (new_but.color,))
        #else:
        # TODO: figure ou how to gray out these buttons
        #    new_but.color = u'.1'
        #    new_but.hovercolor = u'.1'
        #    new_but.active = False
        #    print('new_but.color = %r' % (new_but.color,))
        ph.set_plotdat(new_ax, 'viztype', 'button')
        ph.set_plotdat(new_ax, 'text', text)
        #ph.set_plotdat(new_ax, 'parent_axes', ax)
        if ax is not None:
            child_axes = ph.get_plotdat(ax, 'child_axes', [])
            child_axes.append(new_ax)
            ph.set_plotdat(ax, 'child_axes', child_axes)
        for key, val in six.iteritems(kwargs):
            ph.set_plotdat(new_ax, key, val)
        # Keep buttons from losing scrop
        tup = (new_but, new_ax)
        self.scope.append(tup)
        return tup
Пример #11
0
def show_multiple_chips(ibs, aid_list, in_image=True, fnum=0, sel_aids=[],
                        subtitle='', annote=False, **kwargs):
    """
    CommandLine:
        python -m ibeis.viz.viz_name --test-show_multiple_chips --show --no-inimage
        python -m ibeis.viz.viz_name --test-show_multiple_chips --show --db NNP_Master3 --aids=6435,9861,137,6563,9167,12547,9332,12598,13285 --no-inimage --notitle
        python -m ibeis.viz.viz_name --test-show_multiple_chips --show --db NNP_Master3 --aids=137,6563,12547,9332,12598,13285 --no-inimage --notitle --adjust=.05
        python -m ibeis.viz.viz_name --test-show_multiple_chips --show --db NNP_Master3 --aids=6563,9332,13285,12598 --no-inimage --notitle --adjust=.05 --rc=1,4
        python -m ibeis.viz.viz_name --test-show_multiple_chips --show --db PZ_Master0 --aids=1288 --no-inimage --notitle --adjust=.05
        python -m ibeis.viz.viz_name --test-show_multiple_chips --show --db PZ_Master0 --aids=4020,4839 --no-inimage --notitle --adjust=.05

        python -m ibeis.viz.viz_name --test-show_multiple_chips --db NNP_Master3 --aids=6524,6540,6571,6751 --no-inimage --notitle --adjust=.05 --diskshow

        python -m ibeis.viz.viz_name --test-show_multiple_chips --db PZ_MTEST -a default:index=0:4 --show
        --aids=1 --doboth --show --no-inimage

        python -m ibeis.viz.viz_name --test-show_multiple_chips --db PZ_MTEST --aids=1 --doboth --show --no-inimage
        python -m ibeis.viz.viz_name --test-show_multiple_chips --db PZ_MTEST --aids=1 --doboth --rc=2,1 --show --no-inimage
        python -m ibeis.viz.viz_name --test-show_multiple_chips --db PZ_MTEST --aids=1 --doboth --rc=2,1 --show --notitle --trydrawline --no-draw_lbls
        python -m ibeis.viz.viz_name --test-show_multiple_chips --db PZ_MTEST --aids=1,2 --doboth  --show --notitle --trydrawline

        python -m ibeis.viz.viz_name --test-show_multiple_chips --db PZ_MTEST --aids=1,2,3,4,5 --doboth --rc=2,5 --show --chrlbl --trydrawline --qualtitle --no-figtitle --notitle
        --doboth
        --doboth --show

        python -m ibeis.viz.viz_name --test-show_multiple_chips --db NNP_Master3 --aids=15419 --doboth --rc=2,1 --show --notitle --trydrawline --no-draw_lbls

    Example:
        >>> # DISABLE_DOCTEST
        >>> from ibeis.viz.viz_name import *  # NOQA
        >>> import ibeis
        >>> ibs, aid_list, in_image = testdata_multichips()
        >>> fnum = 0
        >>> sel_aids = []
        >>> subtitle = ''
        >>> annote = False
        >>> fig = show_multiple_chips(ibs, aid_list, in_image, fnum, sel_aids, subtitle, annote)
        >>> ut.quit_if_noshow()
        >>> fig.canvas.draw()
        >>> ut.show_if_requested()
    """
    fnum = pt.ensure_fnum(fnum)
    nAids = len(aid_list)
    if nAids == 0:
        fig = df2.figure(fnum=fnum, pnum=(1, 1, 1), **kwargs)
        df2.imshow_null(fnum=fnum, **kwargs)
        return fig
    # Trigger computation of all chips in parallel
    ibsfuncs.ensure_annotation_data(ibs, aid_list, chips=(not in_image or annote), feats=annote)

    print('[viz_name] * annot_vuuid=%r' % ((ibs.get_annot_visual_uuids(aid_list),)))
    print('[viz_name] * aid_list=%r' % ((aid_list,)))

    DOBOTH = ut.get_argflag('--doboth')

    rc = ut.get_argval('--rc', type_=list, default=None)
    if rc is None:
        nRows, nCols = ph.get_square_row_cols(nAids * (2 if DOBOTH else 1))
    else:
        nRows, nCols = rc
    notitle = ut.get_argflag('--notitle')
    draw_lbls = not ut.get_argflag('--no-draw_lbls')
    show_chip_kw = dict(annote=annote, in_image=in_image, notitle=notitle, draw_lbls=draw_lbls)
    #print('[viz_name] * r=%r, c=%r' % (nRows, nCols))
    #gs2 = gridspec.GridSpec(nRows, nCols)
    pnum_ = df2.get_pnum_func(nRows, nCols)
    fig = df2.figure(fnum=fnum, pnum=pnum_(0), **kwargs)
    fig.clf()
    ax_list1 = []
    for px, aid in enumerate(aid_list):
        print('px = %r' % (px,))
        _fig, _ax1 = viz_chip.show_chip(ibs, aid=aid, pnum=pnum_(px), **show_chip_kw)
        print('other_aids = %r' % (ibs.get_annot_contact_aids(aid),))
        ax = df2.gca()
        ax_list1.append(_ax1)
        if aid in sel_aids:
            df2.draw_border(ax, df2.GREEN, 4)
        if ut.get_argflag('--chrlbl') and not DOBOTH:
            ax.set_xlabel('(' + chr(ord('a') - 1 + px) + ')')
        elif ut.get_argflag('--numlbl') and not DOBOTH:
            ax.set_xlabel('(' + str(px + 1) + ')')
        #plot_aid3(ibs, aid)

    # HACK to show in image and not in image
    if DOBOTH:
        #ut.embed()
        #ph.get_plotdat_dict(ax_list1[1])
        #ph.get_plotdat_dict(ax_list2[1])
        ax_list2 = []

        show_chip_kw['in_image'] = not show_chip_kw['in_image']
        start = px + 1
        for px, aid in enumerate(aid_list, start=start):
            _fig, _ax2 = viz_chip.show_chip(ibs, aid=aid, pnum=pnum_(px), **show_chip_kw)
            ax = df2.gca()
            ax_list2.append(_ax2)

            if ut.get_argflag('--chrlbl'):
                ax.set_xlabel('(' + chr(ord('a') - start + px) + ')')
            elif ut.get_argflag('--numlbl'):
                ax.set_xlabel('(' + str(px - start + 1) + ')')

            if ut.get_argflag('--qualtitle'):
                qualtext = ibs.get_annot_quality_texts(aid)
                ax.set_title(qualtext)

            if aid in sel_aids:
                df2.draw_border(ax, df2.GREEN, 4)

        if in_image:
            ax_list1, ax_list2 = ax_list2, ax_list1

        if ut.get_argflag('--trydrawline'):
            # Unfinished
            #ut.embed()
            # Draw lines between corresponding axes
            # References:
            # http://stackoverflow.com/questions/17543359/drawing-lines-between-two-plots-in-matplotlib
            import matplotlib as mpl
            import vtool as vt
            # !!!
            #http://matplotlib.org/users/transforms_tutorial.html

            #invTransFigure_fn1 = fig.transFigure.inverted().transform
            #invTransFigure_fn2 = fig.transFigure.inverted().transform
            #print(ax_list1)
            #print(ax_list2)
            assert len(ax_list1) == len(ax_list2)

            for ax1, ax2 in zip(ax_list1, ax_list2):
                #_ = ax1.get_window_extent().transformed(fig.dpi_scale_trans.inverted())
                #bbox1 = (0, 0, _.width * fig.dpi, _.height * fig.dpi)

                # returns in figure coordinates
                #bbox1 = df2.get_axis_bbox(ax=ax1)
                #if bbox1[-1] < 0:
                #    # Weird bug
                #    bbox1 = bbox1[1]
                print('--')
                print('ax1 = %r' % (ax1,))
                print('ax2 = %r' % (ax2,))
                chipshape = ph.get_plotdat(ax1, 'chipshape')
                #_bbox1 = ax1.get_window_extent().transformed(fig.dpi_scale_trans.inverted())
                #bbox1 = (0, 0, _bbox1.width * fig.dpi, _bbox1.height * fig.dpi)
                bbox1 = (0, 0, chipshape[1], chipshape[0])

                aid_ = ph.get_plotdat(ax2, 'aid')
                aid_list_ = ph.get_plotdat(ax2, 'aid_list')
                index = aid_list_.index(aid_)
                annotation_bbox_list = ph.get_plotdat(ax2, 'annotation_bbox_list')
                bbox2 = annotation_bbox_list[index]

                print('bbox1 = %r' % (bbox1,))
                print('bbox2 = %r' % (bbox2,))

                vert_list1 = np.array(vt.verts_from_bbox(bbox1))
                vert_list2 = np.array(vt.verts_from_bbox(bbox2))

                print('vert_list1 = %r' % (vert_list1,))
                print('vert_list2 = %r' % (vert_list2,))
                #for vx in [0, 1, 2, 3]:
                for vx in [0, 1]:
                    vert1 = vert_list1[vx].tolist()
                    vert2 = vert_list2[vx].tolist()
                    print('  ***')
                    print('  * vert1 = %r' % (vert1,))
                    print('  * vert2 = %r' % (vert2,))

                    coordsA = coordsB = 'data'
                    #coords = 'axes points'
                    #'axes fraction'
                    #'axes pixels'
                    #coordsA = 'axes pixels'
                    #coordsB = 'data'
                    #'figure fraction'
                    #'figure pixels'
                    #'figure pixels'
                    #'figure points'
                    #'polar'
                    #'offset points'

                    con = mpl.patches.ConnectionPatch(
                        xyA=vert1, xyB=vert2, coordsA=coordsA,
                        coordsB=coordsB,
                        axesA=ax1, axesB=ax2,
                        linewidth=1, color='k')
                    #, arrowstyle="-")

                    #ut.embed()
                    #con.set_zorder(None)
                    ax1.add_artist(con)
                    #ax2.add_artist(con)

                    #ut.embed()

                    #verts2.T[1] -= bbox2[-1]
                    #bottom_left1, bottom_right1 = verts1[1:3].tolist()
                    #bottom_left2, bottom_right2 = verts2[1:3].tolist()

                ##transAxes1 = ax1.transData.inverted()
                #transAxes1_fn = ax1.transData.transform
                #transAxes2_fn = ax2.transData.transform

                #transAxes1_fn = ut.identity
                #transAxes2_fn = ut.identity

                #coord_bl1 = transFigure.transform(transAxes1.transform(bottom_left1))
                #coord_br1 = transFigure.transform(transAxes1.transform(bottom_right1))
                #coord_bl1 = invTransFigure_fn1(transAxes1_fn(bottom_left1))
                #print('bottom_left2 = %r' % (bottom_left2,))
                #coord_bl1 = (5, 5)
                #coord_bl2 = invTransFigure_fn2(transAxes2_fn(bottom_left2))
                #print('coord_bl2 = %r' % (coord_bl2,))

                #coord_br1 = invTransFigure_fn1(transAxes1_fn(bottom_right1))
                #coord_br2 = invTransFigure_fn2(transAxes2_fn(bottom_right2))
                ##print('coord_bl1 = %r' % (coord_bl1,))

                #line_coords1 = np.vstack([coord_bl1, coord_bl2])
                #line_coords2 = np.vstack([coord_br1, coord_br2])
                #print('line_coords1 = %r' % (line_coords1,))

                #line1 = mpl.lines.Line2D((line_coords1[0]), (line_coords1[1]), transform=fig.transFigure)
                #line2 = mpl.lines.Line2D((line_coords2[0]), (line_coords2[1]), transform=fig.transFigure)

                #xs1, ys1 = line_coords1.T
                #xs2, ys2 = line_coords2.T

                #linekw = dict(transform=fig.transFigure)
                #linekw = dict()

                #print('xs1 = %r' % (xs1,))
                #print('ys1 = %r' % (ys1,))

                #line1 = mpl.lines.Line2D(xs1, ys1, **linekw)
                #line2 = mpl.lines.Line2D(xs2, ys2, **linekw)  # NOQA
                #shrinkA=5, shrinkB=5, mutation_scale=20, fc="w")

                #ax2.add_artist(con)

                #fig.lines.append(line1)
                #fig.lines.append(line2)

        pass
    return fig
Пример #12
0
def show_descriptors_match_distances(orgres2_distance,
                                     fnum=1,
                                     db_name='',
                                     **kwargs):
    disttype_list = orgres2_distance.itervalues().next().keys()
    orgtype_list = orgres2_distance.keys()
    (nRow, nCol) = len(orgtype_list), len(disttype_list)
    nColors = nRow * nCol
    color_list = df2.distinct_colors(nColors)
    df2.figure(fnum=fnum, docla=True, doclf=True)
    pnum_ = lambda px: (nRow, nCol, px + 1)
    plot_type = utool.get_arg('--plot-type', default='plot')

    # Remember min and max val for each distance type (l1, emd...)
    distkey2_min = {distkey: np.uint64(-1) for distkey in disttype_list}
    distkey2_max = {distkey: 0 for distkey in disttype_list}

    def _distplot(dists, color, label, distkey, plot_type=plot_type):
        data = sorted(dists)
        ax = df2.gca()
        min_ = distkey2_min[distkey]
        max_ = distkey2_max[distkey]
        if plot_type == 'plot':
            df2.plot(data, color=color, label=label, yscale='linear')
            #xticks = np.linspace(np.min(data), np.max(data), 3)
            #yticks = np.linspace(0, len(data), 5)
            #ax.set_xticks(xticks)
            #ax.set_yticks(yticks)
            ax.set_ylim(min_, max_)
            ax.set_xlim(0, len(dists))
            ax.set_ylabel('distance')
            ax.set_xlabel('matches indexes (sorted by distance)')
            df2.legend(loc='lower right')
        if plot_type == 'pdf':
            df2.plot_pdf(data, color=color, label=label)
            ax.set_ylabel('pr')
            ax.set_xlabel('distance')
            ax.set_xlim(min_, max_)
            df2.legend(loc='upper left')
        df2.dark_background(ax)
        df2.small_xticks(ax)
        df2.small_yticks(ax)

    px = 0
    for orgkey in orgtype_list:
        for distkey in disttype_list:
            dists = orgres2_distance[orgkey][distkey]
            if len(dists) == 0:
                continue
            min_ = dists.min()
            max_ = dists.max()
            distkey2_min[distkey] = min(distkey2_min[distkey], min_)
            distkey2_max[distkey] = max(distkey2_max[distkey], max_)

    for count, orgkey in enumerate(orgtype_list):
        for distkey in disttype_list:
            printDBG('[allres-viz] plotting: %r' % ((orgkey, distkey), ))
            dists = orgres2_distance[orgkey][distkey]
            df2.figure(fnum=fnum, pnum=pnum_(px))
            color = color_list[px]
            title = distkey + ' ' + orgkey
            label = 'P(%s | %s)' % (distkey, orgkey)
            _distplot(dists, color, label, distkey, **kwargs)
            if count == 0:
                ax = df2.gca()
                ax.set_title(distkey)
            px += 1

    subtitle = 'the matching distances between sift descriptors'
    title = '(sift) matching distances'
    if db_name != '':
        title = db_name + ' ' + title
    df2.set_figtitle(title, subtitle)
    df2.adjust_subplots_safe()