Ejemplo n.º 1
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
Ejemplo n.º 2
0
def plot_annotaiton_gps(X_Data):
    """ Plots gps coordinates on a map projection """
    from mpl_toolkits.basemap import Basemap
    #lat = X_data[1:5, 1]
    #lon = X_data[1:5, 2]
    lat = X_data[:, 1]
    lon = X_data[:, 2]
    fig = df2.figure(fnum=1, doclf=True, docla=True)
    df2.close_figure(fig)
    fig = df2.figure(fnum=1, doclf=True, docla=True)
    # setup Lambert Conformal basemap.
    m = Basemap(llcrnrlon=lon.min(),
                urcrnrlon=lon.max(),
                llcrnrlat=lat.min(),
                urcrnrlat=lat.max(),
                projection='cea',
                resolution='h')
    # draw coastlines.
    #m.drawcoastlines()
    #m.drawstates()
    # draw a boundary around the map, fill the background.
    # this background will end up being the ocean color, since
    # the continents will be drawn on top.
    #m.bluemarble()
    m.drawmapboundary(fill_color='aqua')
    m.fillcontinents(color='coral', lake_color='aqua')
    # Convert GPS to projected coordinates
    x1, y1 = m(lon, lat)  # convert to meters # lon==X, lat==Y
    m.plot(x1, y1, 'o')
    fig.show()
Ejemplo n.º 3
0
def TEST_QUERY(ibs):
    print('[TEST_QUERY]')
    valid_aids = ibs.get_valid_aids()
    print('[TEST_QUERY] len(valid_aids)=%r' % (len(valid_aids)))
    qaid_list = valid_aids[0:1]
    print('[TEST_QUERY] len(qaid_list)=%r' % (len(qaid_list)))
    ibs._init_query_requestor()
    qreq = ibs.qreq
    #query_helpers.find_matchable_chips(ibs)
    aids = ibs.get_recognition_database_aids()
    qres_dict = ibs.query_all(qaid_list)

    for qaid in qaid_list:
        qres  = qres_dict[qaid]
        top_aids = qres.get_top_aids(ibs)
        top_aids = utool.safe_slice(top_aids, 3)
        aid2 = top_aids[0]
        fnum = df2.next_fnum()
        df2.figure(fnum=fnum, doclf=True)
        #viz_matches.show_matches(ibs, qres, aid2, fnum=fnum, in_image=True)
        #viz.show_qres(ibs, qres, fnum=fnum, top_aids=top_aids, ensure=False)
        interact.ishow_qres(ibs, qres, fnum=fnum, top_aids=top_aids,
                            ensure=False, annote_mode=1)
        df2.set_figtitle('Query Result')
        df2.adjust_subplots_safe(top=.8)
    return locals()
Ejemplo n.º 4
0
def show_sv_simple(chip1, chip2, kpts1, kpts2, fm, inliers, mx=None, fnum=1, vert=None, **kwargs):
    """

    CommandLine:
        python -m plottool.draw_sv --test-show_sv_simple --show

    Example:
        >>> # DISABLE_DOCTEST
        >>> from plottool.draw_sv import *  # NOQA
        >>> import vtool as vt
        >>> kpts1, kpts2, fm, aff_inliers, chip1, chip2, xy_thresh_sqrd = vt.testdata_matching_affine_inliers()
        >>> inliers = aff_inliers
        >>> mx = None
        >>> fnum = 1
        >>> vert = None  # ut.get_argval('--vert', type_=bool, default=None)
        >>> result = show_sv_simple(chip1, chip2, kpts1, kpts2, fm, inliers, mx, fnum, vert=vert)
        >>> print(result)
        >>> ut.show_if_requested()
    """
    import plottool as pt
    colors = df2.distinct_colors(2, brightness=.95)
    color1, color2 = colors[0:2]
    # Begin the drawing
    fnum = pt.ensure_fnum(fnum)
    df2.figure(fnum=fnum, pnum=(1, 1, 1), docla=True, doclf=True)
    #dmkwargs = dict(fs=None, title='Inconsistent Matches', all_kpts=False, draw_lines=True,
    #                docla=True, draw_border=True, fnum=fnum, pnum=(1, 1, 1), colors=df2.ORANGE)
    inlier_mask = vt.index_to_boolmask(inliers, maxval=len(fm))
    fm_inliers = fm.compress(inlier_mask, axis=0)
    fm_outliers = fm.compress(np.logical_not(inlier_mask), axis=0)
    ax, xywh1, xywh2 = df2.show_chipmatch2(chip1, chip2, vert=vert)
    fmatch_kw = dict(ell_linewidth=2, ell_alpha=.7, line_alpha=.7)
    df2.plot_fmatch(xywh1, xywh2, kpts1, kpts2, fm_inliers, colors=color1, **fmatch_kw)
    df2.plot_fmatch(xywh1, xywh2, kpts1, kpts2, fm_outliers, colors=color2, **fmatch_kw)
Ejemplo n.º 5
0
def plot_keypoint_scales(hs, fnum=1):
    print('[dev] plot_keypoint_scales()')
    cx2_kpts = hs.feats.cx2_kpts
    if len(cx2_kpts) == 0:
        hs.refresh_features()
        cx2_kpts = hs.feats.cx2_kpts
    cx2_nFeats = map(len, cx2_kpts)
    kpts = np.vstack(cx2_kpts)
    print('[dev] --- LaTeX --- ')
    _printopts = np.get_printoptions()
    np.set_printoptions(precision=3)
    print(util_latex.latex_scalar(r'\# keypoints, ', len(kpts)))
    print(util_latex.latex_mystats(r'\# keypoints per image', cx2_nFeats))
    scales = ktool.get_scales(kpts)
    scales = np.array(sorted(scales))
    print(util_latex.latex_mystats(r'keypoint scale', scales))
    np.set_printoptions(**_printopts)
    print('[dev] ---/LaTeX --- ')
    #
    df2.figure(fnum=fnum, docla=True, title='sorted scales')
    df2.plot(scales)
    df2.adjust_subplots_safe()
    #ax = df2.gca()
    #ax.set_yscale('log')
    #ax.set_xscale('log')
    #
    fnum += 1
    df2.figure(fnum=fnum, docla=True, title='hist scales')
    df2.show_histogram(scales, bins=20)
    df2.adjust_subplots_safe()
    #ax = df2.gca()
    #ax.set_yscale('log')
    #ax.set_xscale('log')
    return fnum
Ejemplo n.º 6
0
def TEST_QUERY_COMP(ibs):
    r"""
    CommandLine:
        python -m ibeis.tests.test_ibs_query_components --test-TEST_QUERY_COMP

    Example:
        >>> # ENABLE_DOCTEST
        >>> from ibeis.tests.test_ibs_query_components import *  # NOQA
        >>> import ibeis
        >>> # build test data
        >>> ibs = ibeis.opendb('testdb1')
        >>> # execute function
        >>> TEST_QUERY_COMP(ibs)
    """
    print('[TEST_QUERY_COMP]')
    aids = ibs.get_valid_aids()
    index = 0
    index = utool.get_argval('--index', type_=int, default=index)
    qaid_list = utool.safe_slice(aids, index, index + 1)
    print('[TEST_QUERY_COMP] len(qaid_list)=%r' % (qaid_list))
    try:
        comp_locals_ = query_helpers.get_query_components(ibs, qaid_list)
        qres_dict = OrderedDict([
            ('ORIG', comp_locals_['qres_ORIG']),
            ('FILT', comp_locals_['qres_FILT']),
            ('SVER', comp_locals_['qres_SVER']),
        ])

        top_aids = qres_dict['SVER'].get_top_aids()
        aid2 = top_aids[0]
    except Exception as ex:
        if 'qres_dict' in vars():
            for name, qres in qres_dict.items():
                print(name)
                print(qres.get_inspect_str())
        utool.printex(ex, keys=['qaid_list'], pad_stdout=True)
        raise

    for px, (lbl, qres) in enumerate(six.iteritems(qres_dict)):
        print(lbl)
        fnum = df2.next_fnum()
        df2.figure(fnum=fnum, doclf=True)
        qres.ishow_top(ibs,  fnum=fnum, top_aids=top_aids, ensure=False)
        df2.set_figtitle(lbl)
        df2.adjust_subplots_safe(top=.8)

    fnum = df2.next_fnum()

    qaid2_svtups = comp_locals_['qaid2_svtups']
    qaid2_chipmatch_FILT = comp_locals_['qaid2_chipmatch_FILT']
    aid1 = qaid = comp_locals_['qaid']
    aid2_svtup  = qaid2_svtups[aid1]
    chipmatch_FILT = qaid2_chipmatch_FILT[aid1]
    viz.show_sver(ibs, aid1, aid2, chipmatch_FILT, aid2_svtup, fnum=fnum)
    return locals()
Ejemplo n.º 7
0
    def chipmatch_view(self, pnum=(1, 1, 1), **kwargs_):
        """
        just visualizes the matches using some type of lines

        CommandLine:
            python -m ibeis.viz.interact.interact_matches --test-chipmatch_view --show

        Example:
            >>> # DISABLE_DOCTEST
            >>> from ibeis.viz.interact.interact_matches import *  # NOQA
            >>> self = testdata_match_interact()
            >>> self.chipmatch_view()
            >>> pt.show_if_requested()
        """
        ibs = self.ibs
        aid = self.daid
        qaid = self.qaid
        fnum = self.fnum
        figtitle = self.figtitle
        xywh2_ptr = self.xywh2_ptr

        # drawing mode draw: with/without lines/feats
        mode = self.mode
        draw_ell = mode >= 1
        draw_lines = mode == 2
        self.mode = (self.mode + 1) % 3
        df2.figure(fnum=fnum, docla=True, doclf=True)
        show_matches_kw = self.kwargs.copy()
        show_matches_kw.update(
            dict(fnum=fnum,
                 pnum=pnum,
                 draw_lines=draw_lines,
                 draw_ell=draw_ell,
                 colorbar_=True,
                 vert=self.vert))
        show_matches_kw.update(kwargs_)

        if self.use_homog:
            show_matches_kw['H1'] = self.H1

        #show_matches_kw['score'] = self.score
        show_matches_kw['rawscore'] = self.score
        #ut.embed()
        show_matches_kw['aid2_raw_rank'] = self.rank
        tup = viz.viz_matches.show_matches2(ibs,
                                            self.qaid,
                                            self.daid,
                                            self.fm,
                                            self.fs,
                                            qreq_=self.qreq_,
                                            **show_matches_kw)
        ax, xywh1, xywh2 = tup
        xywh2_ptr[0] = xywh2

        df2.set_figtitle(figtitle + ' ' + vh.get_vsstr(qaid, aid))
