# Module: viewer.plugins¶

 Canny filter plugin to show edges of an image. skimage.viewer.plugins.Crop([maxdist]) skimage.viewer.plugins.LabelPainter([max_radius]) Plugin to compute interpolated intensity under a scan line on an image. skimage.viewer.plugins.Measure([maxdist]) Plugin for ImageViewer that displays an overlay on top of main image. Plugin for ImageViewer that contains a plot canvas. Base class for plugins that interact with an ImageViewer. skimage.viewer.plugins.base Base class for Plugins that interact with ImageViewer. skimage.viewer.plugins.canny skimage.viewer.plugins.color_histogram skimage.viewer.plugins.crop skimage.viewer.plugins.labelplugin skimage.viewer.plugins.lineprofile skimage.viewer.plugins.measure skimage.viewer.plugins.overlayplugin skimage.viewer.plugins.plotplugin

## CannyPlugin¶

class skimage.viewer.plugins.CannyPlugin(*args, **kwargs)[source]

Bases: skimage.viewer.plugins.overlayplugin.OverlayPlugin

Canny filter plugin to show edges of an image.

__init__(self, *args, **kwargs)[source]

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

attach(self, image_viewer)[source]

Attach the plugin to an ImageViewer.

Note that the ImageViewer will automatically call this method when the plugin is added to the ImageViewer. For example:

viewer += Plugin(...)


Also note that attach automatically calls the filter function so that the image matches the filtered value specified by attached widgets.

name = 'Canny Filter'

## ColorHistogram¶

class skimage.viewer.plugins.ColorHistogram(max_pct=0.99, **kwargs)[source]

Bases: skimage.viewer.plugins.plotplugin.PlotPlugin

__init__(self, max_pct=0.99, **kwargs)[source]

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

ab_selected(self, extents)[source]
attach(self, image_viewer)[source]

Attach the plugin to an ImageViewer.

Note that the ImageViewer will automatically call this method when the plugin is added to the ImageViewer. For example:

viewer += Plugin(...)


Also note that attach automatically calls the filter function so that the image matches the filtered value specified by attached widgets.

help(self)[source]
name = 'Color Histogram'
output(self)[source]

Return the image mask and the histogram data.

Returns
maskarray of bool, same shape as image

The selected pixels.

The data describing the histogram and the selected region. The dictionary contains:

• ‘bins’ : array of float The bin boundaries for both a and b channels.

• ‘hist’ : 2D array of float The normalized histogram.

• ‘edges’ : tuple of array of float The bin edges along each dimension

• ‘extents’ : tuple of float The left and right and top and bottom of the selected region.

## Crop¶

class skimage.viewer.plugins.Crop(maxdist=10, **kwargs)[source]

Bases: skimage.viewer.plugins.base.Plugin

__init__(self, maxdist=10, **kwargs)[source]

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

attach(self, image_viewer)[source]

Attach the plugin to an ImageViewer.

Note that the ImageViewer will automatically call this method when the plugin is added to the ImageViewer. For example:

viewer += Plugin(...)


Also note that attach automatically calls the filter function so that the image matches the filtered value specified by attached widgets.

crop(self, extents)[source]
help(self)[source]
name = 'Crop'
reset(self)[source]

## LabelPainter¶

class skimage.viewer.plugins.LabelPainter(max_radius=20, **kwargs)[source]

Bases: skimage.viewer.plugins.base.Plugin

__init__(self, max_radius=20, **kwargs)[source]

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

attach(self, image_viewer)[source]

Attach the plugin to an ImageViewer.

Note that the ImageViewer will automatically call this method when the plugin is added to the ImageViewer. For example:

viewer += Plugin(...)


Also note that attach automatically calls the filter function so that the image matches the filtered value specified by attached widgets.

help(self)[source]
property label
name = 'LabelPainter'
on_enter(self, overlay)[source]
property radius

## LineProfile¶

class skimage.viewer.plugins.LineProfile(maxdist=10, epsilon='deprecated', limits='image', **kwargs)[source]

Bases: skimage.viewer.plugins.plotplugin.PlotPlugin

Plugin to compute interpolated intensity under a scan line on an image.

See PlotPlugin and Plugin classes for additional details.

Parameters
maxdistfloat

