コード例 #1
0
def show_power_law_plots():
    """

    CommandLine:
        python -m ibeis.algo.hots.devcases --test-show_power_law_plots --show

    Example:
        >>> # DISABLE_DOCTEST
        >>> #%pylab qt4
        >>> from ibeis.all_imports import *  # NOQA
        >>> from ibeis.algo.hots.devcases import *  # NOQA
        >>> show_power_law_plots()
        >>> pt.show_if_requested()
    """
    import numpy as np
    import plottool as pt
    xdata = np.linspace(0, 1, 1000)
    ydata = xdata
    fnum = 1
    powers = [.01, .1, .5, 1, 2, 30, 70, 100, 1000]
    nRows, nCols = pt.get_square_row_cols(len(powers), fix=True)
    pnum_next = pt.make_pnum_nextgen(nRows, nCols)
    for p in powers:
        plotkw = dict(fnum=fnum,
                      marker='g-',
                      linewidth=2,
                      pnum=pnum_next(),
                      title='p=%r' % (p, ))
        ydata_ = ydata**p
        pt.plot2(xdata, ydata_, **plotkw)
    pt.set_figtitle('power laws y = x ** p')
コード例 #2
0
ファイル: scoring.py プロジェクト: Erotemic/ibeis
def show_single_coverage_mask(qreq_, cm, weight_mask_m, weight_mask, daids, fnum=None):
    import plottool as pt
    from ibeis import viz
    fnum = pt.ensure_fnum(fnum)
    idx_list = ut.dict_take(cm.daid2_idx, daids)
    nPlots = len(idx_list) + 1
    nRows, nCols = pt.get_square_row_cols(nPlots)
    pnum_ = pt.make_pnum_nextgen(nRows, nCols)
    pt.figure(fnum=fnum, pnum=(1, 2, 1))
    # Draw coverage masks with bbox
    # <FlipHack>
    #weight_mask_m = np.fliplr(np.flipud(weight_mask_m))
    #weight_mask = np.fliplr(np.flipud(weight_mask))
    # </FlipHack>
    stacked_weights, offset_tup, sf_tup = vt.stack_images(weight_mask_m, weight_mask, return_sf=True)
    (woff, hoff) = offset_tup[1]
    wh1 = weight_mask_m.shape[0:2][::-1]
    wh2 = weight_mask.shape[0:2][::-1]
    pt.imshow(255 * (stacked_weights), fnum=fnum, pnum=pnum_(0), title='(query image) What did match vs what should match')
    pt.draw_bbox((   0,    0) + wh1, bbox_color=(0, 0, 1))
    pt.draw_bbox((woff, hoff) + wh2, bbox_color=(0, 0, 1))
    # Get contributing matches
    qaid = cm.qaid
    daid_list = daids
    fm_list = ut.take(cm.fm_list, idx_list)
    fs_list = ut.take(cm.fs_list, idx_list)
    # Draw matches
    for px, (daid, fm, fs) in enumerate(zip(daid_list, fm_list, fs_list), start=1):
        viz.viz_matches.show_matches2(qreq_.ibs, qaid, daid, fm, fs,
                                      draw_pts=False, draw_lines=True,
                                      draw_ell=False, fnum=fnum, pnum=pnum_(px),
                                      darken=.5)
    coverage_score = score_matching_mask(weight_mask_m, weight_mask)
    pt.set_figtitle('score=%.4f' % (coverage_score,))
コード例 #3
0
ファイル: devcases.py プロジェクト: Erotemic/ibeis
def show_power_law_plots():
    """

    CommandLine:
        python -m ibeis.algo.hots.devcases --test-show_power_law_plots --show

    Example:
        >>> # DISABLE_DOCTEST
        >>> #%pylab qt4
        >>> from ibeis.all_imports import *  # NOQA
        >>> from ibeis.algo.hots.devcases import *  # NOQA
        >>> show_power_law_plots()
        >>> pt.show_if_requested()
    """
    import numpy as np
    import plottool as pt
    xdata = np.linspace(0, 1, 1000)
    ydata = xdata
    fnum = 1
    powers = [.01, .1, .5, 1, 2, 30, 70, 100, 1000]
    nRows, nCols = pt.get_square_row_cols(len(powers), fix=True)
    pnum_next = pt.make_pnum_nextgen(nRows, nCols)
    for p in powers:
        plotkw = dict(
            fnum=fnum,
            marker='g-',
            linewidth=2,
            pnum=pnum_next(),
            title='p=%r' % (p,)
        )
        ydata_ = ydata ** p
        pt.plot2(xdata, ydata_, **plotkw)
    pt.set_figtitle('power laws y = x ** p')
