skimage.util.img_as_bool(image, force_copy=False) [source]

Convert an image to boolean format.  Parameters

imagendarray

Input image.
force_copybool, optional

Force a copy of the data, irrespective of its current dtype.    Returns

outndarray of bool (bool_)

Output image.     Notes The upper half of the input dtype’s positive range is True, and the lower half is False. All negative values (if present) are False.


skimage.util.img_as_float(image, force_copy=False) [source]

Convert an image to floating point format. This function is similar to img_as_float64, but will not convert lower-precision floating point arrays to float64.  Parameters

imagendarray

Input image.
force_copybool, optional

Force a copy of the data, irrespective of its current dtype.    Returns

outndarray of float

Output image.     Notes The range of a floating point image is [0.0, 1.0] or [-1.0, 1.0] when converting from unsigned or signed datatypes, respectively. If the input image has a float type, intensity values are not modified and can be outside the ranges [0.0, 1.0] or [-1.0, 1.0].


skimage.util.img_as_float32(image, force_copy=False) [source]

Convert an image to single-precision (32-bit) floating point format.  Parameters

imagendarray

Input image.
force_copybool, optional

Force a copy of the data, irrespective of its current dtype.    Returns

outndarray of float32

Output image.     Notes The range of a floating point image is [0.0, 1.0] or [-1.0, 1.0] when converting from unsigned or signed datatypes, respectively. If the input image has a float type, intensity values are not modified and can be outside the ranges [0.0, 1.0] or [-1.0, 1.0].


skimage.util.img_as_float64(image, force_copy=False) [source]

Convert an image to double-precision (64-bit) floating point format.  Parameters

imagendarray

Input image.
force_copybool, optional

Force a copy of the data, irrespective of its current dtype.    Returns

outndarray of float64

Output image.     Notes The range of a floating point image is [0.0, 1.0] or [-1.0, 1.0] when converting from unsigned or signed datatypes, respectively. If the input image has a float type, intensity values are not modified and can be outside the ranges [0.0, 1.0] or [-1.0, 1.0].


skimage.util.img_as_int(image, force_copy=False) [source]

Convert an image to 16-bit signed integer format.  Parameters

imagendarray

Input image.
force_copybool, optional

Force a copy of the data, irrespective of its current dtype.    Returns

outndarray of int16

Output image.     Notes The values are scaled between -32768 and 32767. If the input data-type is positive-only (e.g., uint8), then the output image will still only have positive values.


skimage.util.img_as_ubyte(image, force_copy=False) [source]

Convert an image to 8-bit unsigned integer format.  Parameters

imagendarray

Input image.
force_copybool, optional

Force a copy of the data, irrespective of its current dtype.    Returns

outndarray of ubyte (uint8)

Output image.     Notes Negative input values will be clipped. Positive values are scaled between 0 and 255.


skimage.util.img_as_uint(image, force_copy=False) [source]

Convert an image to 16-bit unsigned integer format.  Parameters

imagendarray

Input image.
force_copybool, optional

Force a copy of the data, irrespective of its current dtype.    Returns

outndarray of uint16

Output image.     Notes Negative input values will be clipped. Positive values are scaled between 0 and 65535.


skimage.util.invert(image, signed_float=False) [source]

Invert an image. Invert the intensity range of the input image, so that the dtype maximum is now the dtype minimum, and vice-versa. This operation is slightly different depending on the input dtype:  unsigned integers: subtract the image from the dtype maximum signed integers: subtract the image from -1 (see Notes) floats: subtract the image from 1 (if signed_float is False, so we assume the image is unsigned), or from 0 (if signed_float is True).  See the examples for clarification.  Parameters

imagendarray

Input image.
signed_floatbool, optional

If True and the image is of type float, the range is assumed to be [-1, 1]. If False and the image is of type float, the range is assumed to be [0, 1].    Returns

invertedndarray

Inverted image.     Notes Ideally, for signed integers we would simply multiply by -1. However, signed integer ranges are asymmetric. For example, for np.int8, the range of possible values is [-128, 127], so that -128 * -1 equals -128! By subtracting from -1, we correctly map the maximum dtype value to the minimum. Examples >>> img = np.array([[100,  0, 200],
...                 [  0, 50,   0],
...                 [ 30,  0, 255]], np.uint8)
>>> invert(img)
array([[155, 255,  55],
       [255, 205, 255],
       [225, 255,   0]], dtype=uint8)
>>> img2 = np.array([[ -2, 0, -128],
...                  [127, 0,    5]], np.int8)
>>> invert(img2)
array([[   1,   -1,  127],
       [-128,   -1,   -6]], dtype=int8)
>>> img3 = np.array([[ 0., 1., 0.5, 0.75]])
>>> invert(img3)
array([[1.  , 0.  , 0.5 , 0.25]])
>>> img4 = np.array([[ 0., 1., -1., -0.25]])
>>> invert(img4, signed_float=True)
array([[-0.  , -1.  ,  1.  ,  0.25]])


skimage.util.map_array(input_arr, input_vals, output_vals, out=None) [source]

Map values from input array from input_vals to output_vals.  Parameters

input_arrarray of int, shape (M[, N][, P][, …])

The input label image.
input_valsarray of int, shape (N,)

The values to map from.
output_valsarray, shape (N,)

The values to map to.  out: array, same shape as `input_arr`

The output array. Will be created if not provided. It should have the same dtype as output_vals.    Returns

outarray, same shape as input_arr

The array of mapped values.


skimage.util.montage(arr_in, fill='mean', rescale_intensity=False, grid_shape=None, padding_width=0, multichannel=False) [source]

Create a montage of several single- or multichannel images. Create a rectangular montage from an input array representing an ensemble of equally shaped single- (gray) or multichannel (color) images. For example, montage(arr_in) called with the following arr_in
1 2 3   will return
1 2
3
      where the ‘*’ patch will be determined by the fill parameter.  Parameters

arr_in(K, M, N[, C]) ndarray

An array representing an ensemble of K images of equal shape.
fillfloat or array-like of floats or ‘mean’, optional

Value to fill the padding areas and/or the extra tiles in the output array. Has to be float for single channel collections. For multichannel collections has to be an array-like of shape of number of channels. If mean, uses the mean value over all images.
rescale_intensitybool, optional

Whether to rescale the intensity of each image to [0, 1].
grid_shapetuple, optional

The desired grid shape for the montage (ntiles_row, ntiles_column). The default aspect ratio is square.
padding_widthint, optional

The size of the spacing between the tiles and between the tiles and the borders. If non-zero, makes the boundaries of individual images easier to perceive.
multichannelboolean, optional