Maximum pixel distance allowed when selecting end point of scan line.

limitstuple or {None, ‘image’, ‘dtype’}

(minimum, maximum) intensity limits for plotted profile. The following special values are defined:

None : rescale based on min/max intensity along selected scan line. ‘image’ : fixed scale based on min/max intensity in image. ‘dtype’ : fixed scale based on min/max intensity of image dtype.

__init__(self, maxdist=10, epsilon='deprecated', limits='image', **kwargs)[source]

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

attach(self, image_viewer)[source]

Attach the plugin to an ImageViewer.

Note that the ImageViewer will automatically call this method when the plugin is added to the ImageViewer. For example:

viewer += Plugin(...)


Also note that attach automatically calls the filter function so that the image matches the filtered value specified by attached widgets.

get_profiles(self)[source]

Return intensity profile of the selected line.

Returns
end_points: (2, 2) array

The positions ((x1, y1), (x2, y2)) of the line ends.

profile: list of 1d arrays

Profile of intensity values. Length 1 (grayscale) or 3 (rgb).

help(self)[source]
line_changed(self, end_points)[source]
name = 'Line Profile'
output(self)[source]

Return the drawn line and the resulting scan.

Returns
line_image(M, N) uint8 array, same shape as image

An array of 0s with the scanned line set to 255. If the linewidth of the line tool is greater than 1, sets the values within the profiled polygon to 128.

scan(P,) or (P, 3) array of int or float

The line scan values across the image.

reset_axes(self, scan_data)[source]

## Measure¶

class skimage.viewer.plugins.Measure(maxdist=10, **kwargs)[source]

Bases: skimage.viewer.plugins.base.Plugin

__init__(self, maxdist=10, **kwargs)[source]

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

attach(self, image_viewer)[source]

Attach the plugin to an ImageViewer.

Note that the ImageViewer will automatically call this method when the plugin is added to the ImageViewer. For example:

viewer += Plugin(...)


Also note that attach automatically calls the filter function so that the image matches the filtered value specified by attached widgets.

help(self)[source]
line_changed(self, end_points)[source]
name = 'Measure'

## OverlayPlugin¶

class skimage.viewer.plugins.OverlayPlugin(**kwargs)[source]

Bases: skimage.viewer.plugins.base.Plugin

Plugin for ImageViewer that displays an overlay on top of main image.

The base Plugin class displays the filtered image directly on the viewer. OverlayPlugin will instead overlay an image with a transparent colormap.

See base Plugin class for additional details.

Attributes
overlayarray

Overlay displayed on top of image. This overlay defaults to a color map with alpha values varying linearly from 0 to 1.

colorint

Color of overlay.

__init__(self, **kwargs)[source]

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

attach(self, image_viewer)[source]

Attach the plugin to an ImageViewer.

Note that the ImageViewer will automatically call this method when the plugin is added to the ImageViewer. For example:

viewer += Plugin(...)


Also note that attach automatically calls the filter function so that the image matches the filtered value specified by attached widgets.

closeEvent(self, event)[source]

On close disconnect all artists and events from ImageViewer.

Note that artists must be appended to self.artists.

property color
colors = {'cyan': (0, 1, 1), 'green': (0, 1, 0), 'red': (1, 0, 0), 'yellow': (1, 1, 0)}
display_filtered_image(self, image)[source]

Display filtered image as an overlay on top of image in viewer.

property filtered_image

Return filtered image.

This “filtered image” is used when saving from the plugin.

output(self)[source]

Return the overlaid image.

Returns
overlayarray, same shape as image

The overlay currently displayed.

dataNone
property overlay

## PlotPlugin¶

class skimage.viewer.plugins.PlotPlugin(image_filter=None, height=150, width=400, **kwargs)[source]

Bases: skimage.viewer.plugins.base.Plugin

Plugin for ImageViewer that contains a plot canvas.

Base class for plugins that contain a Matplotlib plot canvas, which can, for example, display an image histogram.

See base Plugin class for additional details.

__init__(self, image_filter=None, height=150, width=400, **kwargs)[source]

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

add_plot(self)[source]
add_tool(self, tool)[source]
attach(self, image_viewer)[source]

Attach the plugin to an ImageViewer.