Ejemplo n.º 8
0
def show_sv_simple(chip1,
                   chip2,
                   kpts1,
                   kpts2,
                   fm,
                   inliers,
                   mx=None,
                   fnum=1,
                   vert=None,
                   **kwargs):
    """

    CommandLine:
        python -m plottool.draw_sv --test-show_sv_simple --show

    Example:
        >>> # DISABLE_DOCTEST
        >>> from plottool.draw_sv import *  # NOQA
        >>> import vtool as vt
        >>> kpts1, kpts2, fm, aff_inliers, chip1, chip2, xy_thresh_sqrd = vt.testdata_matching_affine_inliers()
        >>> inliers = aff_inliers
        >>> mx = None
        >>> fnum = 1
        >>> vert = None  # ut.get_argval('--vert', type_=bool, default=None)
        >>> result = show_sv_simple(chip1, chip2, kpts1, kpts2, fm, inliers, mx, fnum, vert=vert)
        >>> print(result)
        >>> ut.show_if_requested()
    """
    import plottool as pt
    colors = df2.distinct_colors(2, brightness=.95)
    color1, color2 = colors[0:2]
    # Begin the drawing
    fnum = pt.ensure_fnum(fnum)
    df2.figure(fnum=fnum, pnum=(1, 1, 1), docla=True, doclf=True)
    #dmkwargs = dict(fs=None, title='Inconsistent Matches', all_kpts=False, draw_lines=True,
    #                docla=True, draw_border=True, fnum=fnum, pnum=(1, 1, 1), colors=df2.ORANGE)
    inlier_mask = vt.index_to_boolmask(inliers, maxval=len(fm))
    fm_inliers = fm.compress(inlier_mask, axis=0)
    fm_outliers = fm.compress(np.logical_not(inlier_mask), axis=0)
    ax, xywh1, xywh2 = df2.show_chipmatch2(chip1, chip2, vert=vert)
    fmatch_kw = dict(ell_linewidth=2, ell_alpha=.7, line_alpha=.7)
    df2.plot_fmatch(xywh1,
                    xywh2,
                    kpts1,
                    kpts2,
                    fm_inliers,
                    colors=color1,
                    **fmatch_kw)
    df2.plot_fmatch(xywh1,
                    xywh2,
                    kpts1,
                    kpts2,
                    fm_outliers,
                    colors=color2,
                    **fmatch_kw)
Ejemplo n.º 9
0
    def _chip_view(mode=0, pnum=(1, 1, 1), **kwargs):
        print('... _chip_view mode=%r' % mode_ptr[0])
        kwargs['ell'] = mode_ptr[0] == 1
        kwargs['pts'] = mode_ptr[0]  == 2

        if not ischild:
            df2.figure(fnum=fnum, pnum=pnum, docla=True, doclf=True)
        # Toggle no keypoints view
        viz.show_chip(ibs, aid, fnum=fnum, pnum=pnum, config2_=config2_,
                      **kwargs)
        df2.set_figtitle('Chip View')
Ejemplo n.º 10
0
    def _chip_view(mode=0, pnum=(1, 1, 1), **kwargs):
        print('... _chip_view mode=%r' % mode_ptr[0])
        kwargs['ell'] = mode_ptr[0] == 1
        kwargs['pts'] = mode_ptr[0]  == 2

        if not ischild:
            df2.figure(fnum=fnum, pnum=pnum, docla=True, doclf=True)
        # Toggle no keypoints view
        viz.show_chip(ibs, aid, fnum=fnum, pnum=pnum, config2_=config2_,
                      **kwargs)
        df2.set_figtitle('Chip View')
Ejemplo n.º 11
0
def plot_rank_histogram(allres, orgres_type):
    print('[viz] plotting %r rank histogram' % orgres_type)
    ranks = allres.__dict__[orgres_type].ranks
    label = 'P(rank | ' + orgres_type + ' match)'
    title = orgres_type + ' match rankings histogram\n' + allres.title_suffix
    df2.figure(fnum=FIGNUM, doclf=True, title=title)
    df2.draw_histpdf(ranks, label=label)  # FIXME
    df2.set_xlabel('ground truth ranks')
    df2.set_ylabel('frequency')
    df2.legend()
    __dump_or_browse(allres.ibs, 'rankviz')
Ejemplo n.º 12
0
def plot_rank_histogram(allres, orgres_type):
    print('[viz] plotting %r rank histogram' % orgres_type)
    ranks = allres.__dict__[orgres_type].ranks
    label = 'P(rank | ' + orgres_type + ' match)'
    title = orgres_type + ' match rankings histogram\n' + allres.title_suffix
    df2.figure(fnum=FIGNUM, doclf=True, title=title)
    df2.draw_histpdf(ranks, label=label)  # FIXME
    df2.set_xlabel('ground truth ranks')
    df2.set_ylabel('frequency')
    df2.legend()
    __dump_or_browse(allres.ibs, 'rankviz')
Ejemplo n.º 13
0
def TEST_QUERY(ibs):
    r"""
    CommandLine:
        python -m ibeis.tests.test_ibs_query --test-TEST_QUERY
        python -m ibeis.tests.test_ibs_query --test-TEST_QUERY --show

    Example:
        >>> # ENABLE_DOCTEST
        >>> from ibeis.tests.test_ibs_query import *  # NOQA
        >>> import plottool as pt
        >>> import ibeis
        >>> ibs = ibeis.opendb('testdb1')
        >>> TEST_QUERY(ibs)
        >>> pt.show_if_requested()
    """
    print('[TEST_QUERY]')
    daid_list = ibs.get_valid_aids()
    print('[TEST_QUERY] len(daid_list)=%r' % (len(daid_list)))
    qaid_list = daid_list[0:1]
    print('[TEST_QUERY] len(qaid_list)=%r' % (len(qaid_list)))
    qres_list = ibs.query_chips(qaid_list, daid_list, use_cache=False, use_bigcache=False)
    qres_list_ = ibs.query_chips(qaid_list, daid_list)

    try:
        vals1 = qres_list
        vals2 = qres_list_
        assert len(vals1) == 1, 'expected 1 qres in result'
        assert len(vals2) == 1, 'expected 1 qres in result'
        #assert list(qres_dict.keys()) == list(qres_dict_.keys()), 'qres cache doesnt work. key error'
        qres1 = vals1[0]
        qres2 = vals2[0]
        inspect_str1 = qres1.get_inspect_str(ibs)
        inspect_str2 = qres2.get_inspect_str(ibs)
        print(inspect_str1)
        assert inspect_str1 == inspect_str2, 'qres cache inconsistency'
        assert vals1 == vals2, 'qres cache doesnt work. val error'
    except AssertionError as ex:
        utool.printex(ex, key_list=list(locals().keys()))
        raise

    if ut.show_was_requested():
        for qres in qres_list:
            top_aids = qres.get_top_aids()
            #top_aids = utool.safe_slice(top_aids, 3)
            aid2 = top_aids[0]
            fnum = df2.next_fnum()
            df2.figure(fnum=fnum, doclf=True)
            qres.ishow_top(ibs, fnum=fnum, top_aids=top_aids, ensure=False, annot_mode=1)
            df2.set_figtitle('Query Result')
            df2.adjust_subplots_safe(top=.8)
    return locals()
Ejemplo n.º 14
0
def dump_orgres_matches(allres, orgres_type):
    orgres = allres.__dict__[orgres_type]
    ibs = allres.ibs
    qrid2_qres = allres.qrid2_qres
    # loop over each query / result of interest
    for qrid, rid, score, rank in orgres.iter():
        query_gname, _  = os.path.splitext(ibs.tables.gx2_gname[ibs.tables.cx2_gx[qrid]])
        result_gname, _ = os.path.splitext(ibs.tables.gx2_gname[ibs.tables.cx2_gx[rid]])
        qres = qrid2_qres[qrid]
        df2.figure(fnum=1, plotnum=121)
        df2.show_matches_annote_res(qres, ibs, rid, fnum=1, plotnum=121)
        big_title = 'score=%.2f_rank=%d_q=%s_r=%s' % (score, rank, query_gname, result_gname)
        df2.set_figtitle(big_title)
        viz.__dump_or_browse(allres, orgres_type + '_matches' + allres.title_suffix)
Ejemplo n.º 15
0
    def _chipmatch_view(pnum=(1, 1, 1), **kwargs):
        mode = annote_ptr[0]  # drawing mode draw: with/without lines/feats
        draw_ell = mode >= 1
        draw_lines = mode == 2
        annote_ptr[0] = (annote_ptr[0] + 1) % 3
        df2.figure(fnum=fnum, docla=True, doclf=True)
        # TODO RENAME This to remove qres and rectify with show_matches
        tup = viz.show_matches(ibs, qres, aid, fnum=fnum, pnum=pnum,
                               draw_lines=draw_lines, draw_ell=draw_ell,
                               colorbar_=True, **kwargs)
        ax, xywh1, xywh2 = tup
        xywh2_ptr[0] = xywh2

        df2.set_figtitle(figtitle + ' ' + vh.get_vsstr(qaid, aid))
Ejemplo n.º 16
0
def plot_score_pdf(allres, orgres_type, colorx=0.0, variation_truncate=False):
    print('[viz] plotting ' + orgres_type + ' score pdf')
    title  = orgres_type + ' match score frequencies\n' + allres.title_suffix
    scores = allres.__dict__[orgres_type].scores
    print('[viz] len(scores) = %r ' % (len(scores),))
    label  = 'P(score | %r)' % orgres_type
    df2.figure(fnum=FIGNUM, doclf=True, title=title)
    df2.draw_pdf(scores, label=label, colorx=colorx)
    if variation_truncate:
        df2.variation_trunctate(scores)
    #df2.variation_trunctate(false.scores)
    df2.set_xlabel('score')
    df2.set_ylabel('frequency')
    df2.legend()
    __dump_or_browse(allres.ibs, 'scoreviz')
Ejemplo n.º 17
0
def plot_score_pdf(allres, orgres_type, colorx=0.0, variation_truncate=False):
    print('[viz] plotting ' + orgres_type + ' score pdf')
    title = orgres_type + ' match score frequencies\n' + allres.title_suffix
    scores = allres.__dict__[orgres_type].scores
    print('[viz] len(scores) = %r ' % (len(scores), ))
    label = 'P(score | %r)' % orgres_type
    df2.figure(fnum=FIGNUM, doclf=True, title=title)
    df2.draw_pdf(scores, label=label, colorx=colorx)
    if variation_truncate:
        df2.variation_trunctate(scores)
    #df2.variation_trunctate(false.scores)
    df2.set_xlabel('score')
    df2.set_ylabel('frequency')
    df2.legend()
    __dump_or_browse(allres.ibs, 'scoreviz')
Ejemplo n.º 18
0
    def chipmatch_view(self, pnum=(1, 1, 1), **kwargs_):
        """
        just visualizes the matches using some type of lines

        CommandLine:
            python -m ibeis.viz.interact.interact_matches --test-chipmatch_view --show

        Example:
            >>> # DISABLE_DOCTEST
            >>> from ibeis.viz.interact.interact_matches import *  # NOQA
            >>> self = testdata_match_interact()
            >>> self.chipmatch_view()
            >>> pt.show_if_requested()
        """
        ibs      = self.ibs
        aid      = self.daid
        qaid     = self.qaid
        fnum     = self.fnum
        figtitle = self.figtitle
        xywh2_ptr  = self.xywh2_ptr

        # drawing mode draw: with/without lines/feats
        mode = self.mode
        draw_ell = mode >= 1
        draw_lines = mode == 2
        self.mode = (self.mode + 1) % 3
        df2.figure(fnum=fnum, docla=True, doclf=True)
        show_matches_kw = self.kwargs.copy()
        show_matches_kw.update(
            dict(fnum=fnum, pnum=pnum, draw_lines=draw_lines,
                 draw_ell=draw_ell, colorbar_=True, vert=self.vert))
        show_matches_kw.update(kwargs_)

        if self.use_homog:
            show_matches_kw['H1'] = self.H1

        #show_matches_kw['score'] = self.score
        show_matches_kw['rawscore'] = self.score
        #ut.embed()
        show_matches_kw['aid2_raw_rank'] = self.rank
        tup = viz.viz_matches.show_matches2(ibs, self.qaid, self.daid,
                                            self.fm, self.fs,
                                            qreq_=self.qreq_,
                                            **show_matches_kw)
        ax, xywh1, xywh2 = tup
        xywh2_ptr[0] = xywh2

        df2.set_figtitle(figtitle + ' ' + vh.get_vsstr(qaid, aid))