If True, the last arr_in dimension is threated as a color channel, otherwise as spatial.    Returns

arr_out(K*(M+p)+p, K*(N+p)+p[, C]) ndarray

Output array with input images glued together (including padding p).     Examples >>> import numpy as np
>>> from skimage.util import montage
>>> arr_in = np.arange(3 * 2 * 2).reshape(3, 2, 2)
>>> arr_in
array([[[ 0,  1],
        [ 2,  3]],
       [[ 4,  5],
        [ 6,  7]],
       [[ 8,  9],
        [10, 11]]])
>>> arr_out = montage(arr_in)
>>> arr_out.shape
(4, 4)
>>> arr_out
array([[ 0,  1,  4,  5],
       [ 2,  3,  6,  7],
       [ 8,  9,  5,  5],
       [10, 11,  5,  5]])
>>> arr_in.mean()
5.5
>>> arr_out_nonsquare = montage(arr_in, grid_shape=(1, 3))
>>> arr_out_nonsquare
array([[ 0,  1,  4,  5,  8,  9],
       [ 2,  3,  6,  7, 10, 11]])
>>> arr_out_nonsquare.shape
(2, 6)


skimage.util.pad(array, pad_width, mode='constant', **kwargs) [source]

Pad an array.  Parameters

arrayarray_like of rank N

The array to pad.
pad_width{sequence, array_like, int}

Number of values padded to the edges of each axis. ((before_1, after_1), … (before_N, after_N)) unique pad widths for each axis. ((before, after),) yields same before and after pad for each axis. (pad,) or int is a shortcut for before = after = pad width for all axes.
modestr or function, optional

One of the following string values or a user supplied function.  ‘constant’ (default)

Pads with a constant value.  ‘edge’

Pads with the edge values of array.  ‘linear_ramp’

Pads with the linear ramp between end_value and the array edge value.  ‘maximum’

Pads with the maximum value of all or part of the vector along each axis.  ‘mean’

Pads with the mean value of all or part of the vector along each axis.  ‘median’

Pads with the median value of all or part of the vector along each axis.  ‘minimum’

Pads with the minimum value of all or part of the vector along each axis.  ‘reflect’

Pads with the reflection of the vector mirrored on the first and last values of the vector along each axis.  ‘symmetric’

Pads with the reflection of the vector mirrored along the edge of the array.  ‘wrap’

Pads with the wrap of the vector along the axis. The first values are used to pad the end and the end values are used to pad the beginning.  ‘empty’

Pads with undefined values.  New in version 1.17.   <function>

Padding function, see Notes.
stat_lengthsequence or int, optional

Used in ‘maximum’, ‘mean’, ‘median’, and ‘minimum’. Number of values at edge of each axis used to calculate the statistic value. ((before_1, after_1), … (before_N, after_N)) unique statistic lengths for each axis. ((before, after),) yields same before and after statistic lengths for each axis. (stat_length,) or int is a shortcut for before = after = statistic length for all axes. Default is None, to use the entire axis.
constant_valuessequence or scalar, optional

Used in ‘constant’. The values to set the padded values for each axis. ((before_1, after_1), ... (before_N, after_N)) unique pad constants for each axis. ((before, after),) yields same before and after constants for each axis. (constant,) or constant is a shortcut for before = after = constant for all axes. Default is 0.
end_valuessequence or scalar, optional

Used in ‘linear_ramp’. The values used for the ending value of the linear_ramp and that will form the edge of the padded array. ((before_1, after_1), ... (before_N, after_N)) unique end values for each axis. ((before, after),) yields same before and after end values for each axis. (constant,) or constant is a shortcut for before = after = constant for all axes. Default is 0.
reflect_type{‘even’, ‘odd’}, optional

Used in ‘reflect’, and ‘symmetric’. The ‘even’ style is the default with an unaltered reflection around the edge value. For the ‘odd’ style, the extended part of the array is created by subtracting the reflected values from two times the edge value.    Returns

padndarray

Padded array of rank equal to array with shape increased according to pad_width.     Notes  New in version 1.7.0.  For an array with rank greater than 1, some of the padding of later axes is calculated from padding of previous axes. This is easiest to think about with a rank 2 array where the corners of the padded array are calculated by using padded values from the first axis. The padding function, if used, should modify a rank 1 array in-place. It has the following signature: padding_func(vector, iaxis_pad_width, iaxis, kwargs)
 where
vectorndarray

A rank 1 array already padded with zeros. Padded values are vector[:iaxis_pad_width[0]] and vector[-iaxis_pad_width[1]:].
iaxis_pad_widthtuple

A 2-tuple of ints, iaxis_pad_width[0] represents the number of values padded at the beginning of vector where iaxis_pad_width[1] represents the number of values padded at the end of vector.
iaxisint

The axis currently being calculated.
kwargsdict

Any keyword arguments the function requires.   Examples >>> a = [1, 2, 3, 4, 5]
>>> np.pad(a, (2, 3), 'constant', constant_values=(4, 6))
array([4, 4, 1, ..., 6, 6, 6])
 >>> np.pad(a, (2, 3), 'edge')
array([1, 1, 1, ..., 5, 5, 5])
 >>> np.pad(a, (2, 3), 'linear_ramp', end_values=(5, -4))
array([ 5,  3,  1,  2,  3,  4,  5,  2, -1, -4])
 >>> np.pad(a, (2,), 'maximum')
array([5, 5, 1, 2, 3, 4, 5, 5, 5])
 >>> np.pad(a, (2,), 'mean')
array([3, 3, 1, 2, 3, 4, 5, 3, 3])
 >>> np.pad(a, (2,), 'median')
array([3, 3, 1, 2, 3, 4, 5, 3, 3])
 >>> a = [[1, 2], [3, 4]]
>>> np.pad(a, ((3, 2), (2, 3)), 'minimum')
array([[1, 1, 1, 2, 1, 1, 1],
       [1, 1, 1, 2, 1, 1, 1],
       [1, 1, 1, 2, 1, 1, 1],
       [1, 1, 1, 2, 1, 1, 1],
       [3, 3, 3, 4, 3, 3, 3],
       [1, 1, 1, 2, 1, 1, 1],
       [1, 1, 1, 2, 1, 1, 1]])
 >>> a = [1, 2, 3, 4, 5]
>>> np.pad(a, (2, 3), 'reflect')
array([3, 2, 1, 2, 3, 4, 5, 4, 3, 2])
 >>> np.pad(a, (2, 3), 'reflect', reflect_type='odd')
