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
managerViewer or PlotPlugin.

Skimage viewer or plot plugin object.

on_movefunction

Function called whenever a control handle is moved. This function must accept the end points of line as the only argument.

on_releasefunction

Function called whenever the control handle is released.

on_enterfunction

Function called whenever the “enter” key is pressed.

maxdistfloat

Maximum pixel distance allowed when selecting control handle.

line_propsdict

Properties for matplotlib.lines.Line2D.

handle_propsdict

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

Attributes
end_points2D 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]
property end_points
property 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
managerViewer or PlotPlugin.

Skimage viewer or plot plugin object.

overlay_shapeshape tuple

2D shape tuple used to initialize overlay image.

radiusint

The size of the paint cursor.

alphafloat (between [0, 1])

Opacity of overlay.

on_movefunction

Function called whenever a control handle is moved. This function must accept the end points of line as the only argument.

on_releasefunction

Function called whenever the control handle is released.

on_enterfunction

Function called whenever the “enter” key is pressed.

rect_propsdict

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() 
>>> ax = plt.subplot(111) 
>>> plt.imshow(img, cmap=plt.cm.gray) 
>>> p = PaintTool(ax,np.shape(img[:-1]),10,0.2) 
>>> plt.show() 
>>> mask = p.overlay 
>>> plt.imshow(mask,cmap=plt.cm.gray) 
>>> plt.show() 
Attributes
overlayarray

Overlay of painted labels displayed on top of image.

labelint

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]
property geometry

Geometry information that gets passed to callback functions.

property label
on_key_press(event)[source]
on_mouse_press(event)[source]
on_mouse_release(event)[source]
on_move(event)[source]
property overlay
property radius
property 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
managerViewer or PlotPlugin.

Skimage viewer or plot plugin object.

on_movefunction

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

on_releasefunction

Function called whenever the control handle is released.

on_enterfunction

Function called whenever the “enter” key is pressed.

maxdistfloat

Maximum pixel distance allowed when selecting control handle.

rect_propsdict

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
extentstuple

Return (xmin, xmax, ymin, ymax).

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

The parent axes for the widget.

onselectfunction

A callback function that is called after a selection is completed. It must have the signature:

def onselect(eclick: MouseEvent, erelease: MouseEvent)

where eclick and erelease are the mouse click and release MouseEvents that start and complete the selection.

drawtype{“box”, “line”, “none”}, default: “box”

Whether to draw the full rectangle box, the diagonal line of the rectangle, or nothing at all.

minspanxfloat, default: 0

Selections with an x-span less than minspanx are ignored.

minspanyfloat, default: 0

Selections with an y-span less than minspany are ignored.

useblitbool, default: False

Whether to use blitting for faster drawing (if supported by the backend).

linepropsdict, optional

Properties with which the line is drawn, if drawtype == "line". Default:

dict(color="black", linestyle="-", linewidth=2, alpha=0.5)
rectpropsdict, optional

Properties with which the rectangle is drawn, if drawtype == "box". Default:

dict(facecolor="red", edgecolor="black", alpha=0.2, fill=True)
spancoords{“data”, “pixels”}, default: “data”

Whether to interpret minspanx and minspany in data or in pixel coordinates.

buttonMouseButton, list of MouseButton, default: all buttons

Button(s) that trigger rectangle selection.

maxdistfloat, default: 10

Distance in pixels within which the interactive tool handles can be activated.

marker_propsdict

Properties with which the interactive handles are drawn. Currently not implemented and ignored.

interactivebool, default: False

Whether to draw a set of handles that allow interaction with the widget after it is drawn.

state_modifier_keysdict, optional

Keyboard modifiers which affect the widget’s behavior. Values amend the defaults.

  • “move”: Move the existing shape, default: no modifier.

  • “clear”: Clear the current shape, default: “escape”.

  • “square”: Makes the shape square, default: “shift”.

  • “center”: Make the initial point the center of the shape, default: “ctrl”.

“square” and “center” can be combined.

property corners

Corners of rectangle from lower left, moving clockwise.

property edge_centers

Midpoint of rectangle edges from left, moving clockwise.

property extents

Return (xmin, xmax, ymin, ymax).

property 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
managerViewer or PlotPlugin.

Skimage viewer or plot plugin object.

on_movefunction

Function called whenever a control handle is moved. This function must accept the end points of line as the only argument.

on_releasefunction

Function called whenever the control handle is released.

on_enterfunction

Function called whenever the “enter” key is pressed.

on_changefunction

Function called whenever the line thickness is changed.

maxdistfloat

Maximum pixel distance allowed when selecting control handle.

line_propsdict

Properties for matplotlib.lines.Line2D.

handle_propsdict

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

Attributes
end_points2D 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]
on_key_press(event)[source]
on_scroll(event)[source]