Wiener-Hunt deconvolution
Return the deconvolution with a Wiener-Hunt approach (i.e. with Fourier diagonalisation).
Input degraded image
Point Spread Function. This is assumed to be the impulse response (input image space) if the data-type is real, or the transfer function (Fourier space) if the data-type is complex. There is no constraints on the shape of the impulse response. The transfer function must be of shape (M, N) if is_real is True, (M, N // 2 + 1) otherwise (see np.fft.rfftn).
The regularisation parameter value that tunes the balance between the data adequacy that improve frequency restoration and the prior adequacy that reduce frequency restoration (to avoid noise artifacts).
The regularisation operator. The Laplacian by default. It can be an impulse response or a transfer function, as for the psf. Shape constraint is the same as for the psf parameter.
True by default. Specify if psf and reg are provided with hermitian hypothesis, that is only half of the frequency plane is provided (due to the redundancy of Fourier transform of real signal). It’s apply only if psf and/or reg are provided as transfer function. For the hermitian property see uft module or np.fft.rfftn.
True by default. If True, pixel values of the result above 1 or under -1 are thresholded for skimage pipeline compatibility.
The deconvolved image.
This function applies the Wiener filter to a noisy and degraded image by an impulse response (or PSF). If the data model is
where \(n\) is noise, \(H\) the PSF and \(x\) the unknown original image, the Wiener filter is
where \(F\) and \(F^\dagger\) are the Fourier and inverse Fourier transforms respectively, \(\Lambda_H\) the transfer function (or the Fourier transform of the PSF, see [Hunt] below) and \(\Lambda_D\) the filter to penalize the restored image frequencies (Laplacian by default, that is penalization of high frequency). The parameter \(\lambda\) tunes the balance between the data (that tends to increase high frequency, even those coming from noise), and the regularization.
These methods are then specific to a prior model. Consequently, the application or the true image nature must corresponds to the prior model. By default, the prior model (Laplacian) introduce image smoothness or pixel correlation. It can also be interpreted as high-frequency penalization to compensate the instability of the solution with respect to the data (sometimes called noise amplification or “explosive” solution).
Finally, the use of Fourier space implies a circulant property of \(H\), see [Hunt].
François Orieux, Jean-François Giovannelli, and Thomas Rodet, “Bayesian estimation of regularization and point spread function parameters for Wiener-Hunt deconvolution”, J. Opt. Soc. Am. A 27, 1593-1607 (2010)
https://www.osapublishing.org/josaa/abstract.cfm?URI=josaa-27-7-1593
http://research.orieux.fr/files/papers/OGR-JOSA10.pdf
B. R. Hunt “A matrix theory proof of the discrete convolution theorem”, IEEE Trans. on Audio and Electroacoustics, vol. au-19, no. 4, pp. 285-288, dec. 1971


skimage.segmentation.active_contour(image, snake)
Active contour model.
skimage.segmentation.chan_vese(image[, mu, …])
Chan-Vese segmentation algorithm.
skimage.segmentation.checkerboard_level_set(…)
Create a checkerboard level set with binary values.
skimage.segmentation.circle_level_set(…[, …])
Create a circle level set with binary values.
skimage.segmentation.clear_border(labels[, …])
Clear objects connected to the label image border.
skimage.segmentation.disk_level_set(…[, …])
Create a disk level set with binary values.
skimage.segmentation.expand_labels(label_image)
Expand labels in label image by distance pixels without overlapping.
skimage.segmentation.felzenszwalb(image[, …])
Computes Felsenszwalb’s efficient graph based image segmentation.
skimage.segmentation.find_boundaries(label_img)
Return bool array where boundaries between labeled regions are True.
skimage.segmentation.flood(image, seed_point, *)
Mask corresponding to a flood fill.
skimage.segmentation.flood_fill(image, …)
Perform flood filling on an image.
skimage.segmentation.inverse_gaussian_gradient(image)
Inverse of gradient magnitude.
skimage.segmentation.join_segmentations(s1, s2)
Return the join of the two input segmentations.
skimage.segmentation.mark_boundaries(image, …)
Return image with boundaries between labeled regions highlighted.
skimage.segmentation.morphological_chan_vese(…)
Morphological Active Contours without Edges (MorphACWE)
skimage.segmentation.morphological_geodesic_active_contour(…)
Morphological Geodesic Active Contours (MorphGAC).
skimage.segmentation.quickshift(image[, …])
Segments image using quickshift clustering in Color-(x,y) space.
skimage.segmentation.random_walker(data, labels)
Random walker algorithm for segmentation from markers.
skimage.segmentation.relabel_sequential(…)
Relabel arbitrary labels to {offset, …
skimage.segmentation.slic(image[, …])
Segments image using k-means clustering in Color-(x,y,z) space.
skimage.segmentation.watershed(image[, …])
Find watershed basins in image flooded from given markers.
Active contour model.
Active contours by fitting snakes to features of images. Supports single and multichannel 2D images. Snakes can be periodic (for segmentation) or have fixed and/or free ends. The output snake has the same length as the input boundary. As the number of points is constant, make sure that the initial snake has enough points to capture the details of the final contour.
Input image.
Initial snake coordinates. For periodic boundary conditions, endpoints must not be duplicated.
Snake length shape parameter. Higher values makes snake contract faster.
Snake smoothness shape parameter. Higher values makes snake smoother.
Controls attraction to brightness. Use negative values to attract toward dark regions.
Controls attraction to edges. Use negative values to repel snake from edges.
Explicit time stepping parameter.
Maximum pixel distance to move per iteration.
Maximum iterations to optimize snake shape.
Convergence criteria.
Boundary conditions for the contour. Can be one of ‘periodic’, ‘free’, ‘fixed’, ‘free-fixed’, or ‘fixed-free’. ‘periodic’ attaches the two ends of the snake, ‘fixed’ holds the end-points in place, and ‘free’ allows free movement of the ends. ‘fixed’ and ‘free’ can be combined by parsing ‘fixed-free’, ‘free-fixed’. Parsing ‘fixed-fixed’ or ‘free-free’ yields same behaviour as ‘fixed’ and ‘free’, respectively.
This option remains for compatibility purpose only and has no effect. It was introduced in 0.16 with the 'xy' option, but since 0.18, only the 'rc' option is valid. Coordinates must be set in a row-column format.
Optimised snake, same shape as input parameter.
Kass, M.; Witkin, A.; Terzopoulos, D. “Snakes: Active contour models”. International Journal of Computer Vision 1 (4): 321 (1988). DOI:10.1007/BF00133570
Create and smooth image:
Initialize spline:
Fit spline to image:
Chan-Vese segmentation algorithm.
Active contour model by evolving a level set. Can be used to segment objects without clearly defined boundaries.
Grayscale image to be segmented.
‘edge length’ weight parameter. Higher mu values will produce a ‘round’ edge, while values closer to zero will detect smaller objects.
‘difference from average’ weight parameter for the output region with value ‘True’. If it is lower than lambda2, this region will have a larger range of values than the other.
‘difference from average’ weight parameter for the output region with value ‘False’. If it is lower than lambda1, this region will have a larger range of values than the other.
Level set variation tolerance between iterations. If the L2 norm difference between the level sets of successive iterations normalized by the area of the image is below this value, the algorithm will assume that the solution was reached.
Maximum number of iterations allowed before the algorithm interrupts itself.
A multiplication factor applied at calculations for each step, serves to accelerate the algorithm. While higher values may speed up the algorithm, they may also lead to convergence problems.
Defines the starting level set used by the algorithm. If a string is inputted, a level set that matches the image size will automatically be generated. Alternatively, it is possible to define a custom level set, which should be an array of float values, with the same shape as ‘image’. Accepted string values are as follows.
the starting level set is defined as sin(x/5*pi)*sin(y/5*pi), where x and y are pixel coordinates. This level set has fast convergence, but may fail to detect implicit edges.
the starting level set is defined as the opposite of the distance from the center of the image minus half of the minimum value between image width and image height. This is somewhat slower, but is more likely to properly detect implicit edges.
the starting level set is defined as the opposite of the distance from the center of the image minus a quarter of the minimum value between image width and image height.
If set to True, the return value will be a tuple containing the three return values (see below). If set to False which is the default value, only the ‘segmentation’ array will be returned.
Segmentation produced by the algorithm.
Final level set computed by the algorithm.
Shows the evolution of the ‘energy’ for each step of the algorithm. This should allow to check whether the algorithm converged.
The Chan-Vese Algorithm is designed to segment objects without clearly defined boundaries. This algorithm is based on level sets that are evolved iteratively to minimize an energy, which is defined by weighted values corresponding to the sum of differences intensity from the average value outside the segmented region, the sum of differences from the average value inside the segmented region, and a term which is dependent on the length of the boundary of the segmented region.
This algorithm was first proposed by Tony Chan and Luminita Vese, in a publication entitled “An Active Contour Model Without Edges” [1].
This implementation of the algorithm is somewhat simplified in the sense that the area factor ‘nu’ described in the original paper is not implemented, and is only suitable for grayscale images.
Typical values for lambda1 and lambda2 are 1. If the ‘background’ is very different from the segmented object in terms of distribution (for example, a uniform black image with figures of varying intensity), then these values should be different from each other.
Typical values for mu are between 0 and 1, though higher values can be used when dealing with shapes with very ill-defined contours.
The ‘energy’ which this algorithm tries to minimize is defined as the sum of the differences from the average within the region squared and weighed by the ‘lambda’ factors to which is added the length of the contour multiplied by the ‘mu’ factor.
Supports 2D grayscale images only, and does not implement the area term described in the original article.
An Active Contour Model without Edges, Tony Chan and Luminita Vese, Scale-Space Theories in Computer Vision, 1999, DOI:10.1007/3-540-48236-9_13
Chan-Vese Segmentation, Pascal Getreuer Image Processing On Line, 2 (2012), pp. 214-224, DOI:10.5201/ipol.2012.g-cv
The Chan-Vese Algorithm - Project Report, Rami Cohen, 2011 arXiv:1107.2782
Create a checkerboard level set with binary values.
Shape of the image.
Size of the squares of the checkerboard. It defaults to 5.
Binary level set of the checkerboard.
See also
Create a circle level set with binary values.
Shape of the image
Coordinates of the center of the circle given in (row, column). If not given, it defaults to the center of the image.
Radius of the circle. If not given, it is set to the 75% of the smallest image dimension.
Binary level set of the circle with the given radius and center.
New in version 0.17: This function is deprecated and will be removed in scikit-image 0.19. Please use the function named disk_level_set instead.
See also
Clear objects connected to the label image border.
Imaging data labels.
The width of the border examined. By default, only objects that touch the outside of the image are removed.
Cleared objects are set to this value.
Whether or not to manipulate the labels array in-place.
Image data mask. Objects in labels image overlapping with False pixels of mask will be removed. If defined, the argument buffer_size will be ignored.
Imaging data labels with cleared borders
Create a disk level set with binary values.
Shape of the image
Coordinates of the center of the disk given in (row, column). If not given, it defaults to the center of the image.
Radius of the disk. If not given, it is set to the 75% of the smallest image dimension.
Binary level set of the disk with the given radius and center.
See also
Expand labels in label image by distance pixels without overlapping.
Given a label image, expand_labels grows label regions (connected components) outwards by up to distance pixels without overflowing into neighboring regions. More specifically, each background pixel that is within Euclidean distance of <= distance pixels of a connected component is assigned the label of that connected component. Where multiple connected components are within distance pixels of a background pixel, the label value of the closest connected component will be assigned (see Notes for the case of multiple labels at equal distance).
label image
Euclidean distance in pixels by which to grow the labels. Default is one.
Labeled array, where all connected regions have been enlarged
See also
Where labels are spaced more than distance pixels are apart, this is equivalent to a morphological dilation with a disc or hyperball of radius distance. However, in contrast to a morphological dilation, expand_labels will not expand a label region into a neighboring region.
This implementation of expand_labels is derived from CellProfiler [1], where it is known as module “IdentifySecondaryObjects (Distance-N)” [2].
There is an important edge case when a pixel has the same distance to multiple regions, as it is not defined which region expands into that space. Here, the exact behavior depends on the upstream implementation of scipy.ndimage.distance_transform_edt.
https://cellprofiler.org
https://github.com/CellProfiler/CellProfiler/blob/082930ea95add7b72243a4fa3d39ae5145995e9c/cellprofiler/modules/identifysecondaryobjects.py#L559
Labels will not overwrite each other:
In case of ties, behavior is undefined, but currently resolves to the label closest to (0,) * ndim in lexicographical order.
Computes Felsenszwalb’s efficient graph based image segmentation.
Produces an oversegmentation of a multichannel (i.e. RGB) image using a fast, minimum spanning tree based clustering on the image grid. The parameter scale sets an observation level. Higher scale means less and larger segments. sigma is the diameter of a Gaussian kernel, used for smoothing the image prior to segmentation.
The number of produced segments as well as their size can only be controlled indirectly through scale. Segment size within an image can vary greatly depending on local contrast.
For RGB images, the algorithm uses the euclidean distance between pixels in color space.
Input image.
Free parameter. Higher means larger clusters.
Width (standard deviation) of Gaussian kernel used in preprocessing.
Minimum component size. Enforced using postprocessing.
Whether the last axis of the image is to be interpreted as multiple channels. A value of False, for a 3D image, is not currently supported.
Integer mask indicating segment labels.
The k parameter used in the original paper renamed to scale here.
Efficient graph-based image segmentation, Felzenszwalb, P.F. and Huttenlocher, D.P. International Journal of Computer Vision, 2004
Return bool array where boundaries between labeled regions are True.
An array in which different regions are labeled with either different integers or boolean values.
A pixel is considered a boundary pixel if any of its neighbors has a different label. connectivity controls which pixels are considered neighbors. A connectivity of 1 (default) means pixels sharing an edge (in 2D) or a face (in 3D) will be considered neighbors. A connectivity of label_img.ndim means pixels sharing a corner will be considered neighbors.
How to mark the boundaries:
For modes ‘inner’ and ‘outer’, a definition of a background label is required. See mode for descriptions of these two.
A bool image where True represents a boundary pixel. For mode equal to ‘subpixel’, boundaries.shape[i] is equal to 2 * label_img.shape[i] - 1 for all i (a pixel is inserted in between all other pairs of pixels).
Mask corresponding to a flood fill.
Starting at a specific seed_point, connected points equal or within tolerance of the seed value are found.
An n-dimensional array.
The point in image used as the starting point for the flood fill. If the image is 1D, this point may be given as an integer.
A structuring element used to determine the neighborhood of each evaluated pixel. It must contain only 1’s and 0’s, have the same number of dimensions as image. If not given, all adjacent pixels are considered as part of the neighborhood (fully connected).
A number used to determine the neighborhood of each evaluated pixel. Adjacent pixels whose squared distance from the center is larger or equal to connectivity are considered neighbors. Ignored if selem is not None.
If None (default), adjacent values must be strictly equal to the initial value of image at seed_point. This is fastest. If a value is given, a comparison will be done at every point and if within tolerance of the initial value will also be filled (inclusive).
A Boolean array with the same shape as image is returned, with True values for areas connected to and equal (or within tolerance of) the seed point. All other values are False.
The conceptual analogy of this operation is the ‘paint bucket’ tool in many raster graphics programs. This function returns just the mask representing the fill.
If indices are desired rather than masks for memory reasons, the user can simply run numpy.nonzero on the result, save the indices, and discard this mask.
Fill connected ones with 5, with full connectivity (diagonals included):
Fill connected ones with 5, excluding diagonal points (connectivity 1):
Fill with a tolerance:
Flood Fill
Perform flood filling on an image.
Starting at a specific seed_point, connected points equal or within tolerance of the seed value are found, then set to new_value.
An n-dimensional array.
The point in image used as the starting point for the flood fill. If the image is 1D, this point may be given as an integer.
New value to set the entire fill. This must be chosen in agreement with the dtype of image.
A structuring element used to determine the neighborhood of each evaluated pixel. It must contain only 1’s and 0’s, have the same number of dimensions as image. If not given, all adjacent pixels are considered as part of the neighborhood (fully connected).
A number used to determine the neighborhood of each evaluated pixel. Adjacent pixels whose squared distance from the center is less than or equal to connectivity are considered neighbors. Ignored if selem is not None.
If None (default), adjacent values must be strictly equal to the value of image at seed_point to be filled. This is fastest. If a tolerance is provided, adjacent points with values within plus or minus tolerance from the seed point are filled (inclusive).
If True, flood filling is applied to image in place. If False, the flood filled result is returned without modifying the input image (default).
This parameter is deprecated and will be removed in version 0.19.0 in favor of in_place. If True, flood filling is applied to image inplace. If False, the flood filled result is returned without modifying the input image (default).
An array with the same shape as image is returned, with values in areas connected to and equal (or within tolerance of) the seed point replaced with new_value.
The conceptual analogy of this operation is the ‘paint bucket’ tool in many raster graphics programs.
Fill connected ones with 5, with full connectivity (diagonals included):
Fill connected ones with 5, excluding diagonal points (connectivity 1):
Fill with a tolerance:
Flood Fill
Inverse of gradient magnitude.
Compute the magnitude of the gradients in the image and then inverts the result in the range [0, 1]. Flat areas are assigned values close to 1, while areas close to borders are assigned values close to 0.
This function or a similar one defined by the user should be applied over the image as a preprocessing step before calling morphological_geodesic_active_contour.
Grayscale image or volume.
Controls the steepness of the inversion. A larger value will make the transition between the flat areas and border areas steeper in the resulting array.
Standard deviation of the Gaussian filter applied over the image.
Preprocessed image (or volume) suitable for morphological_geodesic_active_contour.
Return the join of the two input segmentations.
The join J of S1 and S2 is defined as the segmentation in which two voxels are in the same segment if and only if they are in the same segment in both S1 and S2.
s1 and s2 are label fields of the same shape.
The join segmentation of s1 and s2.
Return image with boundaries between labeled regions highlighted.
Grayscale or RGB image.
Label array where regions are marked by different integer values.
RGB color of boundaries in the output image.
RGB color surrounding boundaries in the output image. If None, no outline is drawn.
The mode for finding boundaries.
Which label to consider background (this is only useful for modes inner and outer).
An image in which the boundaries between labels are superimposed on the original image.
See also
Trainable segmentation using local features and random forests
Morphological Active Contours without Edges (MorphACWE)
Active contours without edges implemented with morphological operators. It can be used to segment objects in images and volumes without well defined borders. It is required that the inside of the object looks different on average than the outside (i.e., the inner area of the object should be darker or lighter than the outer area on average).
Grayscale image or volume to be segmented.
Number of iterations to run
Initial level set. If an array is given, it will be binarized and used as the initial level set. If a string is given, it defines the method to generate a reasonable initial level set with the shape of the image. Accepted values are ‘checkerboard’ and ‘circle’. See the documentation of checkerboard_level_set and circle_level_set respectively for details about how these level sets are created.
Number of times the smoothing operator is applied per iteration. Reasonable values are around 1-4. Larger values lead to smoother segmentations.
Weight parameter for the outer region. If lambda1 is larger than lambda2, the outer region will contain a larger range of values than the inner region.
Weight parameter for the inner region. If lambda2 is larger than lambda1, the inner region will contain a larger range of values than the outer region.
If given, this function is called once per iteration with the current level set as the only argument. This is useful for debugging or for plotting intermediate results during the evolution.
Final segmentation (i.e., the final level set)
See also
This is a version of the Chan-Vese algorithm that uses morphological operators instead of solving a partial differential equation (PDE) for the evolution of the contour. The set of morphological operators used in this algorithm are proved to be infinitesimally equivalent to the Chan-Vese PDE (see [1]). However, morphological operators are do not suffer from the numerical stability issues typically found in PDEs (it is not necessary to find the right time step for the evolution), and are computationally faster.
The algorithm and its theoretical derivation are described in [1].
A Morphological Approach to Curvature-based Evolution of Curves and Surfaces, Pablo Márquez-Neila, Luis Baumela, Luis Álvarez. In IEEE Transactions on Pattern Analysis and Machine Intelligence (PAMI), 2014, DOI:10.1109/TPAMI.2013.106
Morphological Geodesic Active Contours (MorphGAC).
Geodesic active contours implemented with morphological operators. It can be used to segment objects with visible but noisy, cluttered, broken borders.
Preprocessed image or volume to be segmented. This is very rarely the original image. Instead, this is usually a preprocessed version of the original image that enhances and highlights the borders (or other structures) of the object to segment. morphological_geodesic_active_contour will try to stop the contour evolution in areas where gimage is small. See morphsnakes.inverse_gaussian_gradient as an example function to perform this preprocessing. Note that the quality of morphological_geodesic_active_contour might greatly depend on this preprocessing.
Number of iterations to run.
Initial level set. If an array is given, it will be binarized and used as the initial level set. If a string is given, it defines the method to generate a reasonable initial level set with the shape of the image. Accepted values are ‘checkerboard’ and ‘circle’. See the documentation of checkerboard_level_set and circle_level_set respectively for details about how these level sets are created.
Number of times the smoothing operator is applied per iteration. Reasonable values are around 1-4. Larger values lead to smoother segmentations.
Areas of the image with a value smaller than this threshold will be considered borders. The evolution of the contour will stop in this areas.
Balloon force to guide the contour in non-informative areas of the image, i.e., areas where the gradient of the image is too small to push the contour towards a border. A negative value will shrink the contour, while a positive value will expand the contour in these areas. Setting this to zero will disable the balloon force.
If given, this function is called once per iteration with the current level set as the only argument. This is useful for debugging or for plotting intermediate results during the evolution.
Final segmentation (i.e., the final level set)
See also
This is a version of the Geodesic Active Contours (GAC) algorithm that uses morphological operators instead of solving partial differential equations (PDEs) for the evolution of the contour. The set of morphological operators used in this algorithm are proved to be infinitesimally equivalent to the GAC PDEs (see [1]). However, morphological operators are do not suffer from the numerical stability issues typically found in PDEs (e.g., it is not necessary to find the right time step for the evolution), and are computationally faster.
The algorithm and its theoretical derivation are described in [1].
A Morphological Approach to Curvature-based Evolution of Curves and Surfaces, Pablo Márquez-Neila, Luis Baumela, Luis Álvarez. In IEEE Transactions on Pattern Analysis and Machine Intelligence (PAMI), 2014, DOI:10.1109/TPAMI.2013.106
Segments image using quickshift clustering in Color-(x,y) space.
Produces an oversegmentation of the image using the quickshift mode-seeking algorithm.
Input image.
Balances color-space proximity and image-space proximity. Higher values give more weight to color-space.
Width of Gaussian kernel used in smoothing the sample density. Higher means fewer clusters.
Cut-off point for data distances. Higher means fewer clusters.
Whether to return the full segmentation hierarchy tree and distances.
Width for Gaussian smoothing as preprocessing. Zero means no smoothing.
Whether the input should be converted to Lab colorspace prior to segmentation. For this purpose, the input is assumed to be RGB.
Random seed used for breaking ties.
Integer mask indicating segment labels.
The authors advocate to convert the image to Lab color space prior to segmentation, though this is not strictly necessary. For this to work, the image must be given in RGB format.
Quick shift and kernel methods for mode seeking, Vedaldi, A. and Soatto, S. European Conference on Computer Vision, 2008
Random walker algorithm for segmentation from markers.
Random walker algorithm is implemented for gray-level or multichannel images.
Image to be segmented in phases. Gray-level data can be two- or three-dimensional; multichannel data can be three- or four- dimensional (multichannel=True) with the highest dimension denoting channels. Data spacing is assumed isotropic unless the spacing keyword argument is used.
Array of seed markers labeled with different positive integers for different phases. Zero-labeled pixels are unlabeled pixels. Negative labels correspond to inactive pixels that are not taken into account (they are removed from the graph). If labels are not consecutive integers, the labels array will be transformed so that labels are consecutive. In the multichannel case, labels should have the same shape as a single channel of data, i.e. without the final dimension denoting channels.
Penalization coefficient for the random walker motion (the greater beta, the more difficult the diffusion).
Mode for solving the linear system in the random walker algorithm.
Tolerance to achieve when solving the linear system using the conjugate gradient based modes (‘cg’, ‘cg_j’ and ‘cg_mg’).
If copy is False, the labels array will be overwritten with the result of the segmentation. Use copy=False if you want to save on memory.
If True, input data is parsed as multichannel data (see ‘data’ above for proper input format in this case).
If True, the probability that a pixel belongs to each of the labels will be returned, instead of only the most likely label.
Spacing between voxels in each spatial dimension. If None, then the spacing between pixels/voxels in each dimension is assumed 1.
Tolerance on the resulting probability to be in the interval [0, 1]. If the tolerance is not satisfied, a warning is displayed.
See also
watershed segmentation A segmentation algorithm based on mathematical morphology and “flooding” of regions from markers.
Multichannel inputs are scaled with all channel data combined. Ensure all channels are separately normalized prior to running this algorithm.
The spacing argument is specifically for anisotropic datasets, where data points are spaced differently in one or more spatial dimensions. Anisotropic data is commonly encountered in medical imaging.
The algorithm was first proposed in [1].
The algorithm solves the diffusion equation at infinite times for sources placed on markers of each phase in turn. A pixel is labeled with the phase that has the greatest probability to diffuse first to the pixel.
The diffusion equation is solved by minimizing x.T L x for each phase, where L is the Laplacian of the weighted graph of the image, and x is the probability that a marker of the given phase arrives first at a pixel by diffusion (x=1 on markers of the phase, x=0 on the other markers, and the other coefficients are looked for). Each pixel is attributed the label for which it has a maximal value of x. The Laplacian L of the image is defined as:
The weight w_ij is a decreasing function of the norm of the local gradient. This ensures that diffusion is easier between pixels of similar values.
When the Laplacian is decomposed into blocks of marked and unmarked pixels:
with first indices corresponding to marked pixels, and then to unmarked pixels, minimizing x.T L x for one phase amount to solving:
where x_m = 1 on markers of the given phase, and 0 on other markers. This linear system is solved in the algorithm using a direct method for small images, and an iterative method for larger images.
Leo Grady, Random walks for image segmentation, IEEE Trans Pattern Anal Mach Intell. 2006 Nov;28(11):1768-83. DOI:10.1109/TPAMI.2006.233.
Relabel arbitrary labels to {offset, … offset + number_of_labels}.
This function also returns the forward map (mapping the original labels to the reduced labels) and the inverse map (mapping the reduced labels back to the original ones).
An array of labels, which must be non-negative integers.
The return labels will start at offset, which should be strictly positive.
The input label field with labels mapped to {offset, …, number_of_labels + offset - 1}. The data type will be the same as label_field, except when offset + number_of_labels causes overflow of the current data type.
The map from the original label space to the returned label space. Can be used to re-apply the same mapping. See examples for usage. The output data type will be the same as relabeled.
The map from the new label space to the original space. This can be used to reconstruct the original label field from the relabeled one. The output data type will be the same as label_field.
The label 0 is assumed to denote the background and is never remapped.
The forward map can be extremely big for some inputs, since its length is given by the maximum of the label field. However, in most situations, label_field.max() is much smaller than label_field.size, and in these cases the forward map is guaranteed to be smaller than either the input or output images.
Segments image using k-means clustering in Color-(x,y,z) space.
Input image, which can be 2D or 3D, and grayscale or multichannel (see multichannel parameter). Input image must either be NaN-free or the NaN’s must be masked out
The (approximate) number of labels in the segmented output image.
Balances color proximity and space proximity. Higher values give more weight to space proximity, making superpixel shapes more square/cubic. In SLICO mode, this is the initial compactness. This parameter depends strongly on image contrast and on the shapes of objects in the image. We recommend exploring possible values on a log scale, e.g., 0.01, 0.1, 1, 10, 100, before refining around a chosen value.
Maximum number of iterations of k-means.
Width of Gaussian smoothing kernel for pre-processing for each dimension of the image. The same sigma is applied to each dimension in case of a scalar value. Zero means no smoothing. Note, that sigma is automatically scaled if it is scalar and a manual voxel spacing is provided (see Notes section).
The voxel spacing along each image dimension. By default, slic assumes uniform spacing (same voxel resolution along z, y and x). This parameter controls the weights of the distances along z, y, and x during k-means clustering.
Whether the last axis of the image is to be interpreted as multiple channels or another spatial dimension.
Whether the input should be converted to Lab colorspace prior to segmentation. The input image must be RGB. Highly recommended. This option defaults to True when multichannel=True and image.shape[-1] == 3.
Whether the generated segments are connected or not
Proportion of the minimum segment size to be removed with respect to the supposed segment size `depth*width*height/n_segments`
Proportion of the maximum connected segment size. A value of 3 works in most of the cases.
Run SLIC-zero, the zero-parameter mode of SLIC. [2]
The labels’ index start. Should be 0 or 1.
New in version 0.17: start_label was introduced in 0.17
If provided, superpixels are computed only where mask is True, and seed points are homogeneously distributed over the mask using a K-means clustering strategy.
New in version 0.17: mask was introduced in 0.17
Integer mask indicating segment labels.
If convert2lab is set to True but the last array dimension is not of length 3.
If start_label is not 0 or 1.
Radhakrishna Achanta, Appu Shaji, Kevin Smith, Aurelien Lucchi, Pascal Fua, and Sabine Süsstrunk, SLIC Superpixels Compared to State-of-the-art Superpixel Methods, TPAMI, May 2012. DOI:10.1109/TPAMI.2012.120
https://www.epfl.ch/labs/ivrl/research/slic-superpixels/#SLICO
Irving, Benjamin. “maskSLIC: regional superpixel generation with application to local pathology characterisation in medical images.”, 2016, arXiv:1606.09518
https://github.com/scikit-image/scikit-image/issues/3722
Increasing the compactness parameter yields more square regions:
Find watershed basins in image flooded from given markers.
Data array where the lowest value points are labeled first.
The desired number of markers, or an array marking the basins with the values to be assigned in the label matrix. Zero means not a marker. If None (no markers given), the local minima of the image are used as markers.
An array with the same number of dimensions as image whose non-zero elements indicate neighbors for connection. Following the scipy convention, default is a one-connected array of the dimension of the image.
offset of the connectivity (one offset per dimension)
Array of same shape as image. Only points at which mask == True will be labeled.
Use compact watershed [3] with given compactness parameter. Higher values result in more regularly-shaped watershed basins.
If watershed_line is True, a one-pixel wide line separates the regions obtained by the watershed algorithm. The line has the label 0.
A labeled matrix of the same type and shape as markers
See also
random walker segmentation A segmentation algorithm based on anisotropic diffusion, usually slower than the watershed but with good results on noisy data and boundaries with holes.
This function implements a watershed algorithm [1] [2] that apportions pixels into marked basins. The algorithm uses a priority queue to hold the pixels with the metric for the priority queue being pixel value, then the time of entry into the queue - this settles ties in favor of the closest marker.
Some ideas taken from Soille, “Automated Basin Delineation from Digital Elevation Models Using Mathematical Morphology”, Signal Processing 20 (1990) 171-182
The most important insight in the paper is that entry time onto the queue solves two problems: a pixel should be assigned to the neighbor with the largest gradient or, if there is no gradient, pixels on a plateau should be split between markers on opposite sides.
This implementation converts all arguments to specific, lowest common denominator types, then passes these to a C algorithm.
Markers can be determined manually, or automatically using for example the local minima of the gradient of the image, or the local maxima of the distance function to the background for separating overlapping objects (see example).
https://en.wikipedia.org/wiki/Watershed_%28image_processing%29
http://cmm.ensmp.fr/~beucher/wtshed.html
Peer Neubert & Peter Protzel (2014). Compact Watershed and Preemptive SLIC: On Improving Trade-offs of Superpixel Segmentation Algorithms. ICPR 2014, pp 996-1001. DOI:10.1109/ICPR.2014.181 https://www.tu-chemnitz.de/etit/proaut/publications/cws_pSLIC_ICPR.pdf
The watershed algorithm is useful to separate overlapping objects.
We first generate an initial image with two overlapping circles:
Next, we want to separate the two circles. We generate markers at the maxima of the distance to the background:
Finally, we run the watershed on the image and markers:
The algorithm works also for 3-D images, and can be used for example to separate overlapping spheres.
Watershed segmentation
Markers for watershed transform
Segment human cells (in mitosis)


Active contour model.
Active contours by fitting snakes to features of images. Supports single and multichannel 2D images. Snakes can be periodic (for segmentation) or have fixed and/or free ends. The output snake has the same length as the input boundary. As the number of points is constant, make sure that the initial snake has enough points to capture the details of the final contour.
Input image.
Initial snake coordinates. For periodic boundary conditions, endpoints must not be duplicated.
Snake length shape parameter. Higher values makes snake contract faster.
Snake smoothness shape parameter. Higher values makes snake smoother.
Controls attraction to brightness. Use negative values to attract toward dark regions.
Controls attraction to edges. Use negative values to repel snake from edges.
Explicit time stepping parameter.
Maximum pixel distance to move per iteration.
Maximum iterations to optimize snake shape.
Convergence criteria.
Boundary conditions for the contour. Can be one of ‘periodic’, ‘free’, ‘fixed’, ‘free-fixed’, or ‘fixed-free’. ‘periodic’ attaches the two ends of the snake, ‘fixed’ holds the end-points in place, and ‘free’ allows free movement of the ends. ‘fixed’ and ‘free’ can be combined by parsing ‘fixed-free’, ‘free-fixed’. Parsing ‘fixed-fixed’ or ‘free-free’ yields same behaviour as ‘fixed’ and ‘free’, respectively.
This option remains for compatibility purpose only and has no effect. It was introduced in 0.16 with the 'xy' option, but since 0.18, only the 'rc' option is valid. Coordinates must be set in a row-column format.
Optimised snake, same shape as input parameter.
Kass, M.; Witkin, A.; Terzopoulos, D. “Snakes: Active contour models”. International Journal of Computer Vision 1 (4): 321 (1988). DOI:10.1007/BF00133570
Create and smooth image:
Initialize spline:
Fit spline to image:


Chan-Vese segmentation algorithm.
Active contour model by evolving a level set. Can be used to segment objects without clearly defined boundaries.
Grayscale image to be segmented.
‘edge length’ weight parameter. Higher mu values will produce a ‘round’ edge, while values closer to zero will detect smaller objects.
‘difference from average’ weight parameter for the output region with value ‘True’. If it is lower than lambda2, this region will have a larger range of values than the other.
‘difference from average’ weight parameter for the output region with value ‘False’. If it is lower than lambda1, this region will have a larger range of values than the other.
Level set variation tolerance between iterations. If the L2 norm difference between the level sets of successive iterations normalized by the area of the image is below this value, the algorithm will assume that the solution was reached.
Maximum number of iterations allowed before the algorithm interrupts itself.
A multiplication factor applied at calculations for each step, serves to accelerate the algorithm. While higher values may speed up the algorithm, they may also lead to convergence problems.
Defines the starting level set used by the algorithm. If a string is inputted, a level set that matches the image size will automatically be generated. Alternatively, it is possible to define a custom level set, which should be an array of float values, with the same shape as ‘image’. Accepted string values are as follows.
the starting level set is defined as sin(x/5*pi)*sin(y/5*pi), where x and y are pixel coordinates. This level set has fast convergence, but may fail to detect implicit edges.
the starting level set is defined as the opposite of the distance from the center of the image minus half of the minimum value between image width and image height. This is somewhat slower, but is more likely to properly detect implicit edges.
the starting level set is defined as the opposite of the distance from the center of the image minus a quarter of the minimum value between image width and image height.
If set to True, the return value will be a tuple containing the three return values (see below). If set to False which is the default value, only the ‘segmentation’ array will be returned.
Segmentation produced by the algorithm.
Final level set computed by the algorithm.
Shows the evolution of the ‘energy’ for each step of the algorithm. This should allow to check whether the algorithm converged.
The Chan-Vese Algorithm is designed to segment objects without clearly defined boundaries. This algorithm is based on level sets that are evolved iteratively to minimize an energy, which is defined by weighted values corresponding to the sum of differences intensity from the average value outside the segmented region, the sum of differences from the average value inside the segmented region, and a term which is dependent on the length of the boundary of the segmented region.
This algorithm was first proposed by Tony Chan and Luminita Vese, in a publication entitled “An Active Contour Model Without Edges” [1].
This implementation of the algorithm is somewhat simplified in the sense that the area factor ‘nu’ described in the original paper is not implemented, and is only suitable for grayscale images.
Typical values for lambda1 and lambda2 are 1. If the ‘background’ is very different from the segmented object in terms of distribution (for example, a uniform black image with figures of varying intensity), then these values should be different from each other.
Typical values for mu are between 0 and 1, though higher values can be used when dealing with shapes with very ill-defined contours.
The ‘energy’ which this algorithm tries to minimize is defined as the sum of the differences from the average within the region squared and weighed by the ‘lambda’ factors to which is added the length of the contour multiplied by the ‘mu’ factor.
Supports 2D grayscale images only, and does not implement the area term described in the original article.
An Active Contour Model without Edges, Tony Chan and Luminita Vese, Scale-Space Theories in Computer Vision, 1999, DOI:10.1007/3-540-48236-9_13
Chan-Vese Segmentation, Pascal Getreuer Image Processing On Line, 2 (2012), pp. 214-224, DOI:10.5201/ipol.2012.g-cv
The Chan-Vese Algorithm - Project Report, Rami Cohen, 2011 arXiv:1107.2782


Create a checkerboard level set with binary values.
Shape of the image.
Size of the squares of the checkerboard. It defaults to 5.
Binary level set of the checkerboard.
See also


Create a circle level set with binary values.
Shape of the image
Coordinates of the center of the circle given in (row, column). If not given, it defaults to the center of the image.
Radius of the circle. If not given, it is set to the 75% of the smallest image dimension.
Binary level set of the circle with the given radius and center.
New in version 0.17: This function is deprecated and will be removed in scikit-image 0.19. Please use the function named disk_level_set instead.
See also


Clear objects connected to the label image border.
Imaging data labels.
The width of the border examined. By default, only objects that touch the outside of the image are removed.
Cleared objects are set to this value.
Whether or not to manipulate the labels array in-place.
Image data mask. Objects in labels image overlapping with False pixels of mask will be removed. If defined, the argument buffer_size will be ignored.
Imaging data labels with cleared borders


Create a disk level set with binary values.
Shape of the image
Coordinates of the center of the disk given in (row, column). If not given, it defaults to the center of the image.
Radius of the disk. If not given, it is set to the 75% of the smallest image dimension.
Binary level set of the disk with the given radius and center.
See also


Expand labels in label image by distance pixels without overlapping.
Given a label image, expand_labels grows label regions (connected components) outwards by up to distance pixels without overflowing into neighboring regions. More specifically, each background pixel that is within Euclidean distance of <= distance pixels of a connected component is assigned the label of that connected component. Where multiple connected components are within distance pixels of a background pixel, the label value of the closest connected component will be assigned (see Notes for the case of multiple labels at equal distance).
label image
Euclidean distance in pixels by which to grow the labels. Default is one.
Labeled array, where all connected regions have been enlarged
See also
Where labels are spaced more than distance pixels are apart, this is equivalent to a morphological dilation with a disc or hyperball of radius distance. However, in contrast to a morphological dilation, expand_labels will not expand a label region into a neighboring region.
This implementation of expand_labels is derived from CellProfiler [1], where it is known as module “IdentifySecondaryObjects (Distance-N)” [2].
There is an important edge case when a pixel has the same distance to multiple regions, as it is not defined which region expands into that space. Here, the exact behavior depends on the upstream implementation of scipy.ndimage.distance_transform_edt.
https://cellprofiler.org
https://github.com/CellProfiler/CellProfiler/blob/082930ea95add7b72243a4fa3d39ae5145995e9c/cellprofiler/modules/identifysecondaryobjects.py#L559
Labels will not overwrite each other:
In case of ties, behavior is undefined, but currently resolves to the label closest to (0,) * ndim in lexicographical order.


Computes Felsenszwalb’s efficient graph based image segmentation.
Produces an oversegmentation of a multichannel (i.e. RGB) image using a fast, minimum spanning tree based clustering on the image grid. The parameter scale sets an observation level. Higher scale means less and larger segments. sigma is the diameter of a Gaussian kernel, used for smoothing the image prior to segmentation.
The number of produced segments as well as their size can only be controlled indirectly through scale. Segment size within an image can vary greatly depending on local contrast.
For RGB images, the algorithm uses the euclidean distance between pixels in color space.
Input image.
Free parameter. Higher means larger clusters.
Width (standard deviation) of Gaussian kernel used in preprocessing.
Minimum component size. Enforced using postprocessing.
Whether the last axis of the image is to be interpreted as multiple channels. A value of False, for a 3D image, is not currently supported.
Integer mask indicating segment labels.
The k parameter used in the original paper renamed to scale here.
Efficient graph-based image segmentation, Felzenszwalb, P.F. and Huttenlocher, D.P. International Journal of Computer Vision, 2004


Return bool array where boundaries between labeled regions are True.
An array in which different regions are labeled with either different integers or boolean values.
A pixel is considered a boundary pixel if any of its neighbors has a different label. connectivity controls which pixels are considered neighbors. A connectivity of 1 (default) means pixels sharing an edge (in 2D) or a face (in 3D) will be considered neighbors. A connectivity of label_img.ndim means pixels sharing a corner will be considered neighbors.
How to mark the boundaries:
For modes ‘inner’ and ‘outer’, a definition of a background label is required. See mode for descriptions of these two.
A bool image where True represents a boundary pixel. For mode equal to ‘subpixel’, boundaries.shape[i] is equal to 2 * label_img.shape[i] - 1 for all i (a pixel is inserted in between all other pairs of pixels).


Mask corresponding to a flood fill.
Starting at a specific seed_point, connected points equal or within tolerance of the seed value are found.
An n-dimensional array.
The point in image used as the starting point for the flood fill. If the image is 1D, this point may be given as an integer.
A structuring element used to determine the neighborhood of each evaluated pixel. It must contain only 1’s and 0’s, have the same number of dimensions as image. If not given, all adjacent pixels are considered as part of the neighborhood (fully connected).
A number used to determine the neighborhood of each evaluated pixel. Adjacent pixels whose squared distance from the center is larger or equal to connectivity are considered neighbors. Ignored if selem is not None.
If None (default), adjacent values must be strictly equal to the initial value of image at seed_point. This is fastest. If a value is given, a comparison will be done at every point and if within tolerance of the initial value will also be filled (inclusive).
A Boolean array with the same shape as image is returned, with True values for areas connected to and equal (or within tolerance of) the seed point. All other values are False.
The conceptual analogy of this operation is the ‘paint bucket’ tool in many raster graphics programs. This function returns just the mask representing the fill.
If indices are desired rather than masks for memory reasons, the user can simply run numpy.nonzero on the result, save the indices, and discard this mask.
Fill connected ones with 5, with full connectivity (diagonals included):
Fill connected ones with 5, excluding diagonal points (connectivity 1):
Fill with a tolerance:


Perform flood filling on an image.
Starting at a specific seed_point, connected points equal or within tolerance of the seed value are found, then set to new_value.
An n-dimensional array.
The point in image used as the starting point for the flood fill. If the image is 1D, this point may be given as an integer.
New value to set the entire fill. This must be chosen in agreement with the dtype of image.
A structuring element used to determine the neighborhood of each evaluated pixel. It must contain only 1’s and 0’s, have the same number of dimensions as image. If not given, all adjacent pixels are considered as part of the neighborhood (fully connected).
A number used to determine the neighborhood of each evaluated pixel. Adjacent pixels whose squared distance from the center is less than or equal to connectivity are considered neighbors. Ignored if selem is not None.
If None (default), adjacent values must be strictly equal to the value of image at seed_point to be filled. This is fastest. If a tolerance is provided, adjacent points with values within plus or minus tolerance from the seed point are filled (inclusive).
If True, flood filling is applied to image in place. If False, the flood filled result is returned without modifying the input image (default).
This parameter is deprecated and will be removed in version 0.19.0 in favor of in_place. If True, flood filling is applied to image inplace. If False, the flood filled result is returned without modifying the input image (default).
An array with the same shape as image is returned, with values in areas connected to and equal (or within tolerance of) the seed point replaced with new_value.
The conceptual analogy of this operation is the ‘paint bucket’ tool in many raster graphics programs.
Fill connected ones with 5, with full connectivity (diagonals included):
Fill connected ones with 5, excluding diagonal points (connectivity 1):
Fill with a tolerance:


Inverse of gradient magnitude.
Compute the magnitude of the gradients in the image and then inverts the result in the range [0, 1]. Flat areas are assigned values close to 1, while areas close to borders are assigned values close to 0.
This function or a similar one defined by the user should be applied over the image as a preprocessing step before calling morphological_geodesic_active_contour.
Grayscale image or volume.
Controls the steepness of the inversion. A larger value will make the transition between the flat areas and border areas steeper in the resulting array.
Standard deviation of the Gaussian filter applied over the image.
Preprocessed image (or volume) suitable for morphological_geodesic_active_contour.


Return the join of the two input segmentations.
The join J of S1 and S2 is defined as the segmentation in which two voxels are in the same segment if and only if they are in the same segment in both S1 and S2.
s1 and s2 are label fields of the same shape.
The join segmentation of s1 and s2.


Return image with boundaries between labeled regions highlighted.
Grayscale or RGB image.
Label array where regions are marked by different integer values.
RGB color of boundaries in the output image.
RGB color surrounding boundaries in the output image. If None, no outline is drawn.
The mode for finding boundaries.
Which label to consider background (this is only useful for modes inner and outer).
An image in which the boundaries between labels are superimposed on the original image.
See also


Morphological Active Contours without Edges (MorphACWE)
Active contours without edges implemented with morphological operators. It can be used to segment objects in images and volumes without well defined borders. It is required that the inside of the object looks different on average than the outside (i.e., the inner area of the object should be darker or lighter than the outer area on average).
Grayscale image or volume to be segmented.
Number of iterations to run
Initial level set. If an array is given, it will be binarized and used as the initial level set. If a string is given, it defines the method to generate a reasonable initial level set with the shape of the image. Accepted values are ‘checkerboard’ and ‘circle’. See the documentation of checkerboard_level_set and circle_level_set respectively for details about how these level sets are created.
Number of times the smoothing operator is applied per iteration. Reasonable values are around 1-4. Larger values lead to smoother segmentations.
Weight parameter for the outer region. If lambda1 is larger than lambda2, the outer region will contain a larger range of values than the inner region.
Weight parameter for the inner region. If lambda2 is larger than lambda1, the inner region will contain a larger range of values than the outer region.
If given, this function is called once per iteration with the current level set as the only argument. This is useful for debugging or for plotting intermediate results during the evolution.
Final segmentation (i.e., the final level set)
See also
This is a version of the Chan-Vese algorithm that uses morphological operators instead of solving a partial differential equation (PDE) for the evolution of the contour. The set of morphological operators used in this algorithm are proved to be infinitesimally equivalent to the Chan-Vese PDE (see [1]). However, morphological operators are do not suffer from the numerical stability issues typically found in PDEs (it is not necessary to find the right time step for the evolution), and are computationally faster.
The algorithm and its theoretical derivation are described in [1].
A Morphological Approach to Curvature-based Evolution of Curves and Surfaces, Pablo Márquez-Neila, Luis Baumela, Luis Álvarez. In IEEE Transactions on Pattern Analysis and Machine Intelligence (PAMI), 2014, DOI:10.1109/TPAMI.2013.106


Morphological Geodesic Active Contours (MorphGAC).
Geodesic active contours implemented with morphological operators. It can be used to segment objects with visible but noisy, cluttered, broken borders.
Preprocessed image or volume to be segmented. This is very rarely the original image. Instead, this is usually a preprocessed version of the original image that enhances and highlights the borders (or other structures) of the object to segment. morphological_geodesic_active_contour will try to stop the contour evolution in areas where gimage is small. See morphsnakes.inverse_gaussian_gradient as an example function to perform this preprocessing. Note that the quality of morphological_geodesic_active_contour might greatly depend on this preprocessing.
Number of iterations to run.
Initial level set. If an array is given, it will be binarized and used as the initial level set. If a string is given, it defines the method to generate a reasonable initial level set with the shape of the image. Accepted values are ‘checkerboard’ and ‘circle’. See the documentation of checkerboard_level_set and circle_level_set respectively for details about how these level sets are created.
Number of times the smoothing operator is applied per iteration. Reasonable values are around 1-4. Larger values lead to smoother segmentations.
Areas of the image with a value smaller than this threshold will be considered borders. The evolution of the contour will stop in this areas.
Balloon force to guide the contour in non-informative areas of the image, i.e., areas where the gradient of the image is too small to push the contour towards a border. A negative value will shrink the contour, while a positive value will expand the contour in these areas. Setting this to zero will disable the balloon force.
If given, this function is called once per iteration with the current level set as the only argument. This is useful for debugging or for plotting intermediate results during the evolution.
Final segmentation (i.e., the final level set)
See also
This is a version of the Geodesic Active Contours (GAC) algorithm that uses morphological operators instead of solving partial differential equations (PDEs) for the evolution of the contour. The set of morphological operators used in this algorithm are proved to be infinitesimally equivalent to the GAC PDEs (see [1]). However, morphological operators are do not suffer from the numerical stability issues typically found in PDEs (e.g., it is not necessary to find the right time step for the evolution), and are computationally faster.
The algorithm and its theoretical derivation are described in [1].
A Morphological Approach to Curvature-based Evolution of Curves and Surfaces, Pablo Márquez-Neila, Luis Baumela, Luis Álvarez. In IEEE Transactions on Pattern Analysis and Machine Intelligence (PAMI), 2014, DOI:10.1109/TPAMI.2013.106


Segments image using quickshift clustering in Color-(x,y) space.
Produces an oversegmentation of the image using the quickshift mode-seeking algorithm.
Input image.
Balances color-space proximity and image-space proximity. Higher values give more weight to color-space.
Width of Gaussian kernel used in smoothing the sample density. Higher means fewer clusters.
Cut-off point for data distances. Higher means fewer clusters.
Whether to return the full segmentation hierarchy tree and distances.
Width for Gaussian smoothing as preprocessing. Zero means no smoothing.
Whether the input should be converted to Lab colorspace prior to segmentation. For this purpose, the input is assumed to be RGB.
Random seed used for breaking ties.
Integer mask indicating segment labels.
The authors advocate to convert the image to Lab color space prior to segmentation, though this is not strictly necessary. For this to work, the image must be given in RGB format.
Quick shift and kernel methods for mode seeking, Vedaldi, A. and Soatto, S. European Conference on Computer Vision, 2008


Random walker algorithm for segmentation from markers.
Random walker algorithm is implemented for gray-level or multichannel images.
Image to be segmented in phases. Gray-level data can be two- or three-dimensional; multichannel data can be three- or four- dimensional (multichannel=True) with the highest dimension denoting channels. Data spacing is assumed isotropic unless the spacing keyword argument is used.
Array of seed markers labeled with different positive integers for different phases. Zero-labeled pixels are unlabeled pixels. Negative labels correspond to inactive pixels that are not taken into account (they are removed from the graph). If labels are not consecutive integers, the labels array will be transformed so that labels are consecutive. In the multichannel case, labels should have the same shape as a single channel of data, i.e. without the final dimension denoting channels.
Penalization coefficient for the random walker motion (the greater beta, the more difficult the diffusion).
Mode for solving the linear system in the random walker algorithm.
Tolerance to achieve when solving the linear system using the conjugate gradient based modes (‘cg’, ‘cg_j’ and ‘cg_mg’).
If copy is False, the labels array will be overwritten with the result of the segmentation. Use copy=False if you want to save on memory.
If True, input data is parsed as multichannel data (see ‘data’ above for proper input format in this case).
If True, the probability that a pixel belongs to each of the labels will be returned, instead of only the most likely label.
Spacing between voxels in each spatial dimension. If None, then the spacing between pixels/voxels in each dimension is assumed 1.
Tolerance on the resulting probability to be in the interval [0, 1]. If the tolerance is not satisfied, a warning is displayed.
See also
watershed segmentation A segmentation algorithm based on mathematical morphology and “flooding” of regions from markers.
Multichannel inputs are scaled with all channel data combined. Ensure all channels are separately normalized prior to running this algorithm.
The spacing argument is specifically for anisotropic datasets, where data points are spaced differently in one or more spatial dimensions. Anisotropic data is commonly encountered in medical imaging.
The algorithm was first proposed in [1].
The algorithm solves the diffusion equation at infinite times for sources placed on markers of each phase in turn. A pixel is labeled with the phase that has the greatest probability to diffuse first to the pixel.
The diffusion equation is solved by minimizing x.T L x for each phase, where L is the Laplacian of the weighted graph of the image, and x is the probability that a marker of the given phase arrives first at a pixel by diffusion (x=1 on markers of the phase, x=0 on the other markers, and the other coefficients are looked for). Each pixel is attributed the label for which it has a maximal value of x. The Laplacian L of the image is defined as:
The weight w_ij is a decreasing function of the norm of the local gradient. This ensures that diffusion is easier between pixels of similar values.
When the Laplacian is decomposed into blocks of marked and unmarked pixels:
with first indices corresponding to marked pixels, and then to unmarked pixels, minimizing x.T L x for one phase amount to solving:
where x_m = 1 on markers of the given phase, and 0 on other markers. This linear system is solved in the algorithm using a direct method for small images, and an iterative method for larger images.
Leo Grady, Random walks for image segmentation, IEEE Trans Pattern Anal Mach Intell. 2006 Nov;28(11):1768-83. DOI:10.1109/TPAMI.2006.233.


Relabel arbitrary labels to {offset, … offset + number_of_labels}.
This function also returns the forward map (mapping the original labels to the reduced labels) and the inverse map (mapping the reduced labels back to the original ones).
An array of labels, which must be non-negative integers.
The return labels will start at offset, which should be strictly positive.
The input label field with labels mapped to {offset, …, number_of_labels + offset - 1}. The data type will be the same as label_field, except when offset + number_of_labels causes overflow of the current data type.
The map from the original label space to the returned label space. Can be used to re-apply the same mapping. See examples for usage. The output data type will be the same as relabeled.
The map from the new label space to the original space. This can be used to reconstruct the original label field from the relabeled one. The output data type will be the same as label_field.
The label 0 is assumed to denote the background and is never remapped.
The forward map can be extremely big for some inputs, since its length is given by the maximum of the label field. However, in most situations, label_field.max() is much smaller than label_field.size, and in these cases the forward map is guaranteed to be smaller than either the input or output images.


Segments image using k-means clustering in Color-(x,y,z) space.
Input image, which can be 2D or 3D, and grayscale or multichannel (see multichannel parameter). Input image must either be NaN-free or the NaN’s must be masked out
The (approximate) number of labels in the segmented output image.
Balances color proximity and space proximity. Higher values give more weight to space proximity, making superpixel shapes more square/cubic. In SLICO mode, this is the initial compactness. This parameter depends strongly on image contrast and on the shapes of objects in the image. We recommend exploring possible values on a log scale, e.g., 0.01, 0.1, 1, 10, 100, before refining around a chosen value.
Maximum number of iterations of k-means.
Width of Gaussian smoothing kernel for pre-processing for each dimension of the image. The same sigma is applied to each dimension in case of a scalar value. Zero means no smoothing. Note, that sigma is automatically scaled if it is scalar and a manual voxel spacing is provided (see Notes section).
The voxel spacing along each image dimension. By default, slic assumes uniform spacing (same voxel resolution along z, y and x). This parameter controls the weights of the distances along z, y, and x during k-means clustering.
Whether the last axis of the image is to be interpreted as multiple channels or another spatial dimension.
Whether the input should be converted to Lab colorspace prior to segmentation. The input image must be RGB. Highly recommended. This option defaults to True when multichannel=True and image.shape[-1] == 3.
Whether the generated segments are connected or not
Proportion of the minimum segment size to be removed with respect to the supposed segment size `depth*width*height/n_segments`
Proportion of the maximum connected segment size. A value of 3 works in most of the cases.
Run SLIC-zero, the zero-parameter mode of SLIC. [2]
The labels’ index start. Should be 0 or 1.
New in version 0.17: start_label was introduced in 0.17
If provided, superpixels are computed only where mask is True, and seed points are homogeneously distributed over the mask using a K-means clustering strategy.
New in version 0.17: mask was introduced in 0.17
Integer mask indicating segment labels.
If convert2lab is set to True but the last array dimension is not of length 3.
If start_label is not 0 or 1.
Radhakrishna Achanta, Appu Shaji, Kevin Smith, Aurelien Lucchi, Pascal Fua, and Sabine Süsstrunk, SLIC Superpixels Compared to State-of-the-art Superpixel Methods, TPAMI, May 2012. DOI:10.1109/TPAMI.2012.120
https://www.epfl.ch/labs/ivrl/research/slic-superpixels/#SLICO
Irving, Benjamin. “maskSLIC: regional superpixel generation with application to local pathology characterisation in medical images.”, 2016, arXiv:1606.09518
https://github.com/scikit-image/scikit-image/issues/3722
Increasing the compactness parameter yields more square regions:


Find watershed basins in image flooded from given markers.
Data array where the lowest value points are labeled first.
The desired number of markers, or an array marking the basins with the values to be assigned in the label matrix. Zero means not a marker. If None (no markers given), the local minima of the image are used as markers.
An array with the same number of dimensions as image whose non-zero elements indicate neighbors for connection. Following the scipy convention, default is a one-connected array of the dimension of the image.
offset of the connectivity (one offset per dimension)
Array of same shape as image. Only points at which mask == True will be labeled.
Use compact watershed [3] with given compactness parameter. Higher values result in more regularly-shaped watershed basins.
If watershed_line is True, a one-pixel wide line separates the regions obtained by the watershed algorithm. The line has the label 0.
A labeled matrix of the same type and shape as markers
See also
random walker segmentation A segmentation algorithm based on anisotropic diffusion, usually slower than the watershed but with good results on noisy data and boundaries with holes.
This function implements a watershed algorithm [1] [2] that apportions pixels into marked basins. The algorithm uses a priority queue to hold the pixels with the metric for the priority queue being pixel value, then the time of entry into the queue - this settles ties in favor of the closest marker.
Some ideas taken from Soille, “Automated Basin Delineation from Digital Elevation Models Using Mathematical Morphology”, Signal Processing 20 (1990) 171-182
The most important insight in the paper is that entry time onto the queue solves two problems: a pixel should be assigned to the neighbor with the largest gradient or, if there is no gradient, pixels on a plateau should be split between markers on opposite sides.
This implementation converts all arguments to specific, lowest common denominator types, then passes these to a C algorithm.
Markers can be determined manually, or automatically using for example the local minima of the gradient of the image, or the local maxima of the distance function to the background for separating overlapping objects (see example).
https://en.wikipedia.org/wiki/Watershed_%28image_processing%29
http://cmm.ensmp.fr/~beucher/wtshed.html
Peer Neubert & Peter Protzel (2014). Compact Watershed and Preemptive SLIC: On Improving Trade-offs of Superpixel Segmentation Algorithms. ICPR 2014, pp 996-1001. DOI:10.1109/ICPR.2014.181 https://www.tu-chemnitz.de/etit/proaut/publications/cws_pSLIC_ICPR.pdf
The watershed algorithm is useful to separate overlapping objects.
We first generate an initial image with two overlapping circles:
Next, we want to separate the two circles. We generate markers at the maxima of the distance to the background:
Finally, we run the watershed on the image and markers:
The algorithm works also for 3-D images, and can be used for example to separate overlapping spheres.


Image Processing for Python
scikit-image (a.k.a. skimage) is a collection of algorithms for image processing and computer vision.
The main package of skimage only provides a few utilities for converting between image data types; for most features, you need to import one of the following subpackages:
Color space conversion.
Test images and example data.
Drawing primitives (lines, text, etc.) that operate on NumPy arrays.
Image intensity adjustment, e.g., histogram equalization, etc.
Feature detection and extraction, e.g., texture analysis corners, etc.
Sharpening, edge finding, rank filters, thresholding, etc.
Graph-theoretic operations, e.g., shortest paths.
Reading, saving, and displaying images and video.
Measurement of image properties, e.g., region properties and contours.
Metrics corresponding to images, e.g. distance metrics, similarity, etc.
Morphological operations, e.g., opening or skeletonization.
Restoration algorithms, e.g., deconvolution algorithms, denoising, etc.
Partitioning an image into multiple regions.
Geometric and other transforms, e.g., rotation or the Radon transform.
Generic utilities.
A simple graphical user interface for visualizing results and exploring parameters.
Convert an image to floating point format, with values in [0, 1]. Is similar to img_as_float64, but will not convert lower-precision floating point arrays to float64.
Convert an image to single-precision (32-bit) floating point format, with values in [0, 1].
Convert an image to double-precision (64-bit) floating point format, with values in [0, 1].
Convert an image to unsigned integer format, with values in [0, 65535].
Convert an image to signed integer format, with values in [-32768, 32767].
Convert an image to unsigned byte format, with values in [0, 255].
Convert an image to boolean format, with values either True or False.
Return intensity limits, i.e. (min, max) tuple, of the image’s dtype.
skimage.dtype_limits(image[, clip_negative])
Return intensity limits, i.e.
skimage.ensure_python_version(min_version)
skimage.img_as_bool(image[, force_copy])
Convert an image to boolean format.
skimage.img_as_float(image[, force_copy])
Convert an image to floating point format.
skimage.img_as_float32(image[, force_copy])
Convert an image to single-precision (32-bit) floating point format.
skimage.img_as_float64(image[, force_copy])
Convert an image to double-precision (64-bit) floating point format.
skimage.img_as_int(image[, force_copy])
Convert an image to 16-bit signed integer format.
skimage.img_as_ubyte(image[, force_copy])
Convert an image to 8-bit unsigned integer format.
skimage.img_as_uint(image[, force_copy])
Convert an image to 16-bit unsigned integer format.
skimage.lookfor(what)
Do a keyword search on scikit-image docstrings.
skimage.data
Standard test images.
skimage.util
Return intensity limits, i.e. (min, max) tuple, of the image’s dtype.
Input image.
If True, clip the negative range (i.e. return 0 for min intensity) even if the image dtype allows negative values.
Lower and upper intensity limits.
Convert an image to boolean format.
Input image.
Force a copy of the data, irrespective of its current dtype.
Output image.
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.
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.
Input image.
Force a copy of the data, irrespective of its current dtype.
Output image.
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].
Tinting gray-scale images
3D adaptive histogram equalization
Phase Unwrapping
Finding local maxima
Use rolling-ball algorithm for estimating background intensity
Explore 3D images (of cells)
Convert an image to single-precision (32-bit) floating point format.
Input image.
Force a copy of the data, irrespective of its current dtype.
Output image.
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].
Convert an image to double-precision (64-bit) floating point format.
Input image.
Force a copy of the data, irrespective of its current dtype.
Output image.
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].
Convert an image to 16-bit signed integer format.
Input image.
Force a copy of the data, irrespective of its current dtype.
Output image.
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.
Convert an image to 8-bit unsigned integer format.
Input image.
Force a copy of the data, irrespective of its current dtype.
Output image.
Negative input values will be clipped. Positive values are scaled between 0 and 255.
Local Histogram Equalization
Entropy
Markers for watershed transform
Segment human cells (in mitosis)
Rank filters
Convert an image to 16-bit unsigned integer format.
Input image.
Force a copy of the data, irrespective of its current dtype.
Output image.
Negative input values will be clipped. Positive values are scaled between 0 and 65535.
Do a keyword search on scikit-image docstrings.
Words to look for.