array([-1,  0,  1,  2,  3,  4,  5,  6,  7,  8])
 >>> np.pad(a, (2, 3), 'symmetric')
array([2, 1, 1, 2, 3, 4, 5, 5, 4, 3])
 >>> np.pad(a, (2, 3), 'symmetric', reflect_type='odd')
array([0, 1, 1, 2, 3, 4, 5, 5, 6, 7])
 >>> np.pad(a, (2, 3), 'wrap')
array([4, 5, 1, 2, 3, 4, 5, 1, 2, 3])
 >>> def pad_with(vector, pad_width, iaxis, kwargs):
...     pad_value = kwargs.get('padder', 10)
...     vector[:pad_width[0]] = pad_value
...     vector[-pad_width[1]:] = pad_value
>>> a = np.arange(6)
>>> a = a.reshape((2, 3))
>>> np.pad(a, 2, pad_with)
array([[10, 10, 10, 10, 10, 10, 10],
       [10, 10, 10, 10, 10, 10, 10],
       [10, 10,  0,  1,  2, 10, 10],
       [10, 10,  3,  4,  5, 10, 10],
       [10, 10, 10, 10, 10, 10, 10],
       [10, 10, 10, 10, 10, 10, 10]])
>>> np.pad(a, 2, pad_with, padder=100)
array([[100, 100, 100, 100, 100, 100, 100],
       [100, 100, 100, 100, 100, 100, 100],
       [100, 100,   0,   1,   2, 100, 100],
       [100, 100,   3,   4,   5, 100, 100],
       [100, 100, 100, 100, 100, 100, 100],
       [100, 100, 100, 100, 100, 100, 100]])


skimage.util.random_noise(image, mode='gaussian', seed=None, clip=True, **kwargs) [source]

Function to add random noise of various types to a floating-point image.  Parameters

imagendarray

Input image data. Will be converted to float.
modestr, optional

One of the following strings, selecting the type of noise to add:  ‘gaussian’ Gaussian-distributed additive noise.
 ‘localvar’ Gaussian-distributed additive noise, with specified

local variance at each point of image.    ‘poisson’ Poisson-distributed noise generated from the data. ‘salt’ Replaces random pixels with 1.
 ‘pepper’ Replaces random pixels with 0 (for unsigned images) or

-1 (for signed images).

‘s&p’ Replaces random pixels with either 1 or low_val, where

low_val is 0 for unsigned images or -1 for signed images.
 ‘speckle’ Multiplicative noise using out = image + n*image, where

n is Gaussian noise with specified mean & variance.
seedint, optional

If provided, this will set the random seed before generating noise, for valid pseudo-random comparisons.
clipbool, optional

If True (default), the output will be clipped after noise applied for modes ‘speckle’, ‘poisson’, and ‘gaussian’. This is needed to maintain the proper image data range. If False, clipping is not applied, and the output may extend beyond the range [-1, 1].
meanfloat, optional

Mean of random distribution. Used in ‘gaussian’ and ‘speckle’. Default : 0.
varfloat, optional

Variance of random distribution. Used in ‘gaussian’ and ‘speckle’. Note: variance = (standard deviation) ** 2. Default : 0.01
local_varsndarray, optional

Array of positive floats, same shape as image, defining the local variance at every image point. Used in ‘localvar’.
amountfloat, optional

Proportion of image pixels to replace with noise on range [0, 1]. Used in ‘salt’, ‘pepper’, and ‘salt & pepper’. Default : 0.05
salt_vs_pepperfloat, optional

Proportion of salt vs. pepper noise for ‘s&p’ on range [0, 1]. Higher values represent more salt. Default : 0.5 (equal amounts)    Returns

outndarray

Output floating-point image data on range [0, 1] or [-1, 1] if the input image was unsigned or signed, respectively.     Notes Speckle, Poisson, Localvar, and Gaussian noise may generate noise outside the valid image range. The default is to clip (not alias) these values, but they may be preserved by setting clip=False. Note that in this case the output may contain values outside the ranges [0, 1] or [-1, 1]. Use this option with care. Because of the prevalence of exclusively positive floating-point images in intermediate calculations, it is not possible to intuit if an input is signed based on dtype alone. Instead, negative values are explicitly searched for. Only if found does this function assume signed input. Unexpected results only occur in rare, poorly exposes cases (e.g. if all values are above 50 percent gray in a signed image). In this event, manually scaling the input to the positive domain will solve the problem. The Poisson distribution is only defined for positive integers. To apply this noise type, the number of unique values in the image is found and the next round power of two is used to scale up the floating-point result, after which it is scaled back down to the floating-point image range. To generate Poisson noise against a signed image, the signed image is temporarily converted to an unsigned image in the floating point domain, Poisson noise is generated, then it is returned to the original range.


skimage.util.regular_grid(ar_shape, n_points) [source]

Find n_points regularly spaced along ar_shape. The returned points (as slices) should be as close to cubically-spaced as possible. Essentially, the points are spaced by the Nth root of the input array size, where N is the number of dimensions. However, if an array dimension cannot fit a full step size, it is “discarded”, and the computation is done for only the remaining dimensions.  Parameters

ar_shapearray-like of ints

The shape of the space embedding the grid. len(ar_shape) is the number of dimensions.
n_pointsint

The (approximate) number of points to embed in the space.    Returns

slicestuple of slice objects

A slice along each dimension of ar_shape, such that the intersection of all the slices give the coordinates of regularly spaced points.  Changed in version 0.14.1: In scikit-image 0.14.1 and 0.15, the return type was changed from a list to a tuple to ensure compatibility with Numpy 1.15 and higher. If your code requires the returned result to be a list, you may convert the output of this function to a list with: >>> result = list(regular_grid(ar_shape=(3, 20, 40), n_points=8))
      Examples >>> ar = np.zeros((20, 40))
>>> g = regular_grid(ar.shape, 8)
>>> g
(slice(5, None, 10), slice(5, None, 10))
>>> ar[g] = 1
>>> ar.sum()
8.0
>>> ar = np.zeros((20, 40))
>>> g = regular_grid(ar.shape, 32)
>>> g
(slice(2, None, 5), slice(2, None, 5))
>>> ar[g] = 1
>>> ar.sum()
32.0
>>> ar = np.zeros((3, 20, 40))
>>> g = regular_grid(ar.shape, 8)
>>> g
(slice(1, None, 3), slice(5, None, 10), slice(5, None, 10))
>>> ar[g] = 1
>>> ar.sum()
8.0


skimage.util.regular_seeds(ar_shape, n_points, dtype=<class 'int'>) [source]