Ejemplo n.º 19
0
def test_viz_image(imgpaths):
    nImgs = len(imgpaths)
    assert len(imgpaths) < 20, '%d > 20 out of scope of this test' % nImgs
    tau = np.pi * 2
    fnum = 1
    img_list = imread_many(imgpaths)
    nRows, nCols = ph.get_square_row_cols(nImgs)
    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))
    fig.clf()
    for px, img in enumerate(img_list):
        title = 'test title'
        bbox_list = [dummy_bbox(img),
                     dummy_bbox(img, (-.25, -.25), .1)]
        theta_list = [tau * .7, tau * .9]
        sel_list = [True, False]
        label_list = ['test label', 'lbl2']
        viz_image2.show_image(img,
                              bbox_list=bbox_list,
                              title=title,
                              sel_list=sel_list,
                              label_list=label_list,
                              theta_list=theta_list,
                              fnum=fnum,
                              pnum=pnum_(px))
Ejemplo n.º 20
0
def plot_rank_stem(allres, orgres_type='true'):
    print('[viz] plotting rank stem')
    # Visualize rankings with the stem plot
    ibs = allres.ibs
    title = orgres_type + 'rankings stem plot\n' + allres.title_suffix
    orgres = allres.__dict__[orgres_type]
    df2.figure(fnum=FIGNUM, doclf=True, title=title)
    x_data = orgres.qcxs
    y_data = orgres.ranks
    df2.draw_stems(x_data, y_data)
    slice_num = int(np.ceil(np.log10(len(orgres.qcxs))))
    df2.set_xticks(ibs.test_sample_cx[::slice_num])
    df2.set_xlabel('query chip indeX (qcx)')
    df2.set_ylabel('groundtruth chip ranks')
    #df2.set_yticks(list(seen_ranks))
    __dump_or_browse(allres.ibs, 'rankviz')
Ejemplo n.º 21
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)
Ejemplo n.º 22
0
def dump_orgres_matches(allres, orgres_type):
    orgres = allres.__dict__[orgres_type]
    ibs = allres.ibs
    qcx2_res = allres.qcx2_res
    # loop over each query / result of interest
    for qcx, cx, score, rank in orgres.iter():
        query_gname, _  = os.path.splitext(ibs.tables.gx2_gname[ibs.tables.cx2_gx[qcx]])
        result_gname, _ = os.path.splitext(ibs.tables.gx2_gname[ibs.tables.cx2_gx[cx]])
        res = qcx2_res[qcx]
        df2.figure(fnum=FIGNUM, pnum=121)
        df2.show_matches3(res, ibs, cx, SV=False, fnum=FIGNUM, pnum=121)
        df2.show_matches3(res, ibs, cx, SV=True,  fnum=FIGNUM, pnum=122)
        big_title = 'score=%.2f_rank=%d_q=%s_r=%s' % (score, rank, query_gname,
                                                      result_gname)
        df2.set_figtitle(big_title)
        __dump_or_browse(allres.ibs, orgres_type + '_matches' + allres.title_suffix)
Ejemplo n.º 23
0
def plot_rank_stem(allres, orgres_type='true'):
    print('[viz] plotting rank stem')
    # Visualize rankings with the stem plot
    ibs = allres.ibs
    title = orgres_type + 'rankings stem plot\n' + allres.title_suffix
    orgres = allres.__dict__[orgres_type]
    df2.figure(fnum=FIGNUM, doclf=True, title=title)
    x_data = orgres.qcxs
    y_data = orgres.ranks
    df2.draw_stems(x_data, y_data)
    slice_num = int(np.ceil(np.log10(len(orgres.qcxs))))
    df2.set_xticks(ibs.test_sample_cx[::slice_num])
    df2.set_xlabel('query chip indeX (qcx)')
    df2.set_ylabel('groundtruth chip ranks')
    #df2.set_yticks(list(seen_ranks))
    __dump_or_browse(allres.ibs, 'rankviz')
Ejemplo n.º 24
0
def dump_orgres_matches(allres, orgres_type):
    orgres = allres.__dict__[orgres_type]
    ibs = allres.ibs
    qrid2_qres = allres.qrid2_qres
    # loop over each query / result of interest
    for qrid, rid, score, rank in orgres.iter():
        query_gname, _ = os.path.splitext(
            ibs.tables.gx2_gname[ibs.tables.cx2_gx[qrid]])
        result_gname, _ = os.path.splitext(
            ibs.tables.gx2_gname[ibs.tables.cx2_gx[rid]])
        qres = qrid2_qres[qrid]
        df2.figure(fnum=1, plotnum=121)
        df2.show_matches_annote_res(qres, ibs, rid, fnum=1, plotnum=121)
        big_title = 'score=%.2f_rank=%d_q=%s_r=%s' % (score, rank, query_gname,
                                                      result_gname)
        df2.set_figtitle(big_title)
        viz.__dump_or_browse(allres,
                             orgres_type + '_matches' + allres.title_suffix)
Ejemplo n.º 25
0
def plot_seperability(hs, qcx_list, fnum=1):
    print('[dev] plot_seperability(fnum=%r)' % fnum)
    qcx2_res = get_qcx2_res(hs, qcx_list)
    qcx2_separability = get_seperatbility(hs, qcx2_res)
    sep_score_list = qcx2_separability.values()
    df2.figure(fnum=fnum, doclf=True, docla=True)
    print('[dev] seperability stats: ' + utool.stats_str(sep_score_list))
    sorted_sepscores = sorted(sep_score_list)
    df2.plot(sorted_sepscores, color=df2.DEEP_PINK, label='seperation score',
             yscale=YSCALE)
    df2.set_xlabel('true chipmatch index (%d)' % len(sep_score_list))
    df2.set_logyscale_from_data(sorted_sepscores)
    df2.dark_background()
    rowid = qcx2_res.itervalues().next().rowid
    df2.set_figtitle('seperability\n' + rowid)
    df2.legend()
    fnum += 1
    return fnum
Ejemplo n.º 26
0
def TEST_QUERY_COMP(ibs):
    print('[TEST_QUERY_COMP]')
    qaid_list = ibs.get_valid_aids()[0:1]
    print('[TEST_QUERY_COMP] len(qaid_list)=%r' % (qaid_list))
    ibs._init_query_requestor()
    qreq = ibs.qreq

    #query_helpers.find_matchable_chips(ibs)

    aids = ibs.get_recognition_database_aids()
    index = 0
    index = utool.get_arg('--index', type_=int, default=index)
    qaid_list = utool.safe_slice(aids, index, index + 1)

    comp_locals_ = query_helpers.get_query_components(ibs, qaid_list)
    qres_dict = OrderedDict([
        ('ORIG', comp_locals_['qres_ORIG']),
        ('FILT', comp_locals_['qres_FILT']),
        ('SVER', comp_locals_['qres_SVER']),
    ])

    top_aids = qres_dict['SVER'].get_top_aids(ibs)
    top_aids = utool.safe_slice(top_aids, 3)
    aid2 = top_aids[0]

    for px, (lbl, qres) in enumerate(six.iteritems(qres_dict)):
        print(lbl)
        fnum = df2.next_fnum()
        df2.figure(fnum=fnum, doclf=True)
        #viz_matches.show_matches(ibs, qres, aid2, fnum=fnum, in_image=True)
        #viz.show_qres(ibs, qres, fnum=fnum, top_aids=top_aids, ensure=False)
        interact.ishow_qres(ibs, qres, fnum=fnum, top_aids=top_aids, ensure=False)
        df2.set_figtitle(lbl)
        df2.adjust_subplots_safe(top=.8)

    fnum = df2.next_fnum()

    qaid2_svtups = comp_locals_['qaid2_svtups']
    qaid2_chipmatch_FILT = comp_locals_['qaid2_chipmatch_FILT']
    aid1 = qaid = comp_locals_['qaid']
    aid2_svtup  = qaid2_svtups[aid1]
    chipmatch_FILT = qaid2_chipmatch_FILT[aid1]
    viz.show_sver(ibs, aid1, aid2, chipmatch_FILT, aid2_svtup, fnum=fnum)
    return locals()
Ejemplo n.º 27
0
    def _select_ith_match(mx, qaid, aid):
        #----------------------
        # Get info for the _select_ith_match plot
        annote_ptr[0] = 1
        # Get the mx-th feature match
        aid1, aid2 = qaid, aid
        fx1, fx2 = fm[mx]
        fscore2  = qres.aid2_fs[aid2][mx]
        fk2      = qres.aid2_fk[aid2][mx]
        kpts1, kpts2 = ibs.get_annot_kpts([aid1, aid2])
        desc1, desc2 = ibs.get_annot_desc([aid1, aid2])
        kp1, kp2     = kpts1[fx1], kpts2[fx2]
        sift1, sift2 = desc1[fx1], desc2[fx2]
        info1 = '\nquery'
        info2 = '\nk=%r fscore=%r' % (fk2, fscore2)
        last_state.last_fx = fx1

        # Extracted keypoints to draw
        extracted_list = [(rchip1, kp1, sift1, fx1, aid1, info1),
                          (rchip2, kp2, sift2, fx2, aid2, info2)]
        # Normalizng Keypoint
        if hasattr(qres, 'filt2_meta') and 'lnbnn' in qres.filt2_meta:
            qfx2_norm = qres.filt2_meta['lnbnn']
            # Normalizing chip and feature
            (aid3, fx3, normk) = qfx2_norm[fx1]
            rchip3 = ibs.get_annot_chips(aid3)
            kp3 = ibs.get_annot_kpts(aid3)[fx3]
            sift3 = ibs.get_annot_desc(aid3)[fx3]
            info3 = '\nnorm %s k=%r' % (vh.get_aidstrs(aid3), normk)
            extracted_list.append((rchip3, kp3, sift3, fx3, aid3, info3))
        else:
            print('WARNING: meta doesnt exist')

        #----------------------
        # Draw the _select_ith_match plot
        nRows, nCols = len(extracted_list) + same_fig, 3
        # Draw matching chips and features
        sel_fm = np.array([(fx1, fx2)])
        pnum1 = (nRows, 1, 1) if same_fig else (1, 1, 1)
        _chipmatch_view(pnum1, vert=False, ell_alpha=.4, ell_linewidth=1.8,
                        colors=df2.BLUE, sel_fm=sel_fm, **kwargs)
        # Draw selected feature matches
        px = nCols * same_fig  # plot offset
        prevsift = None
        if not same_fig:
            fnum2 = fnum + len(viz.FNUMS)
            fig2 = df2.figure(fnum=fnum2, docla=True, doclf=True)
        else:
            fnum2 = fnum
        for (rchip, kp, sift, fx, aid, info) in extracted_list:
            px = draw_feat_row(rchip, fx, kp, sift, fnum2, nRows, nCols, px,
                               prevsift=prevsift, aid=aid, info=info)
            prevsift = sift
        if not same_fig:
            ih.connect_callback(fig2, 'button_press_event', _click_matches_click)
            df2.set_figtitle(figtitle + vh.get_vsstr(qaid, aid))
Ejemplo n.º 28
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
Ejemplo n.º 29
0
def dump_orgres_matches(allres, orgres_type):
    orgres = allres.__dict__[orgres_type]
    ibs = allres.ibs
    qcx2_res = allres.qcx2_res
    # loop over each query / result of interest
    for qcx, cx, score, rank in orgres.iter():
        query_gname, _ = os.path.splitext(
            ibs.tables.gx2_gname[ibs.tables.cx2_gx[qcx]])
        result_gname, _ = os.path.splitext(
            ibs.tables.gx2_gname[ibs.tables.cx2_gx[cx]])
        res = qcx2_res[qcx]
        df2.figure(fnum=FIGNUM, pnum=121)
        df2.show_matches3(res, ibs, cx, SV=False, fnum=FIGNUM, pnum=121)
        df2.show_matches3(res, ibs, cx, SV=True, fnum=FIGNUM, pnum=122)
        big_title = 'score=%.2f_rank=%d_q=%s_r=%s' % (score, rank, query_gname,
                                                      result_gname)
        df2.set_figtitle(big_title)
        __dump_or_browse(allres.ibs,
                         orgres_type + '_matches' + allres.title_suffix)