コード例 #4
0
ファイル: scoring.py プロジェクト: whaozl/ibeis
def show_single_coverage_mask(qreq_,
                              cm,
                              weight_mask_m,
                              weight_mask,
                              daids,
                              fnum=None):
    import plottool as pt
    from ibeis import viz
    fnum = pt.ensure_fnum(fnum)
    idx_list = ut.dict_take(cm.daid2_idx, daids)
    nPlots = len(idx_list) + 1
    nRows, nCols = pt.get_square_row_cols(nPlots)
    pnum_ = pt.make_pnum_nextgen(nRows, nCols)
    pt.figure(fnum=fnum, pnum=(1, 2, 1))
    # Draw coverage masks with bbox
    # <FlipHack>
    #weight_mask_m = np.fliplr(np.flipud(weight_mask_m))
    #weight_mask = np.fliplr(np.flipud(weight_mask))
    # </FlipHack>
    stacked_weights, offset_tup, sf_tup = vt.stack_images(weight_mask_m,
                                                          weight_mask,
                                                          return_sf=True)
    (woff, hoff) = offset_tup[1]
    wh1 = weight_mask_m.shape[0:2][::-1]
    wh2 = weight_mask.shape[0:2][::-1]
    pt.imshow(255 * (stacked_weights),
              fnum=fnum,
              pnum=pnum_(0),
              title='(query image) What did match vs what should match')
    pt.draw_bbox((0, 0) + wh1, bbox_color=(0, 0, 1))
    pt.draw_bbox((woff, hoff) + wh2, bbox_color=(0, 0, 1))
    # Get contributing matches
    qaid = cm.qaid
    daid_list = daids
    fm_list = ut.take(cm.fm_list, idx_list)
    fs_list = ut.take(cm.fs_list, idx_list)
    # Draw matches
    for px, (daid, fm, fs) in enumerate(zip(daid_list, fm_list, fs_list),
                                        start=1):
        viz.viz_matches.show_matches2(qreq_.ibs,
                                      qaid,
                                      daid,
                                      fm,
                                      fs,
                                      draw_pts=False,
                                      draw_lines=True,
                                      draw_ell=False,
                                      fnum=fnum,
                                      pnum=pnum_(px),
                                      darken=.5)
    coverage_score = score_matching_mask(weight_mask_m, weight_mask)
    pt.set_figtitle('score=%.4f' % (coverage_score, ))
コード例 #5
0
def show_augmented_patches(Xb, Xb_, yb, yb_, data_per_label=1, shadows=None):
    """
    from ibeis_cnn.augment import *  # NOQA
    std_ = center_std
    mean_ = center_mean
    """
    import plottool as pt
    import vtool as vt
    Xb_old = vt.rectify_to_float01(Xb)
    Xb_new = vt.rectify_to_float01(Xb_)

    # only look at ones that were actually augmented
    sample1 = Xb_old[0::data_per_label]
    sample2 = Xb_new[0::data_per_label]
    diff = np.abs((sample1 - sample2))
    diff_batches = diff.sum(-1).sum(-1).sum(-1) > 0
    modified_indexes = np.where(diff_batches > 0)[0]
    print('modified_indexes = %r' % (modified_indexes,))
    #modified_indexes = np.arange(num_examples)

    Xb_old = vt.rectify_to_uint8(Xb_old)
    Xb_new = vt.rectify_to_uint8(Xb_new)

    # Group data into n-tuples
    grouped_idxs = [np.arange(n, len(Xb_), data_per_label)
                    for n in range(data_per_label)]
    data_lists_old = vt.apply_grouping(Xb_old, grouped_idxs, axis=0)
    data_lists_new = vt.apply_grouping(Xb_new, grouped_idxs, axis=0)

    import six
    #chunck_sizes = (4, 10)
    import utool
    with utool.embed_on_exception_context:
        chunk_sizes = pt.get_square_row_cols(len(modified_indexes), max_cols=10,
                                             fix=False, inclusive=False)
        _iter = ut.iter_multichunks(modified_indexes, chunk_sizes)
        multiindices = six.next(_iter)

        from ibeis_cnn import draw_results
        tup = draw_results.get_patch_multichunks(data_lists_old, yb, {},
                                                 multiindices)
        orig_stack = tup[0]
        #stacked_img, stacked_offsets, stacked_sfs = tup

        tup = draw_results.get_patch_multichunks(data_lists_new, yb_, {},
                                                 multiindices)
        warp_stack = tup[0]
    #stacked_img, stacked_offsets, stacked_sfs = tup

    #orig_stack = stacked_img_pairs(Xb_old, modified_indexes, yb)
    #warp_stack = stacked_img_pairs(Xb_new, modified_indexes, yb_)
    if shadows is not None:
        # hack
        shadow_stack = stacked_img_pairs(shadows, modified_indexes, yb_)

    fnum = None
    fnum = pt.ensure_fnum(fnum)
    pt.figure(fnum)
    #next_pnum = pt.make_pnum_nextgen(nRows=2 + (shadows is not None), nCols=1)
    next_pnum = pt.make_pnum_nextgen(nCols=2 + (shadows is not None), nRows=1)
    pt.imshow(orig_stack, pnum=next_pnum(), title='before')
    pt.imshow(warp_stack, pnum=next_pnum(), title='after')

    if shadows is not None:
        pt.imshow(shadow_stack, pnum=next_pnum(), title='shadow_stack')
