Example #1
0
def _annotate_roi(hs, ax, cx, sel_cxs, draw_lbls, annote):
    # Draw an roi around a chip in the image
    roi, theta = hs.cx2_roi(cx), hs.cx2_theta(cx)
    if annote:
        is_sel = cx in sel_cxs
        label = hs.cx2_name(cx)
        label = hs.cidstr(cx) if label == '____' else label
        label = label if draw_lbls else None
        lbl_alpha = .75 if is_sel else .6
        bbox_alpha = .95 if is_sel else .6
        lbl_color = df2.BLACK * lbl_alpha
        bbox_color = (df2.ORANGE if is_sel else df2.DARK_ORANGE) * bbox_alpha
        df2.draw_roi(roi, label, bbox_color, lbl_color, theta=theta, ax=ax)
    # Index the roi centers (for interaction)
    (x, y, w, h) = roi
    xy_center = np.array([x + (w / 2), y + (h / 2)])
    return xy_center
Example #2
0
def _annotate_roi(hs, ax, cx, sel_cxs, draw_lbls, annote):
    # Draw an roi around a chip in the image
    roi, theta = hs.cx2_roi(cx), hs.cx2_theta(cx)
    if annote:
        is_sel =  cx in sel_cxs
        label = hs.cx2_name(cx)
        label = hs.cidstr(cx) if label == '____' else label
        label = label if draw_lbls else None
        lbl_alpha  = .75 if is_sel else .6
        bbox_alpha = .95 if is_sel else .6
        lbl_color  = df2.BLACK * lbl_alpha
        bbox_color = (df2.ORANGE if is_sel else df2.DARK_ORANGE) * bbox_alpha
        df2.draw_roi(roi, label, bbox_color, lbl_color, theta=theta, ax=ax)
    # Index the roi centers (for interaction)
    (x, y, w, h) = roi
    xy_center = np.array([x + (w / 2), y + (h / 2)])
    return xy_center
Example #3
0
def annotate_chipres(hs,
                     res,
                     cx,
                     showTF=True,
                     showScore=True,
                     title_pref='',
                     title_suff='',
                     show_2nd_gname=True,
                     show_2nd_name=True,
                     show_1st=True,
                     time_appart=True,
                     in_image=False,
                     offset1=(0, 0),
                     offset2=(0, 0),
                     show_query=True,
                     xywh2=None,
                     **kwargs):

    printDBG('[viz] annotate_chipres()')
    #print('Did not expect args: %r' % (kwargs.keys(),))
    qcx = res.qcx
    score = res.cx2_score[cx]
    matched_kpts = np.float32(len(res.cx2_fs[cx]))
    #    print('matched_kpts= %r'%str(matched_kpts))
    # TODO Use this function when you clean show_chipres
    (truestr, falsestr, nonamestr) = ('TRUE', 'FALSE', '???')
    is_true, is_unknown = hs.is_true_match(qcx, cx)
    isgt_str = nonamestr if is_unknown else (truestr if is_true else falsestr)
    match_color = {
        nonamestr: df2.UNKNOWN_PURP,
        truestr: df2.TRUE_GREEN,
        falsestr: df2.FALSE_RED
    }[isgt_str]
    # Build title
    title = '*%s*' % isgt_str if showTF else ''
    if showScore:
        score_str = (' score=' + helpers.num_fmt(score)) % (score)
        score_str += ('   matched_kpts=' +
                      helpers.num_fmt(matched_kpts)) % (matched_kpts)
        title += score_str
    title = title_pref + str(title) + title_suff
    # Build xlabel
    xlabel_ = []

    if 'show_1st':
        xlabel_.append('top_gname=%r' % hs.cx2_gname(qcx))
        xlabel_.append('top_name=%r' % hs.cx2_name(qcx))

    if 'show_2nd_gname':
        xlabel_.append('\n below_gname=%r' % hs.cx2_gname(cx))
    if 'show_2nd_name':
        xlabel_.append('below_name=%r' % hs.cx2_name(cx))

    if 'time_appart':
        xlabel_.append('\n' + hs.get_timedelta_str(qcx, cx))
    xlabel = ', '.join(xlabel_)
    ax = df2.gca()
    ax._hs_viewtype = 'chipres'
    ax._hs_qcx = qcx
    ax._hs_cx = cx
    if NO_LABEL_OVERRIDE:
        title = ''
        xlabel = ''
    df2.set_title(title, ax)
    df2.set_xlabel(xlabel, ax)
    if in_image:
        roi1 = hs.cx2_roi(qcx) + np.array(list(offset1) + [0, 0])
        roi2 = hs.cx2_roi(cx) + np.array(list(offset2) + [0, 0])
        theta1 = hs.cx2_theta(qcx)
        theta2 = hs.cx2_theta(cx)
        # HACK!
        lbl1 = 'q' + hs.cidstr(qcx)
        lbl2 = hs.cidstr(cx)
        if show_query:
            df2.draw_roi(roi1, bbox_color=df2.ORANGE, label=lbl1, theta=theta1)
        df2.draw_roi(roi2, bbox_color=match_color, label=lbl2, theta=theta2)
        # No matches draw a red box
        if len(res.cx2_fm[cx]) == 0:
            df2.draw_boxedX(roi2, theta=theta2)
    else:
        if xywh2 is None:
            xy, w, h = df2._axis_xy_width_height(ax)
            xywh2 = (xy[0], xy[1], w, h)
        df2.draw_border(ax, match_color, 4, offset=offset2)
        # No matches draw a red box
        if len(res.cx2_fm[cx]) == 0:
            df2.draw_boxedX(xywh2)