Ejemplo n.º 30
0
def plot_tt_bt_tf_matches(ibs, allres, qcx):
    #print('Visualizing result: ')
    #res.printme()
    res = allres.qcx2_res[qcx]
    ranks = (allres.top_true_qcx_arrays[0][qcx],
             allres.bot_true_qcx_arrays[0][qcx],
             allres.top_false_qcx_arrays[0][qcx])
    #scores = (allres.top_true_qcx_arrays[1][qcx],
    #allres.bot_true_qcx_arrays[1][qcx],
    #allres.top_false_qcx_arrays[1][qcx])
    cxs = (allres.top_true_qcx_arrays[2][qcx],
           allres.bot_true_qcx_arrays[2][qcx],
           allres.top_false_qcx_arrays[2][qcx])
    titles = ('best True rank=' + str(ranks[0]) + ' ',
              'worst True rank=' + str(ranks[1]) + ' ',
              'best False rank=' + str(ranks[2]) + ' ')
    df2.figure(fnum=1, pnum=231)
    res.plot_matches(res,
                     ibs,
                     cxs[0],
                     False,
                     fnum=1,
                     pnum=131,
                     title_aug=titles[0])
    res.plot_matches(res,
                     ibs,
                     cxs[1],
                     False,
                     fnum=1,
                     pnum=132,
                     title_aug=titles[1])
    res.plot_matches(res,
                     ibs,
                     cxs[2],
                     False,
                     fnum=1,
                     pnum=133,
                     title_aug=titles[2])
    fig_title = 'fig q' + ibs.cidstr(
        qcx) + ' TT BT TF -- ' + allres.title_suffix
    df2.set_figtitle(fig_title)
Ejemplo n.º 31
0
    def sv_view(self, dodraw=True):
        """ spatial verification view

        """
        #fnum = viz.FNUMS['special']
        aid = self.daid
        fnum = pt.next_fnum()
        fig = df2.figure(fnum=fnum, docla=True, doclf=True)
        ih.disconnect_callback(fig, 'button_press_event')
        viz.viz_sver.show_sver(self.ibs, self.qaid, aid2=aid, fnum=fnum)
        if dodraw:
            viz.draw()
Ejemplo n.º 32
0
    def sv_view(self, dodraw=True):
        """ spatial verification view

        """
        #fnum = viz.FNUMS['special']
        aid = self.daid
        fnum = pt.next_fnum()
        fig = df2.figure(fnum=fnum, docla=True, doclf=True)
        ih.disconnect_callback(fig, 'button_press_event')
        viz.viz_sver.show_sver(self.ibs, self.qaid, aid2=aid, fnum=fnum)
        if dodraw:
            viz.draw()
Ejemplo n.º 33
0
def TEST_figure1(wpatch, gradx, grady, gmag, gori, hist, centers):
    from plottool import draw_func2 as df2
    import plottool
    import vtool.patch as ptool
    print('[rotinvar] 4) Draw histogram with interpolation annotations')
    fnum = 1
    gorimag = plottool.color_orimag(gori, gmag, True)
    nRow, nCol = (2, 7)

    df2.figure(fnum=1, pnum=(nRow, 1, nRow), doclf=True, docla=True)
    plottool.draw_hist_subbin_maxima(hist, centers)
    df2.set_xlabel('grad orientation (radians)')
    df2.set_ylabel('grad magnitude')
    df2.set_title('dominant orientations')

    print('[rotinvar] 5) Show patch, gradients, magintude, and orientation')
    df2.imshow(wpatch, pnum=(nRow, nCol, 1), fnum=fnum, title='patch')
    df2.draw_vector_field(gradx,
                          grady,
                          pnum=(nRow, nCol, 2),
                          fnum=fnum,
                          title='gori (vec)')
    df2.imshow(gorimag, pnum=(nRow, nCol, 3), fnum=fnum, title='gori (col)')
    df2.imshow(np.abs(gradx), pnum=(nRow, nCol, 4), fnum=fnum, title='gradx')
    df2.imshow(np.abs(grady), pnum=(nRow, nCol, 5), fnum=fnum, title='grady')
    df2.imshow(gmag, pnum=(nRow, nCol, 6), fnum=fnum, title='gmag')

    gpatch = ptool.gaussian_patch(shape=gori.shape)
    df2.imshow(gpatch * 255,
               pnum=(nRow, nCol, 7),
               fnum=fnum,
               title='gauss weights',
               cmap_='hot')
    #gpatch3 = np.dstack((gpatch, gpatch, gpatch))
    #df2.draw_vector_field(gradx * gpatch, grady * gpatch, pnum=(nRow, nCol, 8), fnum=fnum, title='gori (vec)')
    #df2.imshow(gorimag * gpatch3, pnum=(nRow, nCol, 9), fnum=fnum, title='gori (col)')
    #df2.imshow(gradx * gpatch,   pnum=(nRow, nCol, 10), fnum=fnum, title='gradx')
    #df2.imshow(grady * gpatch,   pnum=(nRow, nCol, 11), fnum=fnum, title='grady')
    #df2.imshow(gmag * gpatch,    pnum=(nRow, nCol, 12), fnum=fnum, title='gmag')
    return locals()
Ejemplo n.º 34
0
def plot_tt_bt_tf_matches(ibs, allres, qcx):
    #print('Visualizing result: ')
    #res.printme()
    res = allres.qcx2_res[qcx]
    ranks = (allres.top_true_qcx_arrays[0][qcx],
             allres.bot_true_qcx_arrays[0][qcx],
             allres.top_false_qcx_arrays[0][qcx])
    #scores = (allres.top_true_qcx_arrays[1][qcx],
             #allres.bot_true_qcx_arrays[1][qcx],
             #allres.top_false_qcx_arrays[1][qcx])
    cxs = (allres.top_true_qcx_arrays[2][qcx],
           allres.bot_true_qcx_arrays[2][qcx],
           allres.top_false_qcx_arrays[2][qcx])
    titles = ('best True rank=' + str(ranks[0]) + ' ',
              'worst True rank=' + str(ranks[1]) + ' ',
              'best False rank=' + str(ranks[2]) + ' ')
    df2.figure(fnum=1, pnum=231)
    res.plot_matches(res, ibs, cxs[0], False, fnum=1, pnum=131, title_aug=titles[0])
    res.plot_matches(res, ibs, cxs[1], False, fnum=1, pnum=132, title_aug=titles[1])
    res.plot_matches(res, ibs, cxs[2], False, fnum=1, pnum=133, title_aug=titles[2])
    fig_title = 'fig q' + ibs.cidstr(qcx) + ' TT BT TF -- ' + allres.title_suffix
    df2.set_figtitle(fig_title)
Ejemplo n.º 35
0
def plot_score_matrix(allres):
    print('[viz] plotting score matrix')
    score_matrix = allres.score_matrix
    title = 'Score Matrix\n' + allres.title_suffix
    # Find inliers
    #inliers = util.find_std_inliers(score_matrix)
    #max_inlier = score_matrix[inliers].max()
    # Trunate above 255
    score_img = np.copy(score_matrix)
    #score_img[score_img < 0] = 0
    #score_img[score_img > 255] = 255
    #dim = 0
    #score_img = util.norm_zero_one(score_img, dim=dim)
    # Make colors
    scores = score_img.flatten()
    colors = df2.scores_to_color(scores, logscale=True)
    cmap = df2.scores_to_cmap(scores, colors)
    df2.figure(fnum=FIGNUM, doclf=True, title=title)
    # Show score matrix
    df2.imshow(score_img, fnum=FIGNUM, cmap=cmap)
    # Colorbar
    df2.colorbar(scores, colors)
    df2.set_xlabel('database')
    df2.set_ylabel('queries')
Ejemplo n.º 36
0
def plot_score_matrix(allres):
    print('[viz] plotting score matrix')
    score_matrix = allres.score_matrix
    title = 'Score Matrix\n' + allres.title_suffix
    # Find inliers
    #inliers = util.find_std_inliers(score_matrix)
    #max_inlier = score_matrix[inliers].max()
    # Trunate above 255
    score_img = np.copy(score_matrix)
    #score_img[score_img < 0] = 0
    #score_img[score_img > 255] = 255
    #dim = 0
    #score_img = util.norm_zero_one(score_img, dim=dim)
    # Make colors
    scores = score_img.flatten()
    colors = df2.scores_to_color(scores, logscale=True)
    cmap = df2.scores_to_cmap(scores, colors)
    df2.figure(fnum=FIGNUM, doclf=True, title=title)
    # Show score matrix
    df2.imshow(score_img, fnum=FIGNUM, cmap=cmap)
    # Colorbar
    df2.colorbar(scores, colors)
    df2.set_xlabel('database')
    df2.set_ylabel('queries')
Ejemplo n.º 37
0
 def prepare_page(self, pagenum):
     """ Gets indexes for the pagenum ready to be displayed """
     # Set the start index
     self.start_index = pagenum * self.nPerPage
     # Clip based on nCands
     self.nDisplay = min(self.nCands - self.start_index, self.nPerPage)
     nRows, nCols = ph.get_square_row_cols(self.nDisplay)
     # Create a grid to hold nPerPage
     self.pnum_ = df2.get_pnum_func(nRows, nCols)
     # Adjust stop index
     self.stop_index = self.start_index + self.nDisplay
     # Clear current figure
     self.clean_scope()
     self.fig = df2.figure(fnum=self.fnum, pnum=self.pnum_(0), doclf=True, docla=True)
     ih.disconnect_callback(self.fig, 'button_press_event')
     ih.connect_callback(self.fig, 'button_press_event', self.on_figure_clicked)
Ejemplo n.º 38
0
    def plot_annotationmatch(self, index, draw=True, make_buttons=True):
        self.select_candidate_match(index)
        # Get index relative to the page
        px = index - self.start_index
        pnum = self.pnum_(px)
        # Setup figure
        fnum = self.fnum
        fig = df2.figure(fnum=fnum, pnum=pnum, docla=True, doclf=False)
        fig
        #self.ax = ax = df2.gca()
        # Get viz params
        qres = self.current_qres
        aid1, aid2 = self.current_match_aids
        ibs = self.ibs
        kwargs = self.interactkw
        # Vizualize
        ax = viz_matches.show_matches(ibs,
                                      qres,
                                      aid2,
                                      self_fm=[],
                                      fnum=fnum,
                                      pnum=pnum,
                                      **kwargs)[0]

        divider = df2.ensure_divider(ax)

        name1, name2 = ibs.get_annot_names([aid1, aid2])
        #truth = self.ibs.get_match_truth(aid1, aid2)

        if make_buttons:
            butkw = {
                'divider': divider,
                'callback': self.match_reviewed,
                'index': index,
            }
            if name1 == name2 and not name1.startswith('____'):
                self.append_button(BREAK_MATCH_PREF, **butkw)
            else:
                if not name1.startswith('____'):
                    self.append_button(RENAME2_PREF + name1, **butkw)
                if not name2.startswith('____'):
                    self.append_button(RENAME1_PREF + name2, **butkw)
                if name1.startswith('____') and name2.startswith('____'):
                    self.append_button(NEW_MATCH_PREF, **butkw)

        if draw:
            vh.draw()