コード例 #6
0
def test_rot_invar():
    r"""
    CommandLine:
        python -m pyhesaff test_rot_invar --show --rebuild-hesaff --no-rmbuild
        python -m pyhesaff test_rot_invar --show --nocpp

        python -m vtool.tests.dummy testdata_ratio_matches --show --ratio_thresh=1.0 --rotation_invariance --rebuild-hesaff
        python -m vtool.tests.dummy testdata_ratio_matches --show --ratio_thresh=1.1 --rotation_invariance --rebuild-hesaff

    Example:
        >>> # DISABLE_DODCTEST
        >>> from pyhesaff._pyhesaff import *  # NOQA
        >>> test_rot_invar()
    """
    import cv2
    import vtool as vt
    import plottool as pt
    TAU = 2 * np.pi
    fnum = pt.next_fnum()
    NUM_PTS = 5  # 9
    theta_list = np.linspace(0, TAU, NUM_PTS, endpoint=False)
    nRows, nCols = pt.get_square_row_cols(len(theta_list), fix=True)
    next_pnum = pt.make_pnum_nextgen(nRows, nCols)
    # Expand the border a bit around star.png
    pad_ = 100
    img_fpath = grab_test_imgpath('star.png')
    img_fpath2 = vt.pad_image_ondisk(img_fpath, pad_, value=26)
    for theta in theta_list:
        print('-----------------')
        print('theta = %r' % (theta, ))
        img_fpath = vt.rotate_image_ondisk(img_fpath2,
                                           theta,
                                           border_mode=cv2.BORDER_REPLICATE)
        if not ub.argflag('--nocpp'):
            (kpts_list_ri, vecs_list2) = detect_feats(img_fpath,
                                                      rotation_invariance=True)
            kpts_ri = kpts_list_ri[0:2]
        (kpts_list_gv, vecs_list1) = detect_feats(img_fpath,
                                                  rotation_invariance=False)
        kpts_gv = kpts_list_gv[0:2]
        # find_kpts_direction
        imgBGR = vt.imread(img_fpath)
        kpts_ripy = vt.find_kpts_direction(imgBGR,
                                           kpts_gv,
                                           DEBUG_ROTINVAR=False)
        # Verify results stdout
        #print('nkpts = %r' % (len(kpts_gv)))
        #print(vt.kpts_repr(kpts_gv))
        #print(vt.kpts_repr(kpts_ri))
        #print(vt.kpts_repr(kpts_ripy))
        # Verify results plot
        pt.figure(fnum=fnum, pnum=next_pnum())
        pt.imshow(imgBGR)
        #if len(kpts_gv) > 0:
        #    pt.draw_kpts2(kpts_gv, ori=True, ell_color=pt.BLUE, ell_linewidth=10.5)
        ell = False
        rect = True
        if not ub.argflag('--nocpp'):
            if len(kpts_ri) > 0:
                pt.draw_kpts2(kpts_ri,
                              rect=rect,
                              ell=ell,
                              ori=True,
                              ell_color=pt.RED,
                              ell_linewidth=5.5)
        if len(kpts_ripy) > 0:
            pt.draw_kpts2(kpts_ripy,
                          rect=rect,
                          ell=ell,
                          ori=True,
                          ell_color=pt.GREEN,
                          ell_linewidth=3.5)
    pt.set_figtitle('green=python, red=C++')
    pt.show_if_requested()
