W3cubDocs

/scikit-image

Module: viewer.canvastools

skimage.viewer.canvastools.LineTool(manager) Widget for line selection in a plot.
skimage.viewer.canvastools.PaintTool(…[, …]) Widget for painting on top of a plot.
skimage.viewer.canvastools.RectangleTool(manager) Widget for selecting a rectangular region in a plot.
skimage.viewer.canvastools.ThickLineTool(manager) Widget for line selection in a plot.
skimage.viewer.canvastools.base
skimage.viewer.canvastools.linetool
skimage.viewer.canvastools.painttool
skimage.viewer.canvastools.recttool

LineTool

class skimage.viewer.canvastools.LineTool(manager, on_move=None, on_release=None, on_enter=None, maxdist=10, line_props=None, handle_props=None, **kwargs) [source]

Bases: skimage.viewer.canvastools.base.CanvasToolBase

Widget for line selection in a plot.

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 end points of line 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.

line_props : dict

Properties for matplotlib.lines.Line2D.

handle_props : dict

Marker properties for the handles (also see matplotlib.lines.Line2D).

Attributes:
end_points : 2D array

End points of line ((x1, y1), (x2, y2)).

__init__(manager, on_move=None, on_release=None, on_enter=None, maxdist=10, line_props=None, handle_props=None, **kwargs) [source]

Initialize self. See help(type(self)) for accurate signature.

end_points
geometry

Geometry information that gets passed to callback functions.

hit_test(event) [source]
on_mouse_press(event) [source]
on_mouse_release(event) [source]
on_move(event) [source]
update(x=None, y=None) [source]

PaintTool

class skimage.viewer.canvastools.PaintTool(manager, overlay_shape, radius=5, alpha=0.3, on_move=None, on_release=None, on_enter=None, rect_props=None) [source]

Bases: skimage.viewer.canvastools.base.CanvasToolBase

Widget for painting on top of a plot.

Parameters:
manager : Viewer or PlotPlugin.

Skimage viewer or plot plugin object.

overlay_shape : shape tuple

2D shape tuple used to initialize overlay image.

alpha : float (between [0, 1])

Opacity of overlay

on_move : function

Function called whenever a control handle is moved. This function must accept the end points of line 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.

rect_props : dict

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

Examples

>>> from skimage.data import camera
>>> import matplotlib.pyplot as plt
>>> from skimage.viewer.canvastools import PaintTool
>>> import numpy as np
>>> img = camera() #doctest: +SKIP
>>> ax = plt.subplot(111) #doctest: +SKIP 
>>> plt.imshow(img, cmap=plt.cm.gray) #doctest: +SKIP
>>> p = PaintTool(ax,np.shape(img[:-1]),10,0.2) #doctest: +SKIP
>>> plt.show() #doctest: +SKIP
>>> mask = p.overlay #doctest: +SKIP
>>> plt.imshow(mask,cmap=plt.cm.gray) #doctest: +SKIP
>>> plt.show() #doctest: +SKIP
Attributes:
overlay : array

Overlay of painted labels displayed on top of image.

label : int

Current paint color.

__init__(manager, overlay_shape, radius=5, alpha=0.3, on_move=None, on_release=None, on_enter=None, rect_props=None) [source]

Initialize self. See help(type(self)) for accurate signature.

geometry

Geometry information that gets passed to callback functions.

label
on_key_press(event) [source]
on_mouse_press(event) [source]
on_mouse_release(event) [source]
on_move(event) [source]
overlay
radius
shape
update_cursor(x, y) [source]
update_overlay(x, y) [source]

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())  # doctest: +SKIP
>>> 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) # doctest: +SKIP
>>> viewer.show() # doctest: +SKIP
Attributes:
extents : tuple

Return (xmin, xmax, ymin, ymax).

__init__(manager, on_move=None, on_release=None, on_enter=None, maxdist=10, rect_props=None) [source]

Create a selector in ax. When a selection is made, clear the span and call onselect with:

onselect(pos_1, pos_2)

and clear the drawn box/line. The pos_1 and pos_2 are arrays of length 2 containing the x- and y-coordinate.

If minspanx is not None then events smaller than minspanx in x direction are ignored (it’s the same for y).

The rectangle is drawn with rectprops; default:

rectprops = dict(facecolor='red', edgecolor = 'black',
                 alpha=0.2, fill=True)

The line is drawn with lineprops; default:

lineprops = dict(color='black', linestyle='-',
                 linewidth = 2, alpha=0.5)

Use drawtype if you want the mouse to draw a line, a box or nothing between click and actual position by setting

drawtype = 'line', drawtype='box' or drawtype = 'none'. Drawing a line would result in a line from vertex A to vertex C in a rectangle ABCD.

spancoords is one of ‘data’ or ‘pixels’. If ‘data’, minspanx and minspanx will be interpreted in the same coordinates as the x and y axis. If ‘pixels’, they are in pixels.

button is a list of integers indicating which mouse buttons should be used for rectangle selection. You can also specify a single integer if only a single button is desired. Default is None, which does not limit which button can be used.

Note, typically:
1 = left mouse button 2 = center mouse button (scroll wheel) 3 = right mouse button

interactive will draw a set of handles and allow you interact with the widget after it is drawn.

state_modifier_keys are keyboard modifiers that affect the behavior of the widget.

The defaults are: dict(move=’ ‘, clear=’escape’, square=’shift’, center=’ctrl’)

Keyboard modifiers, which: ‘move’: Move the existing shape. ‘clear’: Clear the current shape. ‘square’: Makes the shape square. ‘center’: Make the initial point the center of the shape. ‘square’ and ‘center’ can be combined.

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

Geometry information that gets passed to callback functions.

on_mouse_press(event) [source]
on_mouse_release(event) [source]
on_move(event) [source]

ThickLineTool

class skimage.viewer.canvastools.ThickLineTool(manager, on_move=None, on_enter=None, on_release=None, on_change=None, maxdist=10, line_props=None, handle_props=None) [source]

Bases: skimage.viewer.canvastools.linetool.LineTool

Widget for line selection in a plot.

The thickness of the line can be varied using the mouse scroll wheel, or with the ‘+’ and ‘-‘ keys.

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 end points of line 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.

on_change : function

Function called whenever the line thickness is changed.

maxdist : float

Maximum pixel distance allowed when selecting control handle.

line_props : dict

Properties for matplotlib.lines.Line2D.

handle_props : dict

Marker properties for the handles (also see matplotlib.lines.Line2D).

Attributes:
end_points : 2D array

End points of line ((x1, y1), (x2, y2)).

__init__(manager, on_move=None, on_enter=None, on_release=None, on_change=None, maxdist=10, line_props=None, handle_props=None) [source]

Initialize self. See help(type(self)) for accurate signature.

on_key_press(event) [source]
on_scroll(event) [source]

© 2011 the scikit-image team
Licensed under the BSD 3-clause License.
http://scikit-image.org/docs/0.14.x/api/skimage.viewer.canvastools.html