Ejemplo n.º 39
0
    def plot_annotationmatch(self, index, draw=True, make_buttons=True):
        printDBG('[ishow_qres] starting interaction')
        self.select_candidate_match(index)
        # Get index relative to the page
        px = index - self.start_index
        pnum = self.pnum_(px)
        #fnum = df2.kwargs_fnum(kwargs)
        #printDBG('[inter] starting %s interaction' % type_)
        # Setup figure
        fnum = self.fnum
        printDBG('\n<<<<  BEGIN %s INTERACTION >>>>' % (str('qres').upper()))
        fig = df2.figure(fnum=fnum, pnum=pnum, docla=True, doclf=False)
        printDBG(fig)
        #self.ax = ax = df2.gca()
        # Get viz params
        qres = self.current_qres
        aid1, aid2 = self.current_match_aids
        ibs = self.ibs
        kwargs = self.interactkw
        # Vizualize
        ax = viz_matches.show_matches(ibs, qres, aid2, self_fm=[], fnum=fnum,
                                      pnum=pnum, **kwargs)[0]

        divider = df2.ensure_divider(ax)

        name1, name2 = ibs.get_annot_names([aid1, aid2])
        #truth = self.ibs.get_match_truth(aid1, aid2)

        if make_buttons:
            butkw = {
                'divider': divider,
                'callback': self.match_reviewed,
                'index': index,
            }
            if name1 == name2 and not name1.startswith('____'):
                self.append_button(BREAK_MATCH_PREF, **butkw)
            else:
                if not name1.startswith('____'):
                    self.append_button(RENAME2_PREF + name1, **butkw)
                if not name2.startswith('____'):
                    self.append_button(RENAME1_PREF + name2, **butkw)
                if name1.startswith('____') and name2.startswith('____'):
                    self.append_button(NEW_MATCH_PREF, **butkw)

        if draw:
            vh.draw()
Ejemplo n.º 40
0
 def prepare_page(self, pagenum):
     """ Gets indexes for the pagenum ready to be displayed """
     # Set the start index
     self.start_index = pagenum * self.nPerPage
     # Clip based on nCands
     self.nDisplay = min(self.nCands - self.start_index, self.nPerPage)
     nRows, nCols = ph.get_square_row_cols(self.nDisplay)
     # Create a grid to hold nPerPage
     self.pnum_ = df2.get_pnum_func(nRows, nCols)
     # Adjust stop index
     self.stop_index = self.start_index + self.nDisplay
     # Clear current figure
     self.clean_scope()
     self.fig = df2.figure(fnum=self.fnum,
                           pnum=self.pnum_(0),
                           doclf=True,
                           docla=True)
     ih.disconnect_callback(self.fig, 'button_press_event')
     ih.connect_callback(self.fig, 'button_press_event',
                         self.on_figure_clicked)
Ejemplo n.º 41
0
def test_viz_image(img_fpath):
    # Read image
    img = cv2.imread(img_fpath)
    tau = np.pi * 2  # References: tauday.com
    # Create figure
    fig = df2.figure(fnum=42, pnum=(1, 1, 1))
    # Clear figure
    fig.clf()
    # Build parameters
    bbox_list = [dummy_bbox(img), dummy_bbox(img, (-.25, -.25), .1)]
    showkw = {
        'title': 'test axis title',
        # The list of bounding boxes to be drawn on the image
        'bbox_list': bbox_list,
        'theta_list': [tau * .7, tau * .9],
        'sel_list': [True, False],
        'label_list': ['test label', 'lbl2'],
    }
    # Print the keyword arguments to illustrate their format
    print('showkw = ' + utool.dict_str(showkw))
    # Display the image in figure-num 42, using a 1x1 axis grid in the first
    # axis. Pass showkw as keyword arguments.
    viz_image2.show_image(img, fnum=42, pnum=(1, 1, 1), **showkw)
    df2.set_figtitle('Test figure title')
Ejemplo n.º 42
0
def test_viz_image(img_fpath):
    # Read image
    img = cv2.imread(img_fpath)
    tau = np.pi * 2  # References: tauday.com
    # Create figure
    fig = df2.figure(fnum=42, pnum=(1, 1, 1))
    # Clear figure
    fig.clf()
    # Build parameters
    bbox_list = [dummy_bbox(img), dummy_bbox(img, (-0.25, -0.25), 0.1)]
    showkw = {
        "title": "test axis title",
        # The list of bounding boxes to be drawn on the image
        "bbox_list": bbox_list,
        "theta_list": [tau * 0.7, tau * 0.9],
        "sel_list": [True, False],
        "label_list": ["test label", "lbl2"],
    }
    # Print the keyword arguments to illustrate their format
    print("showkw = " + utool.dict_str(showkw))
    # Display the image in figure-num 42, using a 1x1 axis grid in the first
    # axis. Pass showkw as keyword arguments.
    viz_image2.show_image(img, fnum=42, pnum=(1, 1, 1), **showkw)
    df2.set_figtitle("Test figure title")
Ejemplo n.º 43
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
Ejemplo n.º 44
0
def dump_feature_pair_analysis(allres):
    print('[rr2] Doing: feature pair analysis')
    # TODO: Measure score consistency over a spatial area.
    # Measures entropy of matching vs nonmatching descriptors
    # Measures scale of m vs nm desc
    ibs = allres.ibs
    qrid2_qres = allres.qrid2_qres

    def _hist_prob_x(desc, bw_factor):
        # Choose number of bins based on the bandwidth
        bin_range = (0, 256)  # assuming input is uint8
        bins = bin_range[1] // bw_factor
        bw_factor = bin_range[1] / bins
        # Compute the probabilty mass function, each w.r.t a single descriptor
        hist_params = dict(bins=bins, range=bin_range, density=True)
        hist_func = np.histogram
        desc_pmf = [hist_func(d, **hist_params)[0] for d in desc]
        # Compute the probability that you saw what you saw
        # TODO: could use linear interpolation for a bit more robustness here
        bin_vals = [
            np.array(np.floor(d / bw_factor), dtype=np.uint8) for d in desc
        ]
        hist_prob_x = [pmf[vals] for pmf, vals in zip(desc_pmf, bin_vals)]
        return hist_prob_x

    def _gkde_prob_x(desc, bw_factor):
        # Estimate the probabilty density function, each w.r.t a single descriptor
        gkde_func = scipy.stats.gaussian_kde
        desc_pdf = [gkde_func(d, bw_factor) for d in desc]
        gkde_prob_x = [pdf(d) for pdf, d in zip(desc_pdf, desc)]
        return gkde_prob_x

    def descriptor_entropy(desc, bw_factor=4):
        'computes the shannon entropy of each descriptor in desc'
        # Compute shannon entropy = -sum(p(x)*log(p(x)))
        prob_x = _hist_prob_x(desc, bw_factor)
        entropy = [-(px * np.log2(px)).sum() for px in prob_x]
        return entropy

    # Load features if we need to
    if ibs.feats.cx2_desc.size == 0:
        print(' * forcing load of descriptors')
        ibs.load_features()
    cx2_desc = ibs.feats.cx2_desc
    cx2_kpts = ibs.feats.cx2_kpts

    def measure_feat_pairs(allres, orgtype='top_true'):
        print('Measure ' + orgtype + ' pairs')
        orgres = allres.__dict__[orgtype]
        entropy_list = []
        scale_list = []
        score_list = []
        lbl = 'Measuring ' + orgtype + ' pair '
        fmt_str = utool.make_progress_fmt_str(len(orgres), lbl)
        rank_skips = []
        gt_skips = []
        for ix, (qrid, rid, score, rank) in enumerate(orgres.iter()):
            utool.print_(fmt_str % (ix + 1, ))
            # Skip low ranks
            if rank > 5:
                rank_skips.append(qrid)
                continue
            other_rids = ibs.get_other_indexed_rids(qrid)
            # Skip no groundtruth
            if len(other_rids) == 0:
                gt_skips.append(qrid)
                continue
            qres = qrid2_qres[qrid]
            # Get matching feature indexes
            fm = qres.cx2_fm[rid]
            # Get their scores
            fs = qres.cx2_fs[rid]
            # Get matching descriptors
            printDBG('\nfm.shape=%r' % (fm.shape, ))
            desc1 = cx2_desc[qrid][fm[:, 0]]
            desc2 = cx2_desc[rid][fm[:, 1]]
            # Get matching keypoints
            kpts1 = cx2_kpts[qrid][fm[:, 0]]
            kpts2 = cx2_kpts[rid][fm[:, 1]]
            # Get their scale
            scale1_m = ktool.get_scales(kpts1)
            scale2_m = ktool.get_scales(kpts2)
            # Get their entropy
            entropy1 = descriptor_entropy(desc1, bw_factor=1)
            entropy2 = descriptor_entropy(desc2, bw_factor=1)
            # Append to results
            entropy_tup = np.array(zip(entropy1, entropy2))
            scale_tup = np.array(zip(scale1_m, scale2_m))
            entropy_tup = entropy_tup.reshape(len(entropy_tup), 2)
            scale_tup = scale_tup.reshape(len(scale_tup), 2)
            entropy_list.append(entropy_tup)
            scale_list.append(scale_tup)
            score_list.append(fs)
        print('Skipped %d total.' % (len(rank_skips) + len(gt_skips), ))
        print('Skipped %d for rank > 5, %d for no gt' % (
            len(rank_skips),
            len(gt_skips),
        ))
        print(np.unique(map(len, entropy_list)))

        def evstack(tup):
            return np.vstack(tup) if len(tup) > 0 else np.empty((0, 2))

        def ehstack(tup):
            return np.hstack(tup) if len(tup) > 0 else np.empty((0, 2))

        entropy_pairs = evstack(entropy_list)
        scale_pairs = evstack(scale_list)
        scores = ehstack(score_list)
        print('\n * Measured %d pairs' % len(entropy_pairs))
        return entropy_pairs, scale_pairs, scores

    tt_entropy, tt_scale, tt_scores = measure_feat_pairs(allres, 'top_true')
    tf_entropy, tf_scale, tf_scores = measure_feat_pairs(allres, 'top_false')

    # Measure ratios
    def measure_ratio(arr):
        return arr[:, 0] / arr[:, 1] if len(arr) > 0 else np.array([])

    tt_entropy_ratio = measure_ratio(tt_entropy)
    tf_entropy_ratio = measure_ratio(tf_entropy)
    tt_scale_ratio = measure_ratio(tt_scale)
    tf_scale_ratio = measure_ratio(tf_scale)

    title_suffix = allres.title_suffix

    # Entropy vs Score
    df2.figure(fnum=1, docla=True)
    df2.figure(fnum=1, plotnum=(2, 2, 1))
    df2.plot2(tt_entropy[:, 0], tt_scores, 'gx', 'entropy1', 'score',
              'Top True')
    df2.figure(fnum=1, plotnum=(2, 2, 2))
    df2.plot2(tf_entropy[:, 0], tf_scores, 'rx', 'entropy1', 'score',
              'Top False')
    df2.figure(fnum=1, plotnum=(2, 2, 3))
    df2.plot2(tt_entropy[:, 1], tt_scores, 'gx', 'entropy2', 'score',
              'Top True')
    df2.figure(fnum=1, plotnum=(2, 2, 4))
    df2.plot2(tf_entropy[:, 1], tf_scores, 'rx', 'entropy2', 'score',
              'Top False')
    df2.set_figtitle('Entropy vs Score -- ' + title_suffix)
    viz.__dump_or_browse(allres, 'pair_analysis')

    # Scale vs Score
    df2.figure(fnum=2, plotnum=(2, 2, 1), docla=True)
    df2.plot2(tt_scale[:, 0], tt_scores, 'gx', 'scale1', 'score', 'Top True')
    df2.figure(fnum=2, plotnum=(2, 2, 2))
    df2.plot2(tf_scale[:, 0], tf_scores, 'rx', 'scale1', 'score', 'Top False')
    df2.figure(fnum=2, plotnum=(2, 2, 3))
    df2.plot2(tt_scale[:, 1], tt_scores, 'gx', 'scale2', 'score', 'Top True')
    df2.figure(fnum=2, plotnum=(2, 2, 4))
    df2.plot2(tf_scale[:, 1], tf_scores, 'rx', 'scale2', 'score', 'Top False')
    df2.set_figtitle('Scale vs Score -- ' + title_suffix)
    viz.__dump_or_browse(allres, 'pair_analysis')

    # Entropy Ratio vs Score
    df2.figure(fnum=3, plotnum=(1, 2, 1), docla=True)
    df2.plot2(tt_entropy_ratio, tt_scores, 'gx', 'entropy-ratio', 'score',
              'Top True')
    df2.figure(fnum=3, plotnum=(1, 2, 2))
    df2.plot2(tf_entropy_ratio, tf_scores, 'rx', 'entropy-ratio', 'score',
              'Top False')
    df2.set_figtitle('Entropy Ratio vs Score -- ' + title_suffix)
    viz.__dump_or_browse(allres, 'pair_analysis')

    # Scale Ratio vs Score
    df2.figure(fnum=4, plotnum=(1, 2, 1), docla=True)
    df2.plot2(tt_scale_ratio, tt_scores, 'gx', 'scale-ratio', 'score',
              'Top True')
    df2.figure(fnum=4, plotnum=(1, 2, 2))
    df2.plot2(tf_scale_ratio, tf_scores, 'rx', 'scale-ratio', 'score',
              'Top False')
    df2.set_figtitle('Entropy Ratio vs Score -- ' + title_suffix)
    viz.__dump_or_browse(allres, 'pair_analysis')