コード例 #7
0
ファイル: _pyhesaff.py プロジェクト: Erotemic/hesaff
def test_rot_invar():
    r"""
    CommandLine:
        python -m pyhesaff test_rot_invar --show --rebuild-hesaff --no-rmbuild
        python -m pyhesaff test_rot_invar --show --nocpp

        python -m vtool.tests.dummy testdata_ratio_matches --show --ratio_thresh=1.0 --rotation_invariance --rebuild-hesaff
        python -m vtool.tests.dummy testdata_ratio_matches --show --ratio_thresh=1.1 --rotation_invariance --rebuild-hesaff

    Example:
        >>> # DISABLE_DODCTEST
        >>> from pyhesaff._pyhesaff import *  # NOQA
        >>> test_rot_invar()
    """
    import cv2
    import utool as ut
    import vtool as vt
    import plottool as pt
    TAU = 2 * np.pi
    fnum = pt.next_fnum()
    NUM_PTS = 5  # 9
    theta_list = np.linspace(0, TAU, NUM_PTS, endpoint=False)
    nRows, nCols = pt.get_square_row_cols(len(theta_list), fix=True)
    next_pnum = pt.make_pnum_nextgen(nRows, nCols)
    # Expand the border a bit around star.png
    pad_ = 100
    img_fpath = ut.grab_test_imgpath('star.png')
    img_fpath2 = vt.pad_image_ondisk(img_fpath, pad_, value=26)
    for theta in theta_list:
        print('-----------------')
        print('theta = %r' % (theta,))
        #theta = ut.get_argval('--theta', type_=float, default=TAU * 3 / 8)
        img_fpath = vt.rotate_image_ondisk(img_fpath2, theta, borderMode=cv2.BORDER_REPLICATE)
        if not ut.get_argflag('--nocpp'):
            (kpts_list_ri, vecs_list2) = detect_feats(img_fpath, rotation_invariance=True)
            kpts_ri = ut.strided_sample(kpts_list_ri, 2)
        (kpts_list_gv, vecs_list1) = detect_feats(img_fpath, rotation_invariance=False)
        kpts_gv = ut.strided_sample(kpts_list_gv, 2)
        # find_kpts_direction
        imgBGR = vt.imread(img_fpath)
        kpts_ripy = vt.find_kpts_direction(imgBGR, kpts_gv, DEBUG_ROTINVAR=False)
        # Verify results stdout
        #print('nkpts = %r' % (len(kpts_gv)))
        #print(vt.kpts_repr(kpts_gv))
        #print(vt.kpts_repr(kpts_ri))
        #print(vt.kpts_repr(kpts_ripy))
        # Verify results plot
        pt.figure(fnum=fnum, pnum=next_pnum())
        pt.imshow(imgBGR)
        #if len(kpts_gv) > 0:
        #    pt.draw_kpts2(kpts_gv, ori=True, ell_color=pt.BLUE, ell_linewidth=10.5)
        ell = False
        rect = True
        if not ut.get_argflag('--nocpp'):
            if len(kpts_ri) > 0:
                pt.draw_kpts2(kpts_ri, rect=rect, ell=ell, ori=True,
                              ell_color=pt.RED, ell_linewidth=5.5)
        if len(kpts_ripy) > 0:
            pt.draw_kpts2(kpts_ripy, rect=rect, ell=ell,  ori=True,
                          ell_color=pt.GREEN, ell_linewidth=3.5)
        #print('\n'.join(vt.get_ori_strs(np.vstack([kpts_gv, kpts_ri, kpts_ripy]))))
        #ut.embed(exec_lines=['pt.update()'])
    pt.set_figtitle('green=python, red=C++')
    pt.show_if_requested()