Return an image with ~`n_points` regularly-spaced nonzero pixels.  Parameters

ar_shapetuple of int

The shape of the desired output image.
n_pointsint

The desired number of nonzero points.
dtypenumpy data type, optional

The desired data type of the output.    Returns

seed_imgarray of int or bool

The desired image.     Examples >>> regular_seeds((5, 5), 4)
array([[0, 0, 0, 0, 0],
       [0, 1, 0, 2, 0],
       [0, 0, 0, 0, 0],
       [0, 3, 0, 4, 0],
       [0, 0, 0, 0, 0]])


skimage.util.unique_rows(ar) [source]

Remove repeated rows from a 2D array. In particular, if given an array of coordinates of shape (Npoints, Ndim), it will remove repeated points.  Parameters

ar2-D ndarray

The input array.    Returns

ar_out2-D ndarray

A copy of the input array with repeated rows removed.    Raises

ValueErrorif ar is not two-dimensional.
   Notes The function will generate a copy of ar if it is not C-contiguous, which will negatively affect performance for large input arrays. Examples >>> ar = np.array([[1, 0, 1],
...                [0, 1, 0],
...                [1, 0, 1]], np.uint8)
>>> unique_rows(ar)
array([[0, 1, 0],
       [1, 0, 1]], dtype=uint8)


skimage.util.view_as_windows(arr_in, window_shape, step=1) [source]

Rolling window view of the input n-dimensional array. Windows are overlapping views of the input array, with adjacent windows shifted by a single row or column (or an index of a higher dimension).  Parameters

arr_inndarray

N-d input array.
window_shapeinteger or tuple of length arr_in.ndim

Defines the shape of the elementary n-dimensional orthotope (better know as hyperrectangle [1]) of the rolling window view. If an integer is given, the shape will be a hypercube of sidelength given by its value.
stepinteger or tuple of length arr_in.ndim

Indicates step size at which extraction shall be performed. If integer is given, then the step is uniform in all dimensions.    Returns

arr_outndarray

(rolling) window view of the input array.     Notes One should be very careful with rolling views when it comes to memory usage. Indeed, although a ‘view’ has the same memory footprint as its base array, the actual array that emerges when this ‘view’ is used in a computation is generally a (much) larger array than the original, especially for 2-dimensional arrays and above. For example, let us consider a 3 dimensional array of size (100, 100, 100) of float64. This array takes about 8*100**3 Bytes for storage which is just 8 MB. If one decides to build a rolling view on this array with a window of (3, 3, 3) the hypothetical size of the rolling view (if one was to reshape the view for example) would be 8*(100-3+1)**3*3**3 which is about 203 MB! The scaling becomes even worse as the dimension of the input array becomes larger. References
1
https://en.wikipedia.org/wiki/Hyperrectangle   Examples >>> import numpy as np
>>> from skimage.util.shape import view_as_windows
>>> A = np.arange(4*4).reshape(4,4)
>>> A
array([[ 0,  1,  2,  3],
       [ 4,  5,  6,  7],
       [ 8,  9, 10, 11],
       [12, 13, 14, 15]])
>>> window_shape = (2, 2)
>>> B = view_as_windows(A, window_shape)
>>> B[0, 0]
array([[0, 1],
       [4, 5]])
>>> B[0, 1]
array([[1, 2],
       [5, 6]])
 >>> A = np.arange(10)
>>> A
array([0, 1, 2, 3, 4, 5, 6, 7, 8, 9])
>>> window_shape = (3,)
>>> B = view_as_windows(A, window_shape)
>>> B.shape
(8, 3)
>>> B
array([[0, 1, 2],
       [1, 2, 3],
       [2, 3, 4],
       [3, 4, 5],
       [4, 5, 6],
       [5, 6, 7],
       [6, 7, 8],
       [7, 8, 9]])
 >>> A = np.arange(5*4).reshape(5, 4)
>>> A
array([[ 0,  1,  2,  3],
       [ 4,  5,  6,  7],
       [ 8,  9, 10, 11],
       [12, 13, 14, 15],
       [16, 17, 18, 19]])
>>> window_shape = (4, 3)
>>> B = view_as_windows(A, window_shape)
>>> B.shape
(2, 2, 4, 3)
>>> B
array([[[[ 0,  1,  2],
         [ 4,  5,  6],
         [ 8,  9, 10],
         [12, 13, 14]],
        [[ 1,  2,  3],
         [ 5,  6,  7],
         [ 9, 10, 11],
         [13, 14, 15]]],
       [[[ 4,  5,  6],
         [ 8,  9, 10],
         [12, 13, 14],
         [16, 17, 18]],
        [[ 5,  6,  7],
         [ 9, 10, 11],
         [13, 14, 15],
         [17, 18, 19]]]])


Module: viewer
skimage.viewer.CollectionViewer(image_collection) Viewer for displaying image collections.
skimage.viewer.ImageViewer(image[, useblit]) Viewer for displaying images.
skimage.viewer.canvastools
skimage.viewer.plugins
skimage.viewer.qt
skimage.viewer.utils
skimage.viewer.viewers
skimage.viewer.widgets Widgets for interacting with ImageViewer.   CollectionViewer
class skimage.viewer.CollectionViewer(image_collection, update_on='move', **kwargs) [source]

Bases: skimage.viewer.viewers.core.ImageViewer Viewer for displaying image collections. Select the displayed frame of the image collection using the slider or with the following keyboard shortcuts:  left/right arrows

Previous/next image in collection.  number keys, 0–9

0% to 90% of collection. For example, “5” goes to the image in the middle (i.e. 50%) of the collection.  home/end keys

First/last image in collection.    Parameters

image_collectionlist of images

List of images to be displayed.
update_on{‘move’ | ‘release’}

Control whether image is updated on slide or release of the image slider. Using ‘on_release’ will give smoother behavior when displaying large images or when writing a plugin/subclass that requires heavy computation.
__init__(image_collection, update_on='move', **kwargs) [source]

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

keyPressEvent(event) [source]

update_index(name, index) [source]

Select image on display using index into image collection.

 ImageViewer
class skimage.viewer.ImageViewer(image, useblit=True) [source]

Bases: object Viewer for displaying images. This viewer is a simple container object that holds a Matplotlib axes for showing images. ImageViewer doesn’t subclass the Matplotlib axes (or figure) because of the high probability of name collisions. Subclasses and plugins will likely extend the update_image method to add custom overlays or filter the displayed image.  Parameters

imagearray