Ejemplo n.º 45
0
 def _start_interaction(self):
     #self.fig = df2.figure(fnum=self.fnum, doclf=True, docla=True)
     self.fig = df2.figure(fnum=self.fnum, doclf=True)
     ih.connect_callback(self.fig, 'close_event', self.on_close)
     register_interaction(self)
     self.is_running = True
Ejemplo n.º 46
0
    def select_ith_match(self, mx):
        """
        Selects the ith match and visualizes and prints information concerning
        features weights, keypoint details, and sift descriptions

        Args:
            mx (int) - the ith match to visualize
            qaid (int) - query annotation id
            aid (int) - database annotation id

        CommandLine:
            python -m ibeis.viz.interact.interact_matches --test-select_ith_match --show

        Example:
            >>> # DISABLE_DOCTEST
            >>> from ibeis.viz.interact.interact_matches import *  # NOQA
            >>> self = testdata_match_interact(mx=1)
            >>> pt.show_if_requested()
        """
        ibs = self.ibs
        qaid = self.qaid
        aid = self.daid
        fnum = self.fnum
        figtitle = self.figtitle
        rchip1 = self.rchip1
        rchip2 = self.rchip2
        aid = self.daid
        same_fig = self.same_fig
        self.mx = mx
        print('+--- SELECT --- ')
        print('qaid=%r, daid=%r' % (qaid, aid))
        print('... selecting mx-th=%r feature match' % mx)
        if False:
            print('score stats:')
            print(ut.get_stats_str(self.fsv, axis=0, newlines=True))
            print('fsv[mx] = %r' % (self.fsv[mx], ))
            print('fs[mx] = %r' % (self.fs[mx], ))
        """
        # test feature weights of actual chips
        fx1, fx2 = fm[mx]
        daid = aid
        ibs.get_annot_fgweights([daid])[0][fx2]
        ibs.get_annot_fgweights([qaid])[0][fx1]
        """
        #----------------------
        # Get info for the select_ith_match plot
        self.mode = 1
        # Get the mx-th feature match
        fx1, fx2 = self.fm[mx]
        fscore2 = self.fs[mx]
        fk2 = self.fk[mx]
        kpts1 = ibs.get_annot_kpts([self.qaid],
                                   config2_=self.query_config2_)[0]
        kpts2 = ibs.get_annot_kpts([self.daid], config2_=self.data_config2_)[0]
        desc1 = ibs.get_annot_vecs([self.qaid],
                                   config2_=self.query_config2_)[0]
        desc2 = ibs.get_annot_vecs([self.daid], config2_=self.data_config2_)[0]
        kp1, kp2 = kpts1[fx1], kpts2[fx2]
        sift1, sift2 = desc1[fx1], desc2[fx2]
        info1 = '\nquery'
        info2 = '\nk=%r fscore=%r' % (fk2, fscore2)
        #last_state.last_fx = fx1
        self.last_fx = fx1
        # Extracted keypoints to draw
        extracted_list = [(rchip1, kp1, sift1, fx1, self.qaid, info1),
                          (rchip2, kp2, sift2, fx2, self.daid, info2)]
        # Normalizng Keypoint
        #if hasattr(cm, 'filt2_meta') and 'lnbnn' in cm.filt2_meta:
        #    qfx2_norm = cm.filt2_meta['lnbnn']
        #    # Normalizing chip and feature
        #    (aid3, fx3, normk) = qfx2_norm[fx1]
        #    rchip3 = ibs.get_annot_chips(aid3)
        #    kp3 = ibs.get_annot_kpts(aid3)[fx3]
        #    sift3 = ibs.get_annot_vecs(aid3)[fx3]
        #    info3 = '\nnorm %s k=%r' % (vh.get_aidstrs(aid3), normk)
        #    extracted_list.append((rchip3, kp3, sift3, fx3, aid3, info3))
        #else:
        #    pass
        # print('WARNING: meta doesnt exist')

        #----------------------
        # Draw the select_ith_match plot
        nRows, nCols = len(extracted_list) + same_fig, 3
        # Draw matching chips and features
        sel_fm = np.array([(fx1, fx2)])
        pnum1 = (nRows, 1, 1) if same_fig else (1, 1, 1)
        vert = self.vert if self.vert is not None else False
        self.chipmatch_view(pnum1,
                            ell_alpha=.4,
                            ell_linewidth=1.8,
                            colors=df2.BLUE,
                            sel_fm=sel_fm,
                            vert=vert)
        # Draw selected feature matches
        px = nCols * same_fig  # plot offset
        prevsift = None
        if not same_fig:
            #fnum2 = fnum + len(viz.FNUMS)
            fnum2 = self.fnum2
            fig2 = df2.figure(fnum=fnum2, docla=True, doclf=True)
        else:
            fnum2 = fnum
        for (rchip, kp, sift, fx, aid, info) in extracted_list:
            px = viz_featrow.draw_feat_row(rchip,
                                           fx,
                                           kp,
                                           sift,
                                           fnum2,
                                           nRows,
                                           nCols,
                                           px,
                                           prevsift=prevsift,
                                           aid=aid,
                                           info=info)
            prevsift = sift
        if not same_fig:
            ih.connect_callback(fig2, 'button_press_event', self.on_click)
            df2.set_figtitle(figtitle + vh.get_vsstr(qaid, aid))
Ejemplo n.º 47
0
def plot_scores(hs, qcx_list, fnum=1):
    print('[dev] plot_scores(fnum=%r)' % fnum)
    topN_gt    = 1
    topN_ranks = 3
    qcx2_res = get_qcx2_res(hs, qcx_list)
    data_scores = []  # matching scores
    data_qpairs = []  # query info (qcx, cx)
    data_gtranks = []  # query info (gtrank)
    # Append all scores to a giant list
    for res in qcx2_res.itervalues():
        # Get gt scores first
        qcx = res.qcx
        top_cxs = np.array(res.topN_cxs(hs, N=topN_ranks, only_gt=False))
        gt_cxs  = np.array(res.topN_cxs(hs, N=topN_gt, only_gt=True))
        top_scores = res.cx2_score[top_cxs]
        np.intersect1d(top_cxs, gt_cxs)
        # list of ranks if score is ground truth otherwise -1
        isgt_ranks = [tx if cx in set(gt_cxs) else -1 for (tx, cx) in enumerate(top_cxs)]
        qcx_pairs  = [(hs.cx2_cid(qcx), hs.cx2_cid(cx)) for cx in top_cxs]
        # Append all scores
        data_scores.extend(top_scores.tolist())
        data_qpairs.extend(qcx_pairs)
        data_gtranks.extend(isgt_ranks)
    data_scores = np.array(data_scores)
    data_qpairs = np.array(data_qpairs)
    data_gtranks = np.array(data_gtranks)

    data_sortx = data_scores.argsort()
    sorted_scores = data_scores[data_sortx]

    # Draw and info
    rank_colorbounds = [
        ((-1, 0), df2.GRAY),
        ((0, 1), df2.TRUE_GREEN),
        ((1, 5), df2.UNKNOWN_PURP),
        ((5, None), df2.FALSE_RED),
    ]
    print('[dev] matching chipscore stats: ' + utool.stats_str(data_scores))
    df2.figure(fnum=fnum, doclf=True, docla=True)
    # Finds the knee
    df2.plot(sorted_scores, color=df2.ORANGE, label='all scores')

    # Plot results with ranks within (low, high) bounds
    colorbounds_iter = reversed(list(enumerate(rank_colorbounds)))
    for count, ((low, high), rankX_color) in colorbounds_iter:
        datarank_flag = utool.inbounds(data_gtranks, low, high)
        rankX_xs = np.where(datarank_flag[data_sortx])[0]
        rankX_ys = sorted_scores[rankX_xs]
        if high is None:
            rankX_label = '%d <= gt rank' % low
        else:
            rankX_label = '%d <= gt rank < %d' % (low, high)
        if len(rankX_ys) > 0:
            df2.plot(rankX_xs, rankX_ys, 'o', color=rankX_color, label=rankX_label, alpha=.5)

    rowid = qcx2_res.itervalues().next().rowid

    df2.set_logyscale_from_data(data_scores)

    df2.set_xlabel('chipmatch index')
    df2.dark_background()
    df2.set_figtitle('matching scores\n' + rowid)
    df2.legend(loc='upper left')
    df2.iup()
    fnum += 1

    score_table = np.vstack((data_scores, data_gtranks, data_qpairs.T)).T
    score_table = score_table[data_sortx[::-1]]

    column_labels = ['score', 'gtrank', 'qcid', 'cid']
    header = 'score_table\nuid=%r' % rowid
    column_type = [float, int, int, int]
    csv_txt = utool.util_csv.numpy_to_csv(score_table,  column_labels, header, column_type)
    print(csv_txt)
    #utool.embed()
    return fnum
