rectangletool

RectangleTool

class skimage.viewer.canvastools.RectangleTool(manager, on_move=None, on_release=None, on_enter=None, maxdist=10, rect_props=None) [source]

Bases: skimage.viewer.canvastools.base.CanvasToolBase, matplotlib.widgets.RectangleSelector

Widget for selecting a rectangular region in a plot.

After making the desired selection, press “Enter” to accept the selection and call the on_enter callback function.

Parameters:

manager : Viewer or PlotPlugin.

Skimage viewer or plot plugin object.

on_move : function

Function called whenever a control handle is moved. This function must accept the rectangle extents as the only argument.

on_release : function

Function called whenever the control handle is released.

on_enter : function

Function called whenever the “enter” key is pressed.

maxdist : float

Maximum pixel distance allowed when selecting control handle.

rect_props : dict

Properties for matplotlib.patches.Rectangle. This class redefines defaults in matplotlib.widgets.RectangleSelector.

Examples

>>> from skimage import data
>>> from skimage.viewer import ImageViewer
>>> from skimage.viewer.canvastools import RectangleTool
>>> from skimage.draw import line
>>> from skimage.draw import set_color
>>> viewer = ImageViewer(data.coffee())  
>>> def print_the_rect(extents):
...     global viewer
...     im = viewer.image
...     coord = np.int64(extents)
...     [rr1, cc1] = line(coord[2],coord[0],coord[2],coord[1])
...     [rr2, cc2] = line(coord[2],coord[1],coord[3],coord[1])
...     [rr3, cc3] = line(coord[3],coord[1],coord[3],coord[0])
...     [rr4, cc4] = line(coord[3],coord[0],coord[2],coord[0])
...     set_color(im, (rr1, cc1), [255, 255, 0])
...     set_color(im, (rr2, cc2), [0, 255, 255])
...     set_color(im, (rr3, cc3), [255, 0, 255])
...     set_color(im, (rr4, cc4), [0, 0, 0])
...     viewer.image=im
>>> rect_tool = RectangleTool(viewer, on_enter=print_the_rect) 
>>> viewer.show() 

Attributes

extents Return (xmin, xmax, ymin, ymax).
__init__(manager, on_move=None, on_release=None, on_enter=None, maxdist=10, rect_props=None) [source]
corners

Corners of rectangle from lower left, moving clockwise.

edge_centers

Midpoint of rectangle edges from left, moving clockwise.

extents

Return (xmin, xmax, ymin, ymax).

geometry
on_mouse_press(event) [source]
on_mouse_release(event) [source]
on_move(event) [source]
doc_scikit_image
2017-01-12 17:23:04
Comments
Leave a Comment

Please login to continue.