Image being viewed.     Examples >>> from skimage import data
>>> image = data.coins()
>>> viewer = ImageViewer(image)
>>> viewer.show()
  Attributes

canvas, fig, axMatplotlib canvas, figure, and axes

Matplotlib canvas, figure, and axes used to display image.
imagearray

Image being viewed. Setting this value will update the displayed frame.
original_imagearray

Plugins typically operate on (but don’t change) the original image.
pluginslist

List of attached plugins.
__init__(image, useblit=True) [source]

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

add_tool(tool) [source]

closeEvent(event) [source]

connect_event(event, callback) [source]

Connect callback function to matplotlib event and return id.

disconnect_event(callback_id) [source]

Disconnect callback by its id (returned by connect_event).

dock_areas = {'bottom': None, 'left': None, 'right': None, 'top': None}

property image

open_file(filename=None) [source]

Open image file and display in viewer.

original_image_changed = None

redraw() [source]

remove_tool(tool) [source]

reset_image() [source]

save_to_file(filename=None) [source]

Save current image to file. The current behavior is not ideal: It saves the image displayed on screen, so all images will be converted to RGB, and the image size is not preserved (resizing the viewer window will alter the size of the saved image).

show(main_window=True) [source]

Show ImageViewer and attached plugins. This behaves much like matplotlib.pyplot.show and QWidget.show.

update_image(image) [source]

Update displayed image. This method can be overridden or extended in subclasses and plugins to react to image changes.


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]

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

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]

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

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]

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

on_key_press(event) [source]

on_scroll(event) [source]


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]

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

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]


property geometry
Geometry information that gets passed to callback functions.


__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.


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]

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

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]


__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.


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]


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).


__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.


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]

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

on_key_press(event) [source]

on_scroll(event) [source]


__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.


class skimage.viewer.CollectionViewer(image_collection, update_on='move', **kwargs) [source]

Bases: skimage.viewer.viewers.core.ImageViewer Viewer for displaying image collections. Select the displayed frame of the image collection using the slider or with the following keyboard shortcuts:  left/right arrows

Previous/next image in collection.  number keys, 0–9

0% to 90% of collection. For example, “5” goes to the image in the middle (i.e. 50%) of the collection.  home/end keys

First/last image in collection.    Parameters

image_collectionlist of images

List of images to be displayed.
update_on{‘move’ | ‘release’}

Control whether image is updated on slide or release of the image slider. Using ‘on_release’ will give smoother behavior when displaying large images or when writing a plugin/subclass that requires heavy computation.
__init__(image_collection, update_on='move', **kwargs) [source]

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

keyPressEvent(event) [source]

update_index(name, index) [source]

Select image on display using index into image collection.


update_index(name, index) [source]

Select image on display using index into image collection.


__init__(image_collection, update_on='move', **kwargs) [source]

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


class skimage.viewer.ImageViewer(image, useblit=True) [source]

Bases: object Viewer for displaying images. This viewer is a simple container object that holds a Matplotlib axes for showing images. ImageViewer doesn’t subclass the Matplotlib axes (or figure) because of the high probability of name collisions. Subclasses and plugins will likely extend the update_image method to add custom overlays or filter the displayed image.  Parameters

imagearray

Image being viewed.     Examples >>> from skimage import data
>>> image = data.coins()
>>> viewer = ImageViewer(image)
>>> viewer.show()
  Attributes

canvas, fig, axMatplotlib canvas, figure, and axes

Matplotlib canvas, figure, and axes used to display image.
imagearray

Image being viewed. Setting this value will update the displayed frame.
original_imagearray

Plugins typically operate on (but don’t change) the original image.
pluginslist

List of attached plugins.
__init__(image, useblit=True) [source]

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

add_tool(tool) [source]

closeEvent(event) [source]

connect_event(event, callback) [source]

Connect callback function to matplotlib event and return id.

disconnect_event(callback_id) [source]

Disconnect callback by its id (returned by connect_event).

dock_areas = {'bottom': None, 'left': None, 'right': None, 'top': None}

property image

open_file(filename=None) [source]

Open image file and display in viewer.

original_image_changed = None

redraw() [source]

remove_tool(tool) [source]

reset_image() [source]

save_to_file(filename=None) [source]

Save current image to file. The current behavior is not ideal: It saves the image displayed on screen, so all images will be converted to RGB, and the image size is not preserved (resizing the viewer window will alter the size of the saved image).

show(main_window=True) [source]

Show ImageViewer and attached plugins. This behaves much like matplotlib.pyplot.show and QWidget.show.

update_image(image) [source]

Update displayed image. This method can be overridden or extended in subclasses and plugins to react to image changes.


connect_event(event, callback) [source]

Connect callback function to matplotlib event and return id.


disconnect_event(callback_id) [source]

Disconnect callback by its id (returned by connect_event).


dock_areas = {'bottom': None, 'left': None, 'right': None, 'top': None}


open_file(filename=None) [source]

Open image file and display in viewer.


save_to_file(filename=None) [source]

Save current image to file. The current behavior is not ideal: It saves the image displayed on screen, so all images will be converted to RGB, and the image size is not preserved (resizing the viewer window will alter the size of the saved image).


show(main_window=True) [source]

Show ImageViewer and attached plugins. This behaves much like matplotlib.pyplot.show and QWidget.show.


update_image(image) [source]

Update displayed image. This method can be overridden or extended in subclasses and plugins to react to image changes.


__init__(image, useblit=True) [source]

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


Module: viewer.plugins
skimage.viewer.plugins.CannyPlugin(*args, …) Canny filter plugin to show edges of an image.
skimage.viewer.plugins.ColorHistogram([max_pct])
skimage.viewer.plugins.Crop([maxdist])
skimage.viewer.plugins.LabelPainter([max_radius])
skimage.viewer.plugins.LineProfile([…]) Plugin to compute interpolated intensity under a scan line on an image.
skimage.viewer.plugins.Measure([maxdist])
skimage.viewer.plugins.OverlayPlugin(**kwargs) Plugin for ImageViewer that displays an overlay on top of main image.
skimage.viewer.plugins.PlotPlugin([…]) Plugin for ImageViewer that contains a plot canvas.
skimage.viewer.plugins.Plugin([…]) 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__(*args, **kwargs) [source]

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