Example #4
0
def annotate_chipres(hs, res, cx, showTF=True, showScore=True, title_pref='',
                     title_suff='', show_gname=False, show_name=True,
                     time_appart=True, in_image=False, offset1=(0, 0),
                     offset2=(0, 0), show_query=True, xywh2=None, **kwargs):
    printDBG('[viz] annotate_chipres()')
    #print('Did not expect args: %r' % (kwargs.keys(),))
    qcx = res.qcx
    score = res.cx2_score[cx]
    # TODO Use this function when you clean show_chipres
    (truestr, falsestr, nonamestr) = ('TRUE', 'FALSE', '???')
    is_true, is_unknown = hs.is_true_match(qcx, cx)
    isgt_str = nonamestr if is_unknown else (truestr if is_true else falsestr)
    match_color = {nonamestr: df2.UNKNOWN_PURP,
                   truestr:   df2.TRUE_GREEN,
                   falsestr:  df2.FALSE_RED}[isgt_str]
    # Build title
    title = '*%s*' % isgt_str if showTF else ''
    if showScore:
        score_str = (' score=' + helpers.num_fmt(score)) % (score)
        title += score_str
    title = title_pref + str(title) + title_suff
    # Build xlabel
    xlabel_ = []
    if 'show_gname':
        xlabel_.append('gname=%r' % hs.cx2_gname(cx))
    if 'show_name':
        xlabel_.append('name=%r' % hs.cx2_name(cx))
    if 'time_appart':
        xlabel_.append('\n' + hs.get_timedelta_str(qcx, cx))
    xlabel = ', '.join(xlabel_)
    ax = df2.gca()
    ax._hs_viewtype = 'chipres'
    ax._hs_qcx = qcx
    ax._hs_cx = cx
    if NO_LABEL_OVERRIDE:
        title = ''
        xlabel = ''
    df2.set_title(title, ax)
    df2.set_xlabel(xlabel, ax)
    if in_image:
        roi1 = hs.cx2_roi(qcx) + np.array(list(offset1) + [0, 0])
        roi2 = hs.cx2_roi(cx) + np.array(list(offset2) + [0, 0])
        theta1 = hs.cx2_theta(qcx)
        theta2 = hs.cx2_theta(cx)
        # HACK!
        lbl1 = 'q' + hs.cidstr(qcx)
        lbl2 = hs.cidstr(cx)
        if show_query:
            df2.draw_roi(roi1, bbox_color=df2.ORANGE, label=lbl1, theta=theta1)
        df2.draw_roi(roi2, bbox_color=match_color, label=lbl2, theta=theta2)
        # No matches draw a red box
        if len(res.cx2_fm[cx]) == 0:
            df2.draw_boxedX(roi2, theta=theta2)
    else:
        if xywh2 is None:
            xy, w, h = df2._axis_xy_width_height(ax)
            xywh2 = (xy[0], xy[1], w, h)
        df2.draw_border(ax, match_color, 4, offset=offset2)
        # No matches draw a red box
        if len(res.cx2_fm[cx]) == 0:
            df2.draw_boxedX(xywh2)