Ejemplo n.º 48
0
def show_sv(chip1,
            chip2,
            kpts1,
            kpts2,
            fm,
            homog_tup=None,
            aff_tup=None,
            mx=None,
            show_assign=True,
            show_lines=True,
            show_kpts=True,
            show_aff=None,
            fnum=1,
            refine_method=None,
            **kwargs):
    """ Visualizes spatial verification

    CommandLine:
        python -m vtool.spatial_verification --test-spatially_verify_kpts --show

    """
    #import plottool as pt
    # GEt Matching chips
    kpts1_m = kpts1[fm.T[0]]
    kpts2_m = kpts2[fm.T[1]]
    wh2 = vt.get_size(chip2)
    #
    # Get Affine Chips, Keypoints, Inliers
    if show_aff is None:
        show_aff_ = aff_tup is not None
    else:
        show_aff_ = show_aff
    if show_aff_:
        (aff_inliers, Aff) = aff_tup
        chip1_At = vt.warpAffine(chip1, Aff, wh2)
        #kpts1_mAt = ktool.transform_kpts(kpts1_m, Aff)
        chip2_blendA = vt.blend_images(chip1_At, chip2)
    #
    # Get Homog Chips, Keypoints, Inliers
    show_homog = homog_tup is not None
    if show_homog:
        (hom_inliers, H) = homog_tup
        #kpts1_mHt = ktool.transform_kpts(kpts1_m, H)
        chip1_Ht = vt.warpHomog(chip1, H, wh2)
        chip2_blendH = vt.blend_images(chip1_Ht, chip2)
    #
    # Drawing settings
    nRows = (show_assign) + (show_aff_) + (show_homog)
    nCols1 = (show_assign) + (show_aff_) + (show_homog)
    nCols2 = 2
    pnum1_ = df2.get_pnum_func(nRows, nCols1)
    pnum2_ = df2.get_pnum_func(nRows, nCols2)
    #in_kwargs  = dict(rect=True,  ell_alpha=.7, eig=False, ori=True, pts=True)
    #out_kwargs = dict(rect=False, ell_alpha=.3, eig=False)
    in_kwargs = dict(rect=False, ell_alpha=.7, eig=False, ori=False, pts=False)
    out_kwargs = dict(rect=False, ell_alpha=.7, eig=False, ori=False)

    def _draw_kpts(*args, **kwargs):
        if not show_kpts:
            return
        df2.draw_kpts2(*args, **kwargs)

    def draw_inlier_kpts(kpts_m, inliers, color, H=None):
        _draw_kpts(kpts_m[inliers], color=color, H=H, **in_kwargs)
        if mx is not None:
            _draw_kpts(kpts_m[mx:(mx + 1)],
                       color=color,
                       ell_linewidth=3,
                       H=H,
                       **in_kwargs)

    def _draw_matches(px, title, inliers):
        dmkwargs = dict(fs=None,
                        title=title,
                        all_kpts=False,
                        draw_lines=True,
                        docla=True,
                        draw_border=True,
                        fnum=fnum,
                        pnum=pnum1_(px),
                        colors=df2.ORANGE)
        __fm = np.vstack((inliers, inliers)).T
        df2.show_chipmatch2(chip1, chip2, kpts1_m, kpts2_m, __fm, **dmkwargs)
        return px + 1

    from plottool import color_funcs
    colors = df2.distinct_colors(2, brightness=.95)
    color1, color2 = colors[0], colors[1]
    color1_dark = color_funcs.darken_rgb(color1, .2)
    color2_dark = color_funcs.darken_rgb(color2, .2)

    def _draw_chip(px, title, chip, inliers, kpts1_m, kpts2_m, H1=None):
        if isinstance(px, tuple):
            pnum = px
            df2.imshow(chip, title=title, fnum=fnum, pnum=pnum)
            px = pnum[2]
        else:
            df2.imshow(chip, title=title, fnum=fnum, pnum=pnum2_(px))
        if kpts1_m is not None:
            _draw_kpts(kpts1_m, color=color1_dark, H=H1, **out_kwargs)
            draw_inlier_kpts(kpts1_m, inliers, color1, H=H1)
        if kpts2_m is not None:
            _draw_kpts(kpts2_m, color=color2_dark, **out_kwargs)
            draw_inlier_kpts(kpts2_m, inliers, color2)
        if kpts2_m is not None and kpts1_m is not None and show_lines:
            __fm = np.vstack((inliers, inliers)).T
            df2.draw_lines2(kpts1_m,
                            kpts2_m,
                            __fm,
                            color_list=[custom_constants.ORANGE],
                            lw=2,
                            line_alpha=1,
                            H1=H1)
        return px + 1

    #
    # Begin the drawing
    df2.figure(fnum=fnum, pnum=(nRows, nCols1, 1), docla=True, doclf=True)
    px = 0
    if show_assign:
        # Draw the Assigned -> Affine -> Homography matches
        px = _draw_matches(px, '%d Assigned matches  ' % len(fm),
                           np.arange(len(fm)))
        if show_aff_:
            px = _draw_matches(px, '%d Initial inliers    ' % len(aff_inliers),
                               aff_inliers)
        if show_homog:
            if refine_method is None:
                refine_method = ''

            if len(refine_method) > 0:
                refine_method_ = '(%s) ' % (refine_method, )
            else:
                refine_method_ = ''
            px = _draw_matches(
                px,
                '%d Refined %sinliers' % (len(hom_inliers), refine_method_),
                hom_inliers)
    #
    # Draw the Affine Transformations
    px = nCols2 * show_assign
    #if show_aff_ or show_homog:

    if show_aff_:
        #px = _draw_chip(px, 'Source',    chip1,        aff_inliers,   kpts1_m, None)
        #px = _draw_chip(px, 'Dest',      chip2,        aff_inliers,   None, kpts2_m)
        px = _draw_chip(px,
                        'Initial Warped',
                        chip1_At,
                        aff_inliers,
                        kpts1_m,
                        None,
                        H1=Aff)
        px = _draw_chip(px,
                        'Initial Blend',
                        chip2_blendA,
                        aff_inliers,
                        kpts1_m,
                        kpts2_m,
                        H1=Aff)
        #px = _draw_chip(px, 'Affine',    chip1_At,     aff_inliers, kpts1_mAt, None)
        #px = _draw_chip(px, 'Aff Blend', chip2_blendA, aff_inliers, kpts1_mAt, kpts2_m)
        pass
    #
    # Draw the Homography Transformation
    if show_homog:
        #px = _draw_chip(px, 'Source',      chip1,        hom_inliers,   kpts1_m, None)
        #px = _draw_chip(px, 'Dest',        chip2,        hom_inliers,   None, kpts2_m)
        #px = _draw_chip(px, 'Homog',       chip1_Ht,     hom_inliers, kpts1_mHt, None)
        #px = _draw_chip(px, 'Homog Blend', chip2_blendH, hom_inliers, kpts1_mHt, kpts2_m)
        px = _draw_chip(px,
                        'Refined Warped',
                        chip1_Ht,
                        hom_inliers,
                        kpts1_m,
                        None,
                        H1=H)
        px = _draw_chip(px,
                        'Refined Blend',
                        chip2_blendH,
                        hom_inliers,
                        kpts1_m,
                        kpts2_m,
                        H1=H)
Ejemplo n.º 49
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()
Ejemplo n.º 50
0
def test_ori_extract_main():
    """
    CommandLine:
        python -m pyhesaff.tests.test_exhaustive_ori_extract --test-test_ori_extract_main
        python -m pyhesaff.tests.test_exhaustive_ori_extract --test-test_ori_extract_main --show

    Example:
        >>> # GUI_DOCTEST
        >>> from pyhesaff.tests.test_exhaustive_ori_extract import *  # NOQA
        >>> test_ori_extract_main()
        >>> ut.show_if_requested()
    """
    import pyhesaff
    from plottool import draw_func2 as df2
    from plottool.viz_keypoints import show_keypoints
    import vtool  # NOQA
    import vtool.image as gtool
    import vtool.keypoint as ktool
    np.set_printoptions(threshold=5000, linewidth=5000, precision=3)
    # Read data
    print('[rotinvar] loading test data')

    img_fpath = ut.grab_test_imgpath('jeff.png')
    imgL = gtool.cvt_BGR2L(gtool.imread(img_fpath))
    detect_kw0 = {}
    detect_kw1 = {'scale_min': 20, 'scale_max': 100}
    detect_kw2 = {'scale_min': 40, 'scale_max': 60}
    detect_kw3 = {'scale_min': 45, 'scale_max': 49}

    # Remove skew and anisotropic scaling
    def force_isotropic(kpts):
        kpts_ = kpts.copy()
        kpts_[:, ktool.SKEW_DIM] = 0
        kpts_[:, ktool.SCAX_DIM] = kpts_[:, ktool.SCAY_DIM]
        vecs_ = pyhesaff.extract_vecs(img_fpath, kpts_)
        return kpts_, vecs_

    def force_ori(kpts, ori):
        kpts_ = kpts.copy()
        kpts_[:, ktool.ORI_DIM] = ori
        vecs_ = pyhesaff.extract_vecs(img_fpath, kpts_)
        return kpts_, vecs_

    def shift_kpts(kpts, x, y):
        kpts_ = kpts.copy()
        kpts_[:, ktool.XDIM] += x
        kpts_[:, ktool.YDIM] += y
        vecs_ = pyhesaff.extract_vecs(img_fpath, kpts_)
        return kpts_, vecs_

    # --- Experiment ---
    kpts0, vecs0 = double_detect(img_fpath, **detect_kw0)
    kpts1, vecs1 = double_detect(img_fpath, **detect_kw1)
    kpts2, vecs2 = double_detect(img_fpath, **detect_kw2)
    #
    kpts3, vecs3 = double_detect(img_fpath, **detect_kw3)
    kpts4, vecs4 = force_isotropic(kpts3)
    kpts5, vecs5 = force_ori(kpts3, 1.45)
    kpts6, vecs6 = shift_kpts(kpts5, -60, -50)
    kpts7, vecs7 = force_ori(kpts6, 0)
    kpts8, vecs8 = force_ori(kpts7, 2.40)
    kpts9, vecs9 = force_ori(kpts8, 5.40)
    kpts10, vecs10 = force_ori(kpts9, 10.40)

    # --- Print ---

    # ---- Draw ----
    nRow, nCol = 1, 2
    df2.figure(fnum=2, doclf=True, docla=True)
    df2.figure(fnum=1, doclf=True, docla=True)

    def show_kpts_(fnum, pnum, kpts, vecs, title):
        print('--------')
        print('show_kpts: %r.%r' % (fnum, pnum))
        print('kpts  = %r' % (kpts, ))
        print('scales = %r' % ktool.get_scales(kpts))
        # FIXME: this exists in ibeis. move to vtool
        #dev_consistency.check_vecs(vecs3)

        show_keypoints(imgL,
                       kpts,
                       sifts=vecs,
                       pnum=pnum,
                       rect=True,
                       ori=True,
                       fnum=fnum,
                       title=title,
                       ell_alpha=1)

    show_kpts_(1, (nRow, nCol, 1), kpts3, vecs3, 'kpts3: original')
    show_kpts_(1, (nRow, nCol, 2), kpts4, vecs4, 'kpts4: isotropic + redetect')
    show_kpts_(2, (2, 3, 1), kpts5, vecs5, 'kpts5: force_ori + redetect')
    show_kpts_(2, (2, 3, 2), kpts6, vecs6, 'kpts6: shift')
    show_kpts_(2, (2, 3, 3), kpts7, vecs7, 'kpts7: shift + reorient')
    show_kpts_(2, (2, 3, 4), kpts8, vecs8, 'kpts8: shift + reorient')
    show_kpts_(2, (2, 3, 5), kpts9, vecs9, 'kpts9: reorient')
    show_kpts_(2, (2, 3, 6), kpts10, vecs10, 'kpts10: reorient')
Ejemplo n.º 51
0
 def _viz_keypoints(fnum, pnum=(1, 1, 1), **kwargs):
     df2.figure(fnum=fnum, docla=True, doclf=True)
     show_keypoints(chip, kpts, fnum=fnum, pnum=pnum, **kwargs)
     if figtitle is not None:
         df2.set_figtitle(figtitle)
