def run(self): """ runs the kymograph aligner """ # show the images self.fig = plt.figure() self.ax = plt.gca() plt.subplots_adjust(bottom=0.2) # prepare image to work with image = self.kymograph._make_image(self.kymograph.offsets) height, width = image.shape window = self.window_margin self.data = np.empty((height, width + 2*window), np.double) + np.nan self.data[:, window:width + window] = image self.image = self.ax.imshow(self.data, interpolation='none', aspect='auto', cmap=plt.get_cmap('gray')) self.ax.set_title(self.title) # internal data self.active = True self.result = 'cancel' self._ax_points = None # create the widget for selecting the range useblit = graphics.backend_supports_blitting() self.selector = \ widgets.RectangleSelector(self.ax, self.select_callback, drawtype='box', useblit=useblit, button=[1]) # only use the left button # the rectangle marking the selected area self.selected = slice(0, 0) self.selected_marker = patches.Rectangle((0, -5), self.data.shape[1], 0, color='y', alpha=0.5) self.ax.add_patch(self.selected_marker) # add buttons ax_align = plt.axes([0.5, 0.05, 0.1, 0.075]) bn_align = widgets.Button(ax_align, 'Align All') bn_align.on_clicked(self.clicked_align) ax_ok = plt.axes([0.7, 0.05, 0.1, 0.075]) bn_ok = widgets.Button(ax_ok, 'Save') bn_ok.on_clicked(self.clicked_ok) ax_cancel = plt.axes([0.81, 0.05, 0.1, 0.075]) bp_cancel = widgets.Button(ax_cancel, 'Cancel') bp_cancel.on_clicked(self.clicked_cancel) # initialize the interaction with the image self.fig.canvas.mpl_connect('key_release_event', self.key_callback) # process result plt.show() return self.result
def measure_lines(self): """ shows an interface for measuring lines """ # create the widget for selecting the range useblit = graphics.backend_supports_blitting() self.selector = \ widgets.RectangleSelector(self.ax, self.select_callback, drawtype='line', lineprops=self.lineprops, useblit=useblit, button=[1]) self.line = self.ax.plot([-1, -1], [-1, -1], **self.lineprops)[0] plt.show()
def __init__(self, ax=None): if ax is None: self.ax = plt.gca() else: self.ax = ax self.width = self.ax.get_xlim()[1] self.height = self.ax.get_ylim()[1] # create the widget for selecting the range useblit = graphics.backend_supports_blitting() self.selector = \ widgets.RectangleSelector(self.ax, self.select_callback, drawtype='box', useblit=useblit, button=[1]) # left button # the rectangle marking the selected area self.selected = None self.selected_marker = patches.Rectangle((0, -5), 0, 0, color='y', alpha=0.5) self.ax.add_patch(self.selected_marker)
def run(self): """ runs the segment picker """ # show the images self.fig, self.axes = plt.subplots(nrows=1, ncols=2, sharex=True, sharey=True, squeeze=True) plt.subplots_adjust(bottom=0.2) ax_img, ax_feat = self.axes imshow_args = {'interpolation': 'none', 'aspect': 1, 'cmap': plt.get_cmap('gray')} ax_img.imshow(self._frame, **imshow_args) ax_img.set_title('First _frame of video') ax_img.set_autoscale_on(False) ax_feat.imshow(self.features, **imshow_args) ax_feat.set_title('Automatic feature extraction') ax_feat.set_autoscale_on(False) # internal data self.active = True self.result = 'cancel' self.bounds = self._frame.shape self._ax_segments = [[] for _ in xrange(len(self.axes))] # initialize data if self.segments: segments = self.segments self.segments = [] for segment in segments: self._add_segment(segment) # drawtype is 'box' or 'line' or 'none' useblit = graphics.backend_supports_blitting() self.selectors = [ widgets.RectangleSelector(ax, self.select_callback, drawtype='line', lineprops=self.lineprops, useblit=useblit, button=[1], # don't use middle button minspanx=5, minspany=5, spancoords='pixels') for ax in (ax_img, ax_feat)] # add buttons ax_active = plt.axes([0.5, 0.05, 0.1, 0.075]) check = widgets.CheckButtons(ax_active, ['active'], [self.active]) check.on_clicked(self.clicked_check) ax_ok = plt.axes([0.7, 0.05, 0.1, 0.075]) bn_ok = widgets.Button(ax_ok, 'Ok') bn_ok.on_clicked(self.clicked_ok) ax_cancel = plt.axes([0.81, 0.05, 0.1, 0.075]) bp_cancel = widgets.Button(ax_cancel, 'Cancel') bp_cancel.on_clicked(self.clicked_cancel) self.msg() # initialize the interaction with the image self.fig.canvas.mpl_connect('button_press_event', self.click_image) # process result plt.show() return self.result
def run(self): """ runs the segment picker """ # show the images self.fig, self.axes = plt.subplots(nrows=1, ncols=2, sharex=True, sharey=True, squeeze=True) plt.subplots_adjust(bottom=0.2) ax_img, ax_feat = self.axes imshow_args = { 'interpolation': 'none', 'aspect': 1, 'cmap': plt.get_cmap('gray') } ax_img.imshow(self._frame, **imshow_args) ax_img.set_title('First _frame of video') ax_img.set_autoscale_on(False) ax_feat.imshow(self.features, **imshow_args) ax_feat.set_title('Automatic feature extraction') ax_feat.set_autoscale_on(False) # internal data self.active = True self.result = 'cancel' self.bounds = self._frame.shape self._ax_segments = [[] for _ in xrange(len(self.axes))] # initialize data if self.segments: segments = self.segments self.segments = [] for segment in segments: self._add_segment(segment) # drawtype is 'box' or 'line' or 'none' useblit = graphics.backend_supports_blitting() self.selectors = [ widgets.RectangleSelector( ax, self.select_callback, drawtype='line', lineprops=self.lineprops, useblit=useblit, button=[1], # don't use middle button minspanx=5, minspany=5, spancoords='pixels') for ax in (ax_img, ax_feat) ] # add buttons ax_active = plt.axes([0.5, 0.05, 0.1, 0.075]) check = widgets.CheckButtons(ax_active, ['active'], [self.active]) check.on_clicked(self.clicked_check) ax_ok = plt.axes([0.7, 0.05, 0.1, 0.075]) bn_ok = widgets.Button(ax_ok, 'Ok') bn_ok.on_clicked(self.clicked_ok) ax_cancel = plt.axes([0.81, 0.05, 0.1, 0.075]) bp_cancel = widgets.Button(ax_cancel, 'Cancel') bp_cancel.on_clicked(self.clicked_cancel) self.msg() # initialize the interaction with the image self.fig.canvas.mpl_connect('button_press_event', self.click_image) # process result plt.show() return self.result