Esempio n. 1
0
def select_roi():
    #from matplotlib.backend_bases import mplDeprecation
    print('[*guitools] Define a Rectanglular ROI by clicking two points.')
    try:
        sys.stdout.flush()
        fig = df2.gcf()
        # Disconnect any other button_press events
        oldcbid, oldcbfn = df2.disconnect_callback(fig, 'button_press_event')
        #with warnings.catch_warnings():
            #warnings.filterwarnings("ignore", category=mplDeprecation)
        pts = fig.ginput(2)
        print('[*guitools] ginput(2) = %r' % (pts,))
        [(x1, y1), (x2, y2)] = pts
        xm = min(x1, x2)
        xM = max(x1, x2)
        ym = min(y1, y2)
        yM = max(y1, y2)
        xywh = map(int, map(round, (xm, ym, xM - xm, yM - ym)))
        roi = np.array(xywh, dtype=np.int32)
        # Reconnect the old button press events
        df2.connect_callback(fig, 'button_press_event', oldcbfn)
        print('[*guitools] roi = %r ' % (roi,))
        return roi
    except Exception as ex:
        print('[*guitools] ROI selection Failed:\n%r' % (ex,))
        return None
Esempio n. 2
0
def select_orientation():
    #from matplotlib.backend_bases import mplDeprecation
    print('[*guitools] Define an orientation angle by clicking two points')
    try:
        # Compute an angle from user interaction
        sys.stdout.flush()
        fig = df2.gcf()
        oldcbid, oldcbfn = df2.disconnect_callback(fig, 'button_press_event')
        #with warnings.catch_warnings():
            #warnings.filterwarnings("ignore", category=mplDeprecation)
        pts = np.array(fig.ginput(2))
        #print('[*guitools] ginput(2) = %r' % pts)
        # Get reference point to origin
        refpt = pts[1] - pts[0]
        #theta = np.math.atan2(refpt[1], refpt[0])
        theta = np.math.atan2(refpt[1], refpt[0])
        print('The angle in radians is: %r' % theta)
        df2.connect_callback(fig, 'button_press_event', oldcbfn)
        return theta
    except Exception as ex:
        print('Annotate Orientation Failed %r' % ex)
        return None
Esempio n. 3
0
def draw_images_at_positions(img_list, pos_list):
    print('[encounter] drawing %d images' % len(img_list))
    # Thumb stack
    ax  = df2.gca()
    fig = df2.gcf()
    trans = ax.transData.transform
    trans2 = fig.transFigure.inverted().transform
    mark_progress, end_progress = util.progress_func(len(pos_list), lbl='drawing img')
    for ix, ((x, y), img) in enumerate(izip(pos_list, img_list)):
        mark_progress(ix)
        xx, yy = trans((x, y))  # figure coordinates
        xa, ya = trans2((xx, yy))  # axes coordinates
        #
        width, height = img.shape[0:2]
        tlx = xa - (width / 2.0)
        tly = ya - (height / 2.0)
        img_bbox = [tlx, tly, width, height]
        # Make new axis for the image
        img_ax = df2.plt.axes(img_bbox)
        img_ax.imshow(img)
        img_ax.set_aspect('equal')
        img_ax.axis('off')
    end_progress()