attach(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__(max_pct=0.99, **kwargs) [source]

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

ab_selected(extents) [source]

attach(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() [source]

name = 'Color Histogram'

output() [source]

Return the image mask and the histogram data.  Returns

maskarray of bool, same shape as image

The selected pixels.
datadict

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__(maxdist=10, **kwargs) [source]

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

attach(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(extents) [source]

help() [source]

name = 'Crop'

reset() [source]

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

Bases: skimage.viewer.plugins.base.Plugin
__init__(max_radius=20, **kwargs) [source]

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

attach(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() [source]

property label

name = 'LabelPainter'

on_enter(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__(maxdist=10, epsilon='deprecated', limits='image', **kwargs) [source]

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

attach(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() [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() [source]

line_changed(end_points) [source]

name = 'Line Profile'

output() [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(scan_data) [source]

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

Bases: skimage.viewer.plugins.base.Plugin
__init__(maxdist=10, **kwargs) [source]

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

attach(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() [source]

line_changed(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__(**kwargs) [source]

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

attach(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(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(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() [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__(image_filter=None, height=150, width=400, **kwargs) [source]

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

add_plot() [source]

add_tool(tool) [source]

attach(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() [source]

Redraw plot.

remove_tool(tool) [source]

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

Bases: object 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__(image_filter=None, height=0, width=400, useblit=True, dock='bottom') [source]

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

add_widget(widget) [source]

Add widget to plugin. 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(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() [source]

closeEvent(event) [source]

On close disconnect all artists and events from ImageViewer. Note that artists must be appended to self.artists.

display_filtered_image(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(*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 = None

image_viewer = 'Plugin is not attached to ImageViewer'

name = 'Plugin'

output() [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() [source]

Remove artists that are connected to the image viewer.

show(main_window=True) [source]

Show plugin.

update_plugin(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.


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

Bases: skimage.viewer.plugins.overlayplugin.OverlayPlugin Canny filter plugin to show edges of an image.
__init__(*args, **kwargs) [source]

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

attach(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'


attach(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.


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

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


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

Bases: skimage.viewer.plugins.plotplugin.PlotPlugin
__init__(max_pct=0.99, **kwargs) [source]

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

ab_selected(extents) [source]

attach(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() [source]

name = 'Color Histogram'

output() [source]

Return the image mask and the histogram data.  Returns

maskarray of bool, same shape as image

The selected pixels.
datadict

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.


output() [source]

Return the image mask and the histogram data.  Returns

maskarray of bool, same shape as image

The selected pixels.
datadict

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.


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

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


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

Bases: skimage.viewer.plugins.base.Plugin
__init__(maxdist=10, **kwargs) [source]

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

attach(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(extents) [source]

help() [source]

name = 'Crop'

reset() [source]


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

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


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

Bases: skimage.viewer.plugins.base.Plugin
__init__(max_radius=20, **kwargs) [source]

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

attach(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() [source]

property label

name = 'LabelPainter'

on_enter(overlay) [source]

property radius


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

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


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__(maxdist=10, epsilon='deprecated', limits='image', **kwargs) [source]

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

attach(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() [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() [source]

line_changed(end_points) [source]

name = 'Line Profile'

output() [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(scan_data) [source]


get_profiles() [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).


output() [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.


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

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


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

Bases: skimage.viewer.plugins.base.Plugin
__init__(maxdist=10, **kwargs) [source]

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

attach(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() [source]

line_changed(end_points) [source]

name = 'Measure'


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__(**kwargs) [source]

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

attach(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(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(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() [source]

Return the overlaid image.  Returns

overlayarray, same shape as image

The overlay currently displayed.
dataNone

property overlay


closeEvent(event) [source]

On close disconnect all artists and events from ImageViewer. Note that artists must be appended to self.artists.


display_filtered_image(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() [source]

Return the overlaid image.  Returns

overlayarray, same shape as image

The overlay currently displayed.
dataNone


__init__(**kwargs) [source]

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


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__(image_filter=None, height=150, width=400, **kwargs) [source]

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

add_plot() [source]

add_tool(tool) [source]

attach(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() [source]

Redraw plot.

remove_tool(tool) [source]


attach(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.


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

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


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

Bases: object 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__(image_filter=None, height=0, width=400, useblit=True, dock='bottom') [source]

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

add_widget(widget) [source]

Add widget to plugin. 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(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() [source]

closeEvent(event) [source]

On close disconnect all artists and events from ImageViewer. Note that artists must be appended to self.artists.

display_filtered_image(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(*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 = None

image_viewer = 'Plugin is not attached to ImageViewer'

name = 'Plugin'

output() [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() [source]

Remove artists that are connected to the image viewer.

show(main_window=True) [source]

Show plugin.

update_plugin(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.


add_widget(widget) [source]

Add widget to plugin. 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.


display_filtered_image(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.


property filtered_image
Return filtered image.


filter_image(*widget_arg) [source]

Call image_filter with widget args and kwargs Note: display_filtered_image is automatically called.


image_viewer = 'Plugin is not attached to ImageViewer'


output() [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() [source]

Remove artists that are connected to the image viewer.


show(main_window=True) [source]

Show plugin.


update_plugin(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.


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

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


Module: viewer.utils
skimage.viewer.utils.figimage(image[, …]) Return figure and axes with figure tightly surrounding image.
skimage.viewer.utils.init_qtapp() Initialize QAppliction.
skimage.viewer.utils.new_plot([parent, …]) Return new figure and axes.
skimage.viewer.utils.start_qtapp([app]) Start Qt mainloop
skimage.viewer.utils.update_axes_image(…) Update the image displayed by an image plot.
skimage.viewer.utils.ClearColormap(rgb[, …]) Color map that varies linearly from alpha = 0 to 1
skimage.viewer.utils.FigureCanvas(figure, …) Canvas for displaying images.
skimage.viewer.utils.LinearColormap(name, …) LinearSegmentedColormap in which color varies smoothly.
skimage.viewer.utils.RequiredAttr([init_val]) A class attribute that must be set before use.
skimage.viewer.utils.canvas
skimage.viewer.utils.core
skimage.viewer.utils.dialogs    figimage
skimage.viewer.utils.figimage(image, scale=1, dpi=None, **kwargs) [source]

Return figure and axes with figure tightly surrounding image. Unlike pyplot.figimage, this actually plots onto an axes object, which fills the figure. Plotting the image onto an axes allows for subsequent overlays of axes artists.  Parameters

imagearray

image to plot
scalefloat

If scale is 1, the figure and axes have the same dimension as the image. Smaller values of scale will shrink the figure.
dpiint

Dots per inch for figure. If None, use the default rcParam.
 init_qtapp
skimage.viewer.utils.init_qtapp() [source]

Initialize QAppliction. The QApplication needs to be initialized before creating any QWidgets
 new_plot
skimage.viewer.utils.new_plot(parent=None, subplot_kw=None, **fig_kw) [source]

Return new figure and axes.  Parameters

parentQtWidget

Qt widget that displays the plot objects. If None, you must manually call canvas.setParent and pass the parent widget.
subplot_kwdict

Keyword arguments passed matplotlib.figure.Figure.add_subplot.
fig_kwdict

Keyword arguments passed matplotlib.figure.Figure.
 start_qtapp
skimage.viewer.utils.start_qtapp(app=None) [source]

Start Qt mainloop
 update_axes_image
skimage.viewer.utils.update_axes_image(image_axes, image) [source]

Update the image displayed by an image plot. This sets the image plot’s array and updates its shape appropriately  Parameters

image_axesmatplotlib.image.AxesImage

Image axes to update.
imagearray

Image array.
 ClearColormap
class skimage.viewer.utils.ClearColormap(rgb, max_alpha=1, name='clear_color') [source]

Bases: skimage.viewer.utils.core.LinearColormap Color map that varies linearly from alpha = 0 to 1
__init__(rgb, max_alpha=1, name='clear_color') [source]

Create color map from linear mapping segments segmentdata argument is a dictionary with a red, green and blue entries. Each entry should be a list of x, y0, y1 tuples, forming rows in a table. Entries for alpha are optional. Example: suppose you want red to increase from 0 to 1 over the bottom half, green to do the same over the middle half, and blue over the top half. Then you would use: cdict = {'red':   [(0.0,  0.0, 0.0),
                   (0.5,  1.0, 1.0),
                   (1.0,  1.0, 1.0)],

         'green': [(0.0,  0.0, 0.0),
                   (0.25, 0.0, 0.0),
                   (0.75, 1.0, 1.0),
                   (1.0,  1.0, 1.0)],

         'blue':  [(0.0,  0.0, 0.0),
                   (0.5,  0.0, 0.0),
                   (1.0,  1.0, 1.0)]}
 Each row in the table for a given color is a sequence of x, y0, y1 tuples. In each sequence, x must increase monotonically from 0 to 1. For any input value z falling between x[i] and x[i+1], the output value of a given color will be linearly interpolated between y1[i] and y0[i+1]: row i:   x  y0  y1
               /
              /
row i+1: x  y0  y1
 Hence y0 in the first row and y1 in the last row are never used.  See also
LinearSegmentedColormap.from_list

Static method; factory function for generating a smoothly-varying LinearSegmentedColormap.
makeMappingArray

For information about making a mapping array.

 FigureCanvas
class skimage.viewer.utils.FigureCanvas(figure, **kwargs) [source]

Bases: object Canvas for displaying images.
__init__(figure, **kwargs) [source]

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

resizeEvent(event) [source]

 LinearColormap
class skimage.viewer.utils.LinearColormap(name, segmented_data, **kwargs) [source]

Bases: matplotlib.colors.LinearSegmentedColormap LinearSegmentedColormap in which color varies smoothly. This class is a simplification of LinearSegmentedColormap, which doesn’t support jumps in color intensities.  Parameters

namestr

Name of colormap.
segmented_datadict

Dictionary of ‘red’, ‘green’, ‘blue’, and (optionally) ‘alpha’ values. Each color key contains a list of x, y tuples. x must increase monotonically from 0 to 1 and corresponds to input values for a mappable object (e.g. an image). y corresponds to the color intensity.
__init__(name, segmented_data, **kwargs) [source]

Create color map from linear mapping segments segmentdata argument is a dictionary with a red, green and blue entries. Each entry should be a list of x, y0, y1 tuples, forming rows in a table. Entries for alpha are optional. Example: suppose you want red to increase from 0 to 1 over the bottom half, green to do the same over the middle half, and blue over the top half. Then you would use: cdict = {'red':   [(0.0,  0.0, 0.0),
                   (0.5,  1.0, 1.0),
                   (1.0,  1.0, 1.0)],

         'green': [(0.0,  0.0, 0.0),
                   (0.25, 0.0, 0.0),
                   (0.75, 1.0, 1.0),
                   (1.0,  1.0, 1.0)],

         'blue':  [(0.0,  0.0, 0.0),
                   (0.5,  0.0, 0.0),
                   (1.0,  1.0, 1.0)]}
 Each row in the table for a given color is a sequence of x, y0, y1 tuples. In each sequence, x must increase monotonically from 0 to 1. For any input value z falling between x[i] and x[i+1], the output value of a given color will be linearly interpolated between y1[i] and y0[i+1]: row i:   x  y0  y1
               /
              /
row i+1: x  y0  y1
 Hence y0 in the first row and y1 in the last row are never used.  See also
LinearSegmentedColormap.from_list

Static method; factory function for generating a smoothly-varying LinearSegmentedColormap.
makeMappingArray

For information about making a mapping array.

 RequiredAttr
class skimage.viewer.utils.RequiredAttr(init_val=None) [source]

Bases: object A class attribute that must be set before use.
__init__(init_val=None) [source]

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

instances = {(<skimage.viewer.utils.core.RequiredAttr object>, None): 'Widget is not attached to a Plugin.', (<skimage.viewer.utils.core.RequiredAttr object>, None): 'Plugin is not attached to ImageViewer'}


class skimage.viewer.utils.ClearColormap(rgb, max_alpha=1, name='clear_color') [source]

Bases: skimage.viewer.utils.core.LinearColormap Color map that varies linearly from alpha = 0 to 1
__init__(rgb, max_alpha=1, name='clear_color') [source]

Create color map from linear mapping segments segmentdata argument is a dictionary with a red, green and blue entries. Each entry should be a list of x, y0, y1 tuples, forming rows in a table. Entries for alpha are optional. Example: suppose you want red to increase from 0 to 1 over the bottom half, green to do the same over the middle half, and blue over the top half. Then you would use: cdict = {'red':   [(0.0,  0.0, 0.0),
                   (0.5,  1.0, 1.0),
                   (1.0,  1.0, 1.0)],

         'green': [(0.0,  0.0, 0.0),
                   (0.25, 0.0, 0.0),
                   (0.75, 1.0, 1.0),
                   (1.0,  1.0, 1.0)],

         'blue':  [(0.0,  0.0, 0.0),
                   (0.5,  0.0, 0.0),
                   (1.0,  1.0, 1.0)]}
 Each row in the table for a given color is a sequence of x, y0, y1 tuples. In each sequence, x must increase monotonically from 0 to 1. For any input value z falling between x[i] and x[i+1], the output value of a given color will be linearly interpolated between y1[i] and y0[i+1]: row i:   x  y0  y1
               /
              /
row i+1: x  y0  y1
 Hence y0 in the first row and y1 in the last row are never used.  See also
LinearSegmentedColormap.from_list

Static method; factory function for generating a smoothly-varying LinearSegmentedColormap.
makeMappingArray

For information about making a mapping array.


__init__(rgb, max_alpha=1, name='clear_color') [source]

Create color map from linear mapping segments segmentdata argument is a dictionary with a red, green and blue entries. Each entry should be a list of x, y0, y1 tuples, forming rows in a table. Entries for alpha are optional. Example: suppose you want red to increase from 0 to 1 over the bottom half, green to do the same over the middle half, and blue over the top half. Then you would use: cdict = {'red':   [(0.0,  0.0, 0.0),
                   (0.5,  1.0, 1.0),
                   (1.0,  1.0, 1.0)],

         'green': [(0.0,  0.0, 0.0),
                   (0.25, 0.0, 0.0),
                   (0.75, 1.0, 1.0),
                   (1.0,  1.0, 1.0)],

         'blue':  [(0.0,  0.0, 0.0),
                   (0.5,  0.0, 0.0),
                   (1.0,  1.0, 1.0)]}
 Each row in the table for a given color is a sequence of x, y0, y1 tuples. In each sequence, x must increase monotonically from 0 to 1. For any input value z falling between x[i] and x[i+1], the output value of a given color will be linearly interpolated between y1[i] and y0[i+1]: row i:   x  y0  y1
               /
              /
row i+1: x  y0  y1
 Hence y0 in the first row and y1 in the last row are never used.  See also
LinearSegmentedColormap.from_list

Static method; factory function for generating a smoothly-varying LinearSegmentedColormap.
makeMappingArray

For information about making a mapping array.


skimage.viewer.utils.figimage(image, scale=1, dpi=None, **kwargs) [source]

Return figure and axes with figure tightly surrounding image. Unlike pyplot.figimage, this actually plots onto an axes object, which fills the figure. Plotting the image onto an axes allows for subsequent overlays of axes artists.  Parameters

imagearray

image to plot
scalefloat

If scale is 1, the figure and axes have the same dimension as the image. Smaller values of scale will shrink the figure.
dpiint

Dots per inch for figure. If None, use the default rcParam.


class skimage.viewer.utils.FigureCanvas(figure, **kwargs) [source]

Bases: object Canvas for displaying images.
__init__(figure, **kwargs) [source]

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

resizeEvent(event) [source]


__init__(figure, **kwargs) [source]

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


skimage.viewer.utils.init_qtapp() [source]

Initialize QAppliction. The QApplication needs to be initialized before creating any QWidgets


class skimage.viewer.utils.LinearColormap(name, segmented_data, **kwargs) [source]

Bases: matplotlib.colors.LinearSegmentedColormap LinearSegmentedColormap in which color varies smoothly. This class is a simplification of LinearSegmentedColormap, which doesn’t support jumps in color intensities.  Parameters

namestr

Name of colormap.
segmented_datadict

Dictionary of ‘red’, ‘green’, ‘blue’, and (optionally) ‘alpha’ values. Each color key contains a list of x, y tuples. x must increase monotonically from 0 to 1 and corresponds to input values for a mappable object (e.g. an image). y corresponds to the color intensity.
__init__(name, segmented_data, **kwargs) [source]

Create color map from linear mapping segments segmentdata argument is a dictionary with a red, green and blue entries. Each entry should be a list of x, y0, y1 tuples, forming rows in a table. Entries for alpha are optional. Example: suppose you want red to increase from 0 to 1 over the bottom half, green to do the same over the middle half, and blue over the top half. Then you would use: cdict = {'red':   [(0.0,  0.0, 0.0),
                   (0.5,  1.0, 1.0),
                   (1.0,  1.0, 1.0)],

         'green': [(0.0,  0.0, 0.0),
                   (0.25, 0.0, 0.0),
                   (0.75, 1.0, 1.0),
                   (1.0,  1.0, 1.0)],

         'blue':  [(0.0,  0.0, 0.0),
                   (0.5,  0.0, 0.0),
                   (1.0,  1.0, 1.0)]}
 Each row in the table for a given color is a sequence of x, y0, y1 tuples. In each sequence, x must increase monotonically from 0 to 1. For any input value z falling between x[i] and x[i+1], the output value of a given color will be linearly interpolated between y1[i] and y0[i+1]: row i:   x  y0  y1
               /
              /
row i+1: x  y0  y1
 Hence y0 in the first row and y1 in the last row are never used.  See also
LinearSegmentedColormap.from_list

Static method; factory function for generating a smoothly-varying LinearSegmentedColormap.
makeMappingArray

For information about making a mapping array.


__init__(name, segmented_data, **kwargs) [source]

Create color map from linear mapping segments segmentdata argument is a dictionary with a red, green and blue entries. Each entry should be a list of x, y0, y1 tuples, forming rows in a table. Entries for alpha are optional. Example: suppose you want red to increase from 0 to 1 over the bottom half, green to do the same over the middle half, and blue over the top half. Then you would use: cdict = {'red':   [(0.0,  0.0, 0.0),
                   (0.5,  1.0, 1.0),
                   (1.0,  1.0, 1.0)],

         'green': [(0.0,  0.0, 0.0),
                   (0.25, 0.0, 0.0),
                   (0.75, 1.0, 1.0),
                   (1.0,  1.0, 1.0)],

         'blue':  [(0.0,  0.0, 0.0),
                   (0.5,  0.0, 0.0),
                   (1.0,  1.0, 1.0)]}
 Each row in the table for a given color is a sequence of x, y0, y1 tuples. In each sequence, x must increase monotonically from 0 to 1. For any input value z falling between x[i] and x[i+1], the output value of a given color will be linearly interpolated between y1[i] and y0[i+1]: row i:   x  y0  y1
               /
              /
row i+1: x  y0  y1
 Hence y0 in the first row and y1 in the last row are never used.  See also
LinearSegmentedColormap.from_list

Static method; factory function for generating a smoothly-varying LinearSegmentedColormap.
makeMappingArray

For information about making a mapping array.


skimage.viewer.utils.new_plot(parent=None, subplot_kw=None, **fig_kw) [source]

Return new figure and axes.  Parameters

parentQtWidget

Qt widget that displays the plot objects. If None, you must manually call canvas.setParent and pass the parent widget.
subplot_kwdict

Keyword arguments passed matplotlib.figure.Figure.add_subplot.
fig_kwdict

Keyword arguments passed matplotlib.figure.Figure.