Ejemplo n.º 52
0
def test_ori_extract_main():
    """
    CommandLine:
        python -m pyhesaff.tests.test_exhaustive_ori_extract --test-test_ori_extract_main
        python -m pyhesaff.tests.test_exhaustive_ori_extract --test-test_ori_extract_main --show

    Example:
        >>> # GUI_DOCTEST
        >>> from pyhesaff.tests.test_exhaustive_ori_extract import *  # NOQA
        >>> test_ori_extract_main()
        >>> ut.show_if_requested()
    """
    import pyhesaff
    from plottool import draw_func2 as df2
    from plottool.viz_keypoints import show_keypoints
    import vtool  # NOQA
    import vtool.image as gtool
    import vtool.keypoint as ktool
    np.set_printoptions(threshold=5000, linewidth=5000, precision=3)
    # Read data
    print('[rotinvar] loading test data')

    img_fpath = ut.grab_test_imgpath('jeff.png')
    imgL = gtool.cvt_BGR2L(gtool.imread(img_fpath))
    detect_kw0 = {
    }
    detect_kw1 = {
        'scale_min': 20,
        'scale_max': 100
    }
    detect_kw2 = {
        'scale_min': 40,
        'scale_max': 60
    }
    detect_kw3 = {
        'scale_min': 45,
        'scale_max': 49
    }
    # Remove skew and anisotropic scaling
    def force_isotropic(kpts):
        kpts_ = kpts.copy()
        kpts_[:, ktool.SKEW_DIM] = 0
        kpts_[:, ktool.SCAX_DIM] = kpts_[:, ktool.SCAY_DIM]
        vecs_ = pyhesaff.extract_vecs(img_fpath, kpts_)
        return kpts_, vecs_

    def force_ori(kpts, ori):
        kpts_ = kpts.copy()
        kpts_[:, ktool.ORI_DIM] = ori
        vecs_ = pyhesaff.extract_vecs(img_fpath, kpts_)
        return kpts_, vecs_

    def shift_kpts(kpts, x, y):
        kpts_ = kpts.copy()
        kpts_[:, ktool.XDIM] += x
        kpts_[:, ktool.YDIM] += y
        vecs_ = pyhesaff.extract_vecs(img_fpath, kpts_)
        return kpts_, vecs_

    # --- Experiment ---
    kpts0, vecs0 = double_detect(img_fpath, **detect_kw0)
    kpts1, vecs1 = double_detect(img_fpath, **detect_kw1)
    kpts2, vecs2 = double_detect(img_fpath, **detect_kw2)
    #
    kpts3, vecs3 = double_detect(img_fpath, **detect_kw3)
    kpts4, vecs4 = force_isotropic(kpts3)
    kpts5, vecs5 = force_ori(kpts3, 1.45)
    kpts6, vecs6 = shift_kpts(kpts5, -60, -50)
    kpts7, vecs7 = force_ori(kpts6, 0)
    kpts8, vecs8 = force_ori(kpts7, 2.40)
    kpts9, vecs9 = force_ori(kpts8, 5.40)
    kpts10, vecs10 = force_ori(kpts9, 10.40)

    # --- Print ---

    # ---- Draw ----
    nRow, nCol = 1, 2
    df2.figure(fnum=2, doclf=True, docla=True)
    df2.figure(fnum=1, doclf=True, docla=True)

    def show_kpts_(fnum, pnum, kpts, vecs, title):
        print('--------')
        print('show_kpts: %r.%r' % (fnum, pnum))
        print('kpts  = %r' % (kpts,))
        print('scales = %r' % ktool.get_scales(kpts))
        # FIXME: this exists in ibeis. move to vtool
        #dev_consistency.check_vecs(vecs3)

        show_keypoints(imgL, kpts, sifts=vecs, pnum=pnum, rect=True,
                       ori=True, fnum=fnum, title=title, ell_alpha=1)

    show_kpts_(1, (nRow, nCol, 1), kpts3, vecs3, 'kpts3: original')
    show_kpts_(1, (nRow, nCol, 2), kpts4, vecs4, 'kpts4: isotropic + redetect')
    show_kpts_(2, (2, 3, 1), kpts5, vecs5, 'kpts5: force_ori + redetect')
    show_kpts_(2, (2, 3, 2), kpts6, vecs6, 'kpts6: shift')
    show_kpts_(2, (2, 3, 3), kpts7, vecs7, 'kpts7: shift + reorient')
    show_kpts_(2, (2, 3, 4), kpts8, vecs8, 'kpts8: shift + reorient')
    show_kpts_(2, (2, 3, 5), kpts9, vecs9, 'kpts9: reorient')
    show_kpts_(2, (2, 3, 6), kpts10, vecs10, 'kpts10: reorient')
Ejemplo n.º 53
0
def plot_scores2(hs, qcx_list, fnum=1):
    print('[dev] plot_scores(fnum=%r)' % fnum)
    qcx2_res = get_qcx2_res(hs, qcx_list)
    all_score_list = []
    gtscore_ys = []
    gtscore_xs = []
    gtscore_ranks = []
    EXCLUDE_ZEROS = False
    N = 1
    # Append all scores to a giant list
    for res in qcx2_res.itervalues():
        cx2_score = res.cx2_score
        # Get gt scores first
        #gt_cxs = hs.get_other_indexed_cxs(res.qcx)
        gt_cxs = np.array(res.topN_cxs(hs, N=N, only_gt=True))
        gt_ys = cx2_score[gt_cxs]
        if EXCLUDE_ZEROS:
            nonzero_cxs = np.where(cx2_score != 0)[0]
            gt_cxs = gt_cxs[gt_ys != 0]
            gt_ranks = res.get_gt_ranks(gt_cxs)
            gt_cxs = np.array(utool.list_index(nonzero_cxs, gt_cxs))
            gt_ys  = gt_ys[gt_ys != 0]
            score_list = cx2_score[nonzero_cxs].tolist()
        else:
            score_list = cx2_score.tolist()
            gt_ranks = res.get_gt_ranks(gt_cxs)
        gtscore_ys.extend(gt_ys)
        gtscore_xs.extend(gt_cxs + len(all_score_list))
        gtscore_ranks.extend(gt_ranks)
        # Append all scores
        all_score_list.extend(score_list)
    all_score_list = np.array(all_score_list)
    gtscore_ranks = np.array(gtscore_ranks)
    gtscore_ys = np.array(gtscore_ys)

    # Sort all chipmatch scores
    allx_sorted = all_score_list.argsort()  # mapping from sortedallx to allx
    allscores_sorted = all_score_list[allx_sorted]
    # Change the groundtruth positions to correspond to sorted cmatch scores
    # Find position of gtscore_xs in allx_sorted
    gtscore_sortxs = utool.list_index(allx_sorted, gtscore_xs)
    gtscore_sortxs = np.array(gtscore_sortxs)
    # Draw and info
    rank_bounds = [
        (0, 1),
        (1, 5),
        (5, None)
    ]
    rank_colors = [
        df2.TRUE_GREEN,
        df2.UNKNOWN_PURP,
        df2.FALSE_RED
    ]
    print('[dev] matching chipscore stats: ' + utool.stats_str(all_score_list))
    df2.figure(fnum=fnum, doclf=True, docla=True)
    # Finds the knee
    df2.plot(allscores_sorted, color=df2.ORANGE, label='all scores')

    # get positions which are within rank bounds
    for count, ((low, high), rankX_color) in reversed(list(enumerate(zip(rank_bounds, rank_colors)))):
        rankX_flag_low = gtscore_ranks >= low
        if high is not None:
            rankX_flag_high = gtscore_ranks < high
            rankX_flag = np.logical_and(rankX_flag_low, rankX_flag_high)
        else:
            rankX_flag = rankX_flag_low
        rankX_allgtx = np.where(rankX_flag)[0]
        rankX_gtxs = gtscore_sortxs[rankX_allgtx]
        rankX_gtys = gtscore_ys[rankX_allgtx]
        rankX_label = '%d <= gt rank' % low
        if high is not None:
            rankX_label += ' < %d' % high
        if len(rankX_gtxs) > 0:
            df2.plot(rankX_gtxs, rankX_gtys, 'o', color=rankX_color, label=rankX_label)

    rowid = qcx2_res.itervalues().next().rowid

    df2.set_logyscale_from_data(allscores_sorted)

    df2.set_xlabel('chipmatch index')
    df2.dark_background()
    df2.set_figtitle('matching scores\n' + rowid)
    df2.legend(loc='upper left')
    #xmin = 0
    #xmax = utool.order_of_magnitude_ceil(len(allscores_sorted))
    #print('len_ = %r' % (len(allscores_sorted),))
    #print('xmin = %r' % (xmin,))
    #print('xmax = %r' % (xmax,))
    #df2.gca().set_xlim(xmin, xmax)
    df2.update()

    #utool.embed()
    # Second Plot
    #data = sorted(zip(gtscore_sortxs, gtscore_ys, gtscore_ranks))
    #gtxs = [x for (x, y, z) in data]
    #gtys = [y for (x, y, z) in data]
    #gtrs = [z for (x, y, z) in data]
    #nongtxs = np.setdiff1d(np.arange(gtxs[0], gtxs[-1]), gtxs)

    #min_ = min(gtxs)
    #max_ = len(allscores_sorted)
    #len_ = max_ - min_
    #normsum = 0
    #ratsum = 0
    #gtxs = np.array(gtxs)
    #nongtxs = np.array(nongtxs)
    #for ix in xrange(min_, max_):
        #nongtxs_ = nongtxs[nongtxs >= ix]
        #gtxs_ = gtxs[gtxs >= ix]
        #numer = allscores_sorted[gtxs_].sum()
        #denom = allscores_sorted[nongtxs_].sum()
        #ratio = (1 + numer) / (denom + 1)
        #total_support = (len(gtxs_) + len(nongtxs_))
        #normrat = ratio / total_support
        #ratsum += ratio
        #normsum += normrat
        #print(total_support)
    #print(ratsum / len_)
    #print(normsum / len_)
    #print(ratsum / allscores_sorted[min_:max_].sum())
    #print(normsum / allscores_sorted[min_:max_].sum())

    #index_gap = np.diff(gtxs)
    #score_gap = np.diff(gtys)
    #badness = (index_gap - 1) * score_gap
    #np.arange(len(gtxs))

    fnum += 1
    return fnum
Ejemplo n.º 54
0
def plot_clusters(data, datax2_clusterx, centroids, num_pca_dims=3,
                  whiten=False):
    """ Plots centroids and datapoints. Plots accurately up to 3 dimensions.
    If there are more than 3 dimensions, PCA is used to recude the dimenionality
    to the <num_pca_dims> principal components
    """
    # http://www.janeriksolem.net/2012/03/isomap-with-scikit-learn.html
    from plottool import draw_func2 as df2
    data_dims = data.shape[1]
    show_dims = min(num_pca_dims, data_dims)
    if data_dims != show_dims:
        # we can't physiologically see the data, so look at a projection
        print('[akmeans] Doing PCA')
        from sklearn import decomposition
        pcakw = dict(copy=True, n_components=show_dims, whiten=whiten)
        pca = decomposition.PCA(**pcakw).fit(data)
        pca_data = pca.transform(data)
        pca_clusters = pca.transform(centroids)
        print('[akmeans] ...Finished PCA')
    else:
        # pca is not necessary
        print('[akmeans] No need for PCA')
        pca_data = data
        pca_clusters = centroids
    K = len(centroids)
    print(pca_data.shape)
    # Make a color for each cluster
    colors = np.array(df2.distinct_colors(K, brightness=.95))
    data_x = pca_data[:, 0]
    data_y = pca_data[:, 1]
    data_colors = colors[np.array(datax2_clusterx, dtype=np.int32)]
    clus_x = pca_clusters[:, 0]
    clus_y = pca_clusters[:, 1]
    clus_colors = colors
    # Create a figure
    fig = df2.figure(1, doclf=True, docla=True)
    if show_dims == 2:
        ax = df2.plt.gca()
        df2.plt.scatter(data_x, data_y, s=20,  c=data_colors, marker='o', alpha=.2)
        df2.plt.scatter(clus_x, clus_y, s=500, c=clus_colors, marker='*')
        ax.autoscale(enable=False)
        ax.set_aspect('equal')
        df2.dark_background(ax)
    if show_dims == 3:
        from mpl_toolkits.mplot3d import Axes3D  # NOQA
        ax = fig.add_subplot(111, projection='3d')
        data_z = pca_data[:, 2]
        clus_z = pca_clusters[:, 2]
        ax.scatter(data_x, data_y, data_z, s=20,  c=data_colors, marker='o', alpha=.2)
        ax.scatter(clus_x, clus_y, clus_z, s=500, c=clus_colors, marker='*')
        ax.autoscale(enable=False)
        ax.set_aspect('equal')
        df2.dark_background(ax)
        #ax.set_alpha(.1)
        #ut.embed()
        #ax.set_frame_on(False)
    ax = df2.plt.gca()
    waswhitestr = ' +whitening' * whiten
    titlestr = ('AKmeans: K={K}.'
                'PCA projection {data_dims}D -> {show_dims}D'
                '{waswhitestr}').format(**locals())
    ax.set_title(titlestr)
    return fig