Note that the ImageViewer will automatically call this method when the plugin is added to the ImageViewer. For example:

viewer += Plugin(...)


Also note that attach automatically calls the filter function so that the image matches the filtered value specified by attached widgets.

redraw(self)[source]

Redraw plot.

remove_tool(self, tool)[source]

## Plugin¶

class skimage.viewer.plugins.Plugin(image_filter=None, height=0, width=400, useblit=True, dock='bottom')[source]

Bases: PyQt5.QtWidgets.QDialog

Base class for plugins that interact with an ImageViewer.

A plugin connects an image filter (or another function) to an image viewer. Note that a Plugin is initialized without an image viewer and attached in a later step. See example below for details.

Parameters
image_viewerImageViewer

Window containing image used in measurement/manipulation.

image_filterfunction

Function that gets called to update image in image viewer. This value can be None if, for example, you have a plugin that extracts information from an image and doesn’t manipulate it. Alternatively, this function can be defined as a method in a Plugin subclass.

height, widthint

Size of plugin window in pixels. Note that Qt will automatically resize a window to fit components. So if you’re adding rows of components, you can leave height = 0 and just let Qt determine the final height.

useblitbool

If True, use blitting to speed up animation. Only available on some Matplotlib backends. If None, set to True when using Agg backend. This only has an effect if you draw on top of an image viewer.

Examples

>>> from skimage.viewer import ImageViewer
>>> from skimage.viewer.widgets import Slider
>>> from skimage import data
>>>
>>> plugin = Plugin(image_filter=lambda img,
...                 threshold: img > threshold)
>>> plugin += Slider('threshold', 0, 255)
>>>
>>> image = data.coins()
>>> viewer = ImageViewer(image)
>>> viewer += plugin
>>> thresholded = viewer.show()[0][0]


The plugin will automatically delegate parameters to image_filter based on its parameter type, i.e., ptype (widgets for required arguments must be added in the order they appear in the function). The image attached to the viewer is automatically passed as the first argument to the filter function.

#TODO: Add flag so image is not passed to filter function by default.

ptype = ‘kwarg’ is the default for most widgets so it’s unnecessary here.

Attributes
image_viewerImageViewer

Window containing image used in measurement.

namestr

Name of plugin. This is displayed as the window title.

artistlist

List of Matplotlib artists and canvastools. Any artists created by the plugin should be added to this list so that it gets cleaned up on close.

__init__(self, image_filter=None, height=0, width=400, useblit=True, dock='bottom')[source]

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

add_widget(self, widget)[source]

Alternatively, Plugin’s __add__ method is overloaded to add widgets:

plugin += Widget(...)


Widgets can adjust required or optional arguments of filter function or parameters for the plugin. This is specified by the Widget’s ptype.

attach(self, image_viewer)[source]

Attach the plugin to an ImageViewer.

Note that the ImageViewer will automatically call this method when the plugin is added to the ImageViewer. For example:

viewer += Plugin(...)


Also note that attach automatically calls the filter function so that the image matches the filtered value specified by attached widgets.

clean_up(self)[source]
closeEvent(self, event)[source]

On close disconnect all artists and events from ImageViewer.

Note that artists must be appended to self.artists.

display_filtered_image(self, image)[source]

Display the filtered image on image viewer.

If you don’t want to simply replace the displayed image with the filtered image (e.g., you want to display a transparent overlay), you can override this method.

filter_image(self, *widget_arg)[source]

Call image_filter with widget args and kwargs

Note: display_filtered_image is automatically called.

property filtered_image

Return filtered image.

image_changed
image_viewer = 'Plugin is not attached to ImageViewer'
name = 'Plugin'
output(self)[source]

Return the plugin’s representation and data.

Returns
imagearray, same shape as self.image_viewer.image, or None

The filtered image.

dataNone

Any data associated with the plugin.

Notes

Derived classes should override this method to return a tuple containing an overlay of the same shape of the image, and a data object. Either of these is optional: return None if you don’t want to return a value.

remove_image_artists(self)[source]

Remove artists that are connected to the image viewer.

show(self, main_window=True)[source]

Show plugin.

update_plugin(self, name, value)[source]

Update keyword parameters of the plugin itself.

These parameters will typically be implemented as class properties so that they update the image or some other component.