Return the intensity profile of an image measured along a scan line.
The image, either grayscale (2D array) or multichannel (3D array, where the final axis contains the channel information).
The coordinates of the start point of the scan line.
The coordinates of the end point of the scan line. The destination point is included in the profile, in contrast to standard numpy indexing.
Width of the scan, perpendicular to the line
The order of the spline interpolation, default is 0 if image.dtype is bool and 1 otherwise. The order has to be in the range 0-5. See skimage.transform.warp for detail.
How to compute any values falling outside of the image.
If mode is ‘constant’, what constant value to use outside the image.
Function used to calculate the aggregation of pixel values perpendicular to the profile_line direction when linewidth > 1. If set to None the unreduced array will be returned.
The intensity profile along the scan line. The length of the profile is the ceil of the computed length of the scan line.
The destination point is included in the profile, in contrast to standard numpy indexing. For example:
For different reduce_func inputs:
The unreduced array will be returned when reduce_func is None or when reduce_func acts on each pixel value individually.


Fit a model to data with the RANSAC (random sample consensus) algorithm.
RANSAC is an iterative algorithm for the robust estimation of parameters from a subset of inliers from the complete data set. Each iteration performs the following tasks:
These steps are performed either a maximum number of times or until one of the special stop criteria are met. The final model is estimated using all inlier samples of the previously determined best model.
Data set to which the model is fitted, where N is the number of data points and the remaining dimension are depending on model requirements. If the model class requires multiple input data arrays (e.g. source and destination coordinates of skimage.transform.AffineTransform), they can be optionally passed as tuple or list. Note, that in this case the functions estimate(*data), residuals(*data), is_model_valid(model, *random_data) and is_data_valid(*random_data) must all take each data array as separate arguments.
Object with the following object methods:
where success indicates whether the model estimation succeeded (True or None for success, False for failure).
The minimum number of data points to fit a model to.
Maximum distance for a data point to be classified as an inlier.
This function is called with the randomly selected data before the model is fitted to it: is_data_valid(*random_data).
This function is called with the estimated model and the randomly selected data: is_model_valid(model, *random_data), .
Maximum number of iterations for random sample selection.
Stop iteration if at least this number of inliers are found.
Stop iteration if sum of residuals is less than or equal to this threshold.
RANSAC iteration stops if at least one outlier-free set of the training data is sampled with probability >= stop_probability, depending on the current best model’s inlier ratio and the number of trials. This requires to generate at least N samples (trials):
N >= log(1 - probability) / log(1 - e**m)
where the probability (confidence) is typically set to a high value such as 0.99, e is the current fraction of inliers w.r.t. the total number of samples, and m is the min_samples value.
If int, random_state is the seed used by the random number generator; If RandomState instance, random_state is the random number generator; If None, the random number generator is the RandomState instance used by np.random.
Initial samples selection for model estimation
Best model with largest consensus set.
Boolean mask of inliers classified as True.
“RANSAC”, Wikipedia, https://en.wikipedia.org/wiki/RANSAC
Generate ellipse data without tilt and add noise:
Add some faulty data:
Estimate ellipse model using all available data:
Estimate ellipse model using RANSAC:
RANSAC can be used to robustly estimate a geometric transformation. In this section, we also show how to use a proportion of the total samples, rather than an absolute number.


Measure properties of labeled image regions.
Labeled input image. Labels with value 0 are ignored.
Changed in version 0.14.1: Previously, label_image was processed by numpy.squeeze and so any number of singleton dimensions was allowed. This resulted in inconsistent handling of images with singleton dimensions. To recover the old behaviour, use regionprops(np.squeeze(label_image), ...).
Intensity (i.e., input) image with same size as labeled image, plus optionally an extra dimension for multichannel data. Default is None.
Changed in version 0.18.0: The ability to provide an extra dimension for channels was added.
Determine whether to cache calculated properties. The computation is much faster for cached properties, whereas the memory consumption increases.
This argument is deprecated and will be removed in a future version of scikit-image.
See Coordinate conventions for more details.
Deprecated since version 0.16.0: Use “rc” coordinates everywhere. It may be sufficient to call numpy.transpose on your label image to get the same values as 0.15 and earlier. However, for some properties, the transformation will be less trivial. For example, the new orientation is \(\frac{\pi}{2}\) plus the old orientation.
Add extra property computation functions that are not included with skimage. The name of the property is derived from the function name, the dtype is inferred by calling the function on a small sample. If the name of an extra property clashes with the name of an existing property the extra property wil not be visible and a UserWarning is issued. A property computation function must take a region mask as its first argument. If the property requires an intensity image, it must accept the intensity image as the second argument.
Each item describes one labeled region, and can be accessed using the attributes listed below.
See also
The following properties can be accessed as attributes or keys:
Number of pixels of the region.
Bounding box (min_row, min_col, max_row, max_col). Pixels belonging to the bounding box are in the half-open interval [min_row; max_row) and [min_col; max_col).
Number of pixels of bounding box.
Centroid coordinate tuple (row, col).
Number of pixels of convex hull image, which is the smallest convex polygon that encloses the region.
Binary convex hull image which has the same size as bounding box.
Coordinate list (row, col) of the region.
Eccentricity of the ellipse that has the same second-moments as the region. The eccentricity is the ratio of the focal distance (distance between focal points) over the major axis length. The value is in the interval [0, 1). When it is 0, the ellipse becomes a circle.
The diameter of a circle with the same area as the region.
Euler characteristic of the set of non-zero pixels. Computed as number of connected components subtracted by number of holes (input.ndim connectivity). In 3D, number of connected components plus number of holes subtracted by number of tunnels.
Ratio of pixels in the region to pixels in the total bounding box. Computed as area / (rows * cols)
Maximum Feret’s diameter computed as the longest distance between points around a region’s convex hull contour as determined by find_contours. [5]
Number of pixels of the region will all the holes filled in. Describes the area of the filled_image.
Binary region image with filled holes which has the same size as bounding box.
Sliced binary region image which has the same size as bounding box.
Inertia tensor of the region for the rotation around its mass.
The eigenvalues of the inertia tensor in decreasing order.
Image inside region bounding box.
The label in the labeled input image.
Centroid coordinate tuple (row, col), relative to region bounding box.
The length of the major axis of the ellipse that has the same normalized second central moments as the region.
Value with the greatest intensity in the region.
Value with the mean intensity in the region.
Value with the least intensity in the region.
The length of the minor axis of the ellipse that has the same normalized second central moments as the region.
Spatial moments up to 3rd order:
where the sum is over the row, col coordinates of the region.
Central moments (translation invariant) up to 3rd order:
where the sum is over the row, col coordinates of the region, and row_c and col_c are the coordinates of the region’s centroid.
Hu moments (translation, scale and rotation invariant).
Normalized moments (translation and scale invariant) up to 3rd order:
where m_00 is the zeroth spatial moment.
Angle between the 0th axis (rows) and the major axis of the ellipse that has the same second moments as the region, ranging from -pi/2 to pi/2 counter-clockwise.
Perimeter of object which approximates the contour as a line through the centers of border pixels using a 4-connectivity.
Perimeter of object approximated by the Crofton formula in 4 directions.
A slice to extract the object from the source image.
Ratio of pixels in the region to pixels of the convex hull image.
Centroid coordinate tuple (row, col) weighted with intensity image.
Centroid coordinate tuple (row, col), relative to region bounding box, weighted with intensity image.
Spatial moments of intensity image up to 3rd order:
where the sum is over the row, col coordinates of the region.
Central moments (translation invariant) of intensity image up to 3rd order:
where the sum is over the row, col coordinates of the region, and row_c and col_c are the coordinates of the region’s weighted centroid.
Hu moments (translation, scale and rotation invariant) of intensity image.
Normalized moments (translation and scale invariant) of intensity image up to 3rd order:
where wm_00 is the zeroth spatial moment (intensity-weighted area).
Each region also supports iteration, so that you can do:
Wilhelm Burger, Mark Burge. Principles of Digital Image Processing: Core Algorithms. Springer-Verlag, London, 2009.
B. Jähne. Digital Image Processing. Springer-Verlag, Berlin-Heidelberg, 6. edition, 2005.
T. H. Reiss. Recognizing Planar Objects Using Invariant Image Features, from Lecture notes in computer science, p. 676. Springer, Berlin, 1993.
https://en.wikipedia.org/wiki/Image_moment
W. Pabst, E. Gregorová. Characterization of particles and particle systems, pp. 27-28. ICT Prague, 2007. https://old.vscht.cz/sil/keramika/Characterization_of_particles/CPPS%20_English%20version_.pdf
Add custom measurements by passing functions as extra_properties


Compute image properties and return them as a pandas-compatible table.
The table is a dictionary mapping column names to value arrays. See Notes section below for details.
New in version 0.16.
Labeled input image. Labels with value 0 are ignored.
Intensity (i.e., input) image with same size as labeled image, plus optionally an extra dimension for multichannel data. Default is None.
Changed in version 0.18.0: The ability to provide an extra dimension for channels was added.
Properties that will be included in the resulting dictionary For a list of available properties, please see regionprops(). Users should remember to add “label” to keep track of region identities.
Determine whether to cache calculated properties. The computation is much faster for cached properties, whereas the memory consumption increases.
For non-scalar properties not listed in OBJECT_COLUMNS, each element will appear in its own column, with the index of that element separated from the property name by this separator. For example, the inertia tensor of a 2D region will appear in four columns: inertia_tensor-0-0, inertia_tensor-0-1, inertia_tensor-1-0, and inertia_tensor-1-1 (where the separator is -).
Object columns are those that cannot be split in this way because the number of columns would change depending on the object. For example, image and coords.
Add extra property computation functions that are not included with skimage. The name of the property is derived from the function name, the dtype is inferred by calling the function on a small sample. If the name of an extra property clashes with the name of an existing property the extra property wil not be visible and a UserWarning is issued. A property computation function must take a region mask as its first argument. If the property requires an intensity image, it must accept the intensity image as the second argument.
Dictionary mapping property names to an array of values of that property, one value per region. This dictionary can be used as input to pandas DataFrame to map property names to columns in the frame and regions to rows. If the image has no regions, the arrays will have length 0, but the correct type.
Each column contains either a scalar property, an object property, or an element in a multidimensional array.
Properties with scalar values for each region, such as “eccentricity”, will appear as a float or int array with that property name as key.
Multidimensional properties of fixed size for a given image dimension, such as “centroid” (every centroid will have three elements in a 3D image, no matter the region size), will be split into that many columns, with the name {property_name}{separator}{element_num} (for 1D properties), {property_name}{separator}{elem_num0}{separator}{elem_num1} (for 2D properties), and so on.
For multidimensional properties that don’t have a fixed size, such as “image” (the image of a region varies in size depending on the region size), an object array will be used, with the corresponding property name as the key.
The resulting dictionary can be directly passed to pandas, if installed, to obtain a clean DataFrame:
[5 rows x 7 columns]
If we want to measure a feature that does not come as a built-in property, we can define custom functions and pass them as extra_properties. For example, we can create a custom function that measures the intensity quartiles in a region:


Calculate the Shannon entropy of an image.
The Shannon entropy is defined as S = -sum(pk * log(pk)), where pk are frequency/probability of pixels of value k.
Grayscale input image.
The logarithmic base to use.
The returned value is measured in bits or shannon (Sh) for base=2, natural unit (nat) for base=np.e and hartley (Hart) for base=10.
https://en.wikipedia.org/wiki/Entropy_(information_theory)
https://en.wiktionary.org/wiki/Shannon_entropy


Subdivision of polygonal curves using B-Splines.
Note that the resulting curve is always within the convex hull of the original polygon. Circular polygons stay closed after subdivision.
Coordinate array.
Degree of B-Spline. Default is 2.
Preserve first and last coordinate of non-circular polygon. Default is False.
Subdivided coordinate array.
http://mrl.nyu.edu/publications/subdiv-course2000/coursenotes00.pdf


skimage.metrics.adapted_rand_error([…])
Compute Adapted Rand error as defined by the SNEMI3D contest.
skimage.metrics.contingency_table(im_true, …)
Return the contingency table for all regions in matched segmentations.
skimage.metrics.hausdorff_distance(image0, …)
Calculate the Hausdorff distance between nonzero elements of given images.
skimage.metrics.mean_squared_error(image0, …)
Compute the mean-squared error between two images.
skimage.metrics.normalized_root_mse(…[, …])
Compute the normalized root mean-squared error (NRMSE) between two images.
skimage.metrics.peak_signal_noise_ratio(…)
Compute the peak signal to noise ratio (PSNR) for an image.
skimage.metrics.structural_similarity(im1, …)
Compute the mean structural similarity index between two images.
skimage.metrics.variation_of_information([…])
Return symmetric conditional entropies associated with the VI.
Compute Adapted Rand error as defined by the SNEMI3D contest. [1]
Ground-truth label image, same shape as im_test.
Test image.
A contingency table built with skimage.evaluate.contingency_table. If None, it will be computed on the fly.
Labels to ignore. Any part of the true image labeled with any of these values will not be counted in the score.
The adapted Rand error; equal to \(1 - \frac{2pr}{p + r}\), where p and r are the precision and recall described below.
The adapted Rand precision: this is the number of pairs of pixels that have the same label in the test label image and in the true image, divided by the number in the test image.
The adapted Rand recall: this is the number of pairs of pixels that have the same label in the test label image and in the true image, divided by the number in the true image.
Pixels with label 0 in the true segmentation are ignored in the score.
Arganda-Carreras I, Turaga SC, Berger DR, et al. (2015) Crowdsourcing the creation of image segmentation algorithms for connectomics. Front. Neuroanat. 9:142. DOI:10.3389/fnana.2015.00142
Return the contingency table for all regions in matched segmentations.
Ground-truth label image, same shape as im_test.
Test image.
Labels to ignore. Any part of the true image labeled with any of these values will not be counted in the score.
Determines if the contingency table is normalized by pixel count.
A contingency table. cont[i, j] will equal the number of voxels labeled i in im_true and j in im_test.
Calculate the Hausdorff distance between nonzero elements of given images.
The Hausdorff distance [1] is the maximum distance between any point on image0 and its nearest point on image1, and vice-versa.
Arrays where True represents a point that is included in a set of points. Both arrays must have the same shape.
The Hausdorff distance between coordinates of nonzero pixels in image0 and image1, using the Euclidian distance.
http://en.wikipedia.org/wiki/Hausdorff_distance
Hausdorff Distance
Compute the mean-squared error between two images.
Images. Any dimensionality, must have same shape.
The mean-squared error (MSE) metric.
Changed in version 0.16: This function was renamed from skimage.measure.compare_mse to skimage.metrics.mean_squared_error.
Compute the normalized root mean-squared error (NRMSE) between two images.
Ground-truth image, same shape as im_test.
Test image.
Controls the normalization method to use in the denominator of the NRMSE. There is no standard method of normalization across the literature [1]. The methods available here are as follows:
‘euclidean’ : normalize by the averaged Euclidean norm of im_true:
where || . || denotes the Frobenius norm and N = im_true.size. This result is equivalent to:
The NRMSE metric.
Changed in version 0.16: This function was renamed from skimage.measure.compare_nrmse to skimage.metrics.normalized_root_mse.
https://en.wikipedia.org/wiki/Root-mean-square_deviation
Compute the peak signal to noise ratio (PSNR) for an image.
Ground-truth image, same shape as im_test.
Test image.
The data range of the input image (distance between minimum and maximum possible values). By default, this is estimated from the image data-type.
The PSNR metric.
Changed in version 0.16: This function was renamed from skimage.measure.compare_psnr to skimage.metrics.peak_signal_noise_ratio.
https://en.wikipedia.org/wiki/Peak_signal-to-noise_ratio
Compute the mean structural similarity index between two images.
Images. Any dimensionality with same shape.
The side-length of the sliding window used in comparison. Must be an odd value. If gaussian_weights is True, this is ignored and the window size will depend on sigma.
If True, also return the gradient with respect to im2.
The data range of the input image (distance between minimum and maximum possible values). By default, this is estimated from the image data-type.
If True, treat the last dimension of the array as channels. Similarity calculations are done independently for each channel then averaged.
If True, each patch has its mean and variance spatially weighted by a normalized Gaussian kernel of width sigma=1.5.
If True, also return the full structural similarity image.
The mean structural similarity index over the image.
The gradient of the structural similarity between im1 and im2 [2]. This is only returned if gradient is set to True.
The full SSIM image. This is only returned if full is set to True.
If True, normalize covariances by N-1 rather than, N where N is the number of pixels within the sliding window.
Algorithm parameter, K1 (small constant, see [1]).
Algorithm parameter, K2 (small constant, see [1]).
Standard deviation for the Gaussian when gaussian_weights is True.
To match the implementation of Wang et. al. [1], set gaussian_weights to True, sigma to 1.5, and use_sample_covariance to False.
Changed in version 0.16: This function was renamed from skimage.measure.compare_ssim to skimage.metrics.structural_similarity.
Wang, Z., Bovik, A. C., Sheikh, H. R., & Simoncelli, E. P. (2004). Image quality assessment: From error visibility to structural similarity. IEEE Transactions on Image Processing, 13, 600-612. https://ece.uwaterloo.ca/~z70wang/publications/ssim.pdf, DOI:10.1109/TIP.2003.819861
Avanaki, A. N. (2009). Exact global histogram specification optimized for structural similarity. Optical Review, 16, 613-621. arXiv:0901.0065 DOI:10.1007/s10043-009-0119-z
Return symmetric conditional entropies associated with the VI. [1]
The variation of information is defined as VI(X,Y) = H(X|Y) + H(Y|X). If X is the ground-truth segmentation, then H(X|Y) can be interpreted as the amount of under-segmentation and H(X|Y) as the amount of over-segmentation. In other words, a perfect over-segmentation will have H(X|Y)=0 and a perfect under-segmentation will have H(Y|X)=0.
Label images / segmentations, must have same shape.
A contingency table built with skimage.evaluate.contingency_table. If None, it will be computed with skimage.evaluate.contingency_table. If given, the entropies will be computed from this table and any images will be ignored.
Labels to ignore. Any part of the true image labeled with any of these values will not be counted in the score.
The conditional entropies of image1|image0 and image0|image1.
Marina Meilă (2007), Comparing clusterings—an information based distance, Journal of Multivariate Analysis, Volume 98, Issue 5, Pages 873-895, ISSN 0047-259X, DOI:10.1016/j.jmva.2006.11.013.


Compute Adapted Rand error as defined by the SNEMI3D contest. [1]
Ground-truth label image, same shape as im_test.
Test image.
A contingency table built with skimage.evaluate.contingency_table. If None, it will be computed on the fly.
Labels to ignore. Any part of the true image labeled with any of these values will not be counted in the score.
The adapted Rand error; equal to \(1 - \frac{2pr}{p + r}\), where p and r are the precision and recall described below.
The adapted Rand precision: this is the number of pairs of pixels that have the same label in the test label image and in the true image, divided by the number in the test image.
The adapted Rand recall: this is the number of pairs of pixels that have the same label in the test label image and in the true image, divided by the number in the true image.
Pixels with label 0 in the true segmentation are ignored in the score.
Arganda-Carreras I, Turaga SC, Berger DR, et al. (2015) Crowdsourcing the creation of image segmentation algorithms for connectomics. Front. Neuroanat. 9:142. DOI:10.3389/fnana.2015.00142


Return the contingency table for all regions in matched segmentations.
Ground-truth label image, same shape as im_test.
Test image.
Labels to ignore. Any part of the true image labeled with any of these values will not be counted in the score.
Determines if the contingency table is normalized by pixel count.
A contingency table. cont[i, j] will equal the number of voxels labeled i in im_true and j in im_test.


Calculate the Hausdorff distance between nonzero elements of given images.
The Hausdorff distance [1] is the maximum distance between any point on image0 and its nearest point on image1, and vice-versa.
Arrays where True represents a point that is included in a set of points. Both arrays must have the same shape.
The Hausdorff distance between coordinates of nonzero pixels in image0 and image1, using the Euclidian distance.
http://en.wikipedia.org/wiki/Hausdorff_distance


Compute the mean-squared error between two images.
Images. Any dimensionality, must have same shape.
The mean-squared error (MSE) metric.
Changed in version 0.16: This function was renamed from skimage.measure.compare_mse to skimage.metrics.mean_squared_error.


Compute the normalized root mean-squared error (NRMSE) between two images.
Ground-truth image, same shape as im_test.
Test image.
Controls the normalization method to use in the denominator of the NRMSE. There is no standard method of normalization across the literature [1]. The methods available here are as follows:
‘euclidean’ : normalize by the averaged Euclidean norm of im_true:
where || . || denotes the Frobenius norm and N = im_true.size. This result is equivalent to:
The NRMSE metric.
Changed in version 0.16: This function was renamed from skimage.measure.compare_nrmse to skimage.metrics.normalized_root_mse.
https://en.wikipedia.org/wiki/Root-mean-square_deviation


Compute the peak signal to noise ratio (PSNR) for an image.
Ground-truth image, same shape as im_test.
Test image.
The data range of the input image (distance between minimum and maximum possible values). By default, this is estimated from the image data-type.
The PSNR metric.
Changed in version 0.16: This function was renamed from skimage.measure.compare_psnr to skimage.metrics.peak_signal_noise_ratio.
https://en.wikipedia.org/wiki/Peak_signal-to-noise_ratio


Compute the mean structural similarity index between two images.
Images. Any dimensionality with same shape.
The side-length of the sliding window used in comparison. Must be an odd value. If gaussian_weights is True, this is ignored and the window size will depend on sigma.
If True, also return the gradient with respect to im2.
The data range of the input image (distance between minimum and maximum possible values). By default, this is estimated from the image data-type.
If True, treat the last dimension of the array as channels. Similarity calculations are done independently for each channel then averaged.
If True, each patch has its mean and variance spatially weighted by a normalized Gaussian kernel of width sigma=1.5.
If True, also return the full structural similarity image.
The mean structural similarity index over the image.
The gradient of the structural similarity between im1 and im2 [2]. This is only returned if gradient is set to True.
The full SSIM image. This is only returned if full is set to True.
If True, normalize covariances by N-1 rather than, N where N is the number of pixels within the sliding window.
Algorithm parameter, K1 (small constant, see [1]).
Algorithm parameter, K2 (small constant, see [1]).
Standard deviation for the Gaussian when gaussian_weights is True.
To match the implementation of Wang et. al. [1], set gaussian_weights to True, sigma to 1.5, and use_sample_covariance to False.
Changed in version 0.16: This function was renamed from skimage.measure.compare_ssim to skimage.metrics.structural_similarity.
Wang, Z., Bovik, A. C., Sheikh, H. R., & Simoncelli, E. P. (2004). Image quality assessment: From error visibility to structural similarity. IEEE Transactions on Image Processing, 13, 600-612. https://ece.uwaterloo.ca/~z70wang/publications/ssim.pdf, DOI:10.1109/TIP.2003.819861
Avanaki, A. N. (2009). Exact global histogram specification optimized for structural similarity. Optical Review, 16, 613-621. arXiv:0901.0065 DOI:10.1007/s10043-009-0119-z


Return symmetric conditional entropies associated with the VI. [1]
The variation of information is defined as VI(X,Y) = H(X|Y) + H(Y|X). If X is the ground-truth segmentation, then H(X|Y) can be interpreted as the amount of under-segmentation and H(X|Y) as the amount of over-segmentation. In other words, a perfect over-segmentation will have H(X|Y)=0 and a perfect under-segmentation will have H(Y|X)=0.
Label images / segmentations, must have same shape.
A contingency table built with skimage.evaluate.contingency_table. If None, it will be computed with skimage.evaluate.contingency_table. If given, the entropies will be computed from this table and any images will be ignored.
Labels to ignore. Any part of the true image labeled with any of these values will not be counted in the score.
The conditional entropies of image1|image0 and image0|image1.
Marina Meilă (2007), Comparing clusterings—an information based distance, Journal of Multivariate Analysis, Volume 98, Issue 5, Pages 873-895, ISSN 0047-259X, DOI:10.1016/j.jmva.2006.11.013.


skimage.morphology.area_closing(image[, …])
Perform an area closing of the image.
skimage.morphology.area_opening(image[, …])
Perform an area opening of the image.
skimage.morphology.ball(radius[, dtype])
Generates a ball-shaped structuring element.
skimage.morphology.binary_closing(image[, …])
Return fast binary morphological closing of an image.
skimage.morphology.binary_dilation(image[, …])
Return fast binary morphological dilation of an image.
skimage.morphology.binary_erosion(image[, …])
Return fast binary morphological erosion of an image.
skimage.morphology.binary_opening(image[, …])
Return fast binary morphological opening of an image.
skimage.morphology.black_tophat(image[, …])
Return black top hat of an image.
skimage.morphology.closing(image[, selem, out])
Return greyscale morphological closing of an image.
skimage.morphology.convex_hull_image(image)
Compute the convex hull image of a binary image.
skimage.morphology.convex_hull_object(image, *)
Compute the convex hull image of individual objects in a binary image.
skimage.morphology.cube(width[, dtype])
Generates a cube-shaped structuring element.
skimage.morphology.diameter_closing(image[, …])
Perform a diameter closing of the image.
skimage.morphology.diameter_opening(image[, …])
Perform a diameter opening of the image.
skimage.morphology.diamond(radius[, dtype])
Generates a flat, diamond-shaped structuring element.
skimage.morphology.dilation(image[, selem, …])
Return greyscale morphological dilation of an image.
skimage.morphology.disk(radius[, dtype])
Generates a flat, disk-shaped structuring element.
skimage.morphology.erosion(image[, selem, …])
Return greyscale morphological erosion of an image.
skimage.morphology.flood(image, seed_point, *)
Mask corresponding to a flood fill.
skimage.morphology.flood_fill(image, …[, …])
Perform flood filling on an image.
skimage.morphology.h_maxima(image, h[, selem])
Determine all maxima of the image with height >= h.
skimage.morphology.h_minima(image, h[, selem])
Determine all minima of the image with depth >= h.
skimage.morphology.label(input[, …])
Label connected regions of an integer array.
skimage.morphology.local_maxima(image[, …])
Find local maxima of n-dimensional array.
skimage.morphology.local_minima(image[, …])
Find local minima of n-dimensional array.
skimage.morphology.max_tree(image[, …])
Build the max tree from an image.
skimage.morphology.max_tree_local_maxima(image)
Determine all local maxima of the image.
skimage.morphology.medial_axis(image[, …])
Compute the medial axis transform of a binary image
skimage.morphology.octagon(m, n[, dtype])
Generates an octagon shaped structuring element.
skimage.morphology.octahedron(radius[, dtype])
Generates a octahedron-shaped structuring element.
skimage.morphology.opening(image[, selem, out])
Return greyscale morphological opening of an image.
skimage.morphology.reconstruction(seed, mask)
Perform a morphological reconstruction of an image.
skimage.morphology.rectangle(nrows, ncols[, …])
Generates a flat, rectangular-shaped structuring element.
skimage.morphology.remove_small_holes(ar[, …])
Remove contiguous holes smaller than the specified size.
skimage.morphology.remove_small_objects(ar)
Remove objects smaller than the specified size.
skimage.morphology.skeletonize(image, *[, …])
Compute the skeleton of a binary image.
skimage.morphology.skeletonize_3d(image)
Compute the skeleton of a binary image.
skimage.morphology.square(width[, dtype])
Generates a flat, square-shaped structuring element.
skimage.morphology.star(a[, dtype])
Generates a star shaped structuring element.
skimage.morphology.thin(image[, max_iter])
Perform morphological thinning of a binary image.
skimage.morphology.watershed(image[, …])
Deprecated function.
skimage.morphology.white_tophat(image[, …])
Return white top hat of an image.
Perform an area closing of the image.
Area closing removes all dark structures of an image with a surface smaller than area_threshold. The output image is larger than or equal to the input image for every pixel and all local minima have at least a surface of area_threshold pixels.
Area closings are similar to morphological closings, but they do not use a fixed structuring element, but rather a deformable one, with surface = area_threshold.
In the binary case, area closings are equivalent to remove_small_holes; this operator is thus extended to gray-level images.
Technically, this operator is based on the max-tree representation of the image.
The input image for which the area_closing is to be calculated. This image can be of any type.
The size parameter (number of pixels). The default value is arbitrarily chosen to be 64.
The neighborhood connectivity. The integer represents the maximum number of orthogonal steps to reach a neighbor. In 2D, it is 1 for a 4-neighborhood and 2 for a 8-neighborhood. Default value is 1.
Parent image representing the max tree of the inverted image. The value of each pixel is the index of its parent in the ravelled array. See Note for further details.
The ordered pixel indices (referring to the ravelled array). The pixels are ordered such that every pixel is preceded by its parent (except for the root which has no parent).
Output image of the same shape and type as input image.
See also
If a max-tree representation (parent and tree_traverser) are given to the function, they must be calculated from the inverted image for this function, i.e.: >>> P, S = max_tree(invert(f)) >>> closed = diameter_closing(f, 3, parent=P, tree_traverser=S)
Vincent L., Proc. “Grayscale area openings and closings, their efficient implementation and applications”, EURASIP Workshop on Mathematical Morphology and its Applications to Signal Processing, Barcelona, Spain, pp.22-27, May 1993.
Soille, P., “Morphological Image Analysis: Principles and Applications” (Chapter 6), 2nd edition (2003), ISBN 3540429883. DOI:10.1007/978-3-662-05088-0
Salembier, P., Oliveras, A., & Garrido, L. (1998). Antiextensive Connected Operators for Image and Sequence Processing. IEEE Transactions on Image Processing, 7(4), 555-570. DOI:10.1109/83.663500
Najman, L., & Couprie, M. (2006). Building the component tree in quasi-linear time. IEEE Transactions on Image Processing, 15(11), 3531-3539. DOI:10.1109/TIP.2006.877518
Carlinet, E., & Geraud, T. (2014). A Comparative Review of Component Tree Computation Algorithms. IEEE Transactions on Image Processing, 23(9), 3885-3895. DOI:10.1109/TIP.2014.2336551
We create an image (quadratic function with a minimum in the center and 4 additional local minima.
We can calculate the area closing:
All small minima are removed, and the remaining minima have at least a size of 8.
Perform an area opening of the image.
Area opening removes all bright structures of an image with a surface smaller than area_threshold. The output image is thus the largest image smaller than the input for which all local maxima have at least a surface of area_threshold pixels.
Area openings are similar to morphological openings, but they do not use a fixed structuring element, but rather a deformable one, with surface = area_threshold. Consequently, the area_opening with area_threshold=1 is the identity.
In the binary case, area openings are equivalent to remove_small_objects; this operator is thus extended to gray-level images.
Technically, this operator is based on the max-tree representation of the image.
The input image for which the area_opening is to be calculated. This image can be of any type.
The size parameter (number of pixels). The default value is arbitrarily chosen to be 64.
The neighborhood connectivity. The integer represents the maximum number of orthogonal steps to reach a neighbor. In 2D, it is 1 for a 4-neighborhood and 2 for a 8-neighborhood. Default value is 1.
Parent image representing the max tree of the image. The value of each pixel is the index of its parent in the ravelled array.
The ordered pixel indices (referring to the ravelled array). The pixels are ordered such that every pixel is preceded by its parent (except for the root which has no parent).
Output image of the same shape and type as the input image.
See also
Vincent L., Proc. “Grayscale area openings and closings, their efficient implementation and applications”, EURASIP Workshop on Mathematical Morphology and its Applications to Signal Processing, Barcelona, Spain, pp.22-27, May 1993.
Soille, P., “Morphological Image Analysis: Principles and Applications” (Chapter 6), 2nd edition (2003), ISBN 3540429883. :DOI:10.1007/978-3-662-05088-0
Salembier, P., Oliveras, A., & Garrido, L. (1998). Antiextensive Connected Operators for Image and Sequence Processing. IEEE Transactions on Image Processing, 7(4), 555-570. :DOI:10.1109/83.663500
Najman, L., & Couprie, M. (2006). Building the component tree in quasi-linear time. IEEE Transactions on Image Processing, 15(11), 3531-3539. :DOI:10.1109/TIP.2006.877518
Carlinet, E., & Geraud, T. (2014). A Comparative Review of Component Tree Computation Algorithms. IEEE Transactions on Image Processing, 23(9), 3885-3895. :DOI:10.1109/TIP.2014.2336551
We create an image (quadratic function with a maximum in the center and 4 additional local maxima.
We can calculate the area opening:
The peaks with a surface smaller than 8 are removed.
Generates a ball-shaped structuring element.
This is the 3D equivalent of a disk. A pixel is within the neighborhood if the Euclidean distance between it and the origin is no greater than radius.
The radius of the ball-shaped structuring element.
The structuring element where elements of the neighborhood are 1 and 0 otherwise.
The data type of the structuring element.
Local Histogram Equalization
Rank filters
Return fast binary morphological closing of an image.
This function returns the same result as greyscale closing but performs faster for binary images.
The morphological closing on an image is defined as a dilation followed by an erosion. Closing can remove small dark spots (i.e. “pepper”) and connect small bright cracks. This tends to “close” up (dark) gaps between (bright) features.
Binary input image.
The neighborhood expressed as a 2-D array of 1’s and 0’s. If None, use a cross-shaped structuring element (connectivity=1).
The array to store the result of the morphology. If None, is passed, a new array will be allocated.
The result of the morphological closing.
Flood Fill
Return fast binary morphological dilation of an image.
This function returns the same result as greyscale dilation but performs faster for binary images.
Morphological dilation sets a pixel at (i,j) to the maximum over all pixels in the neighborhood centered at (i,j). Dilation enlarges bright regions and shrinks dark regions.
Binary input image.
The neighborhood expressed as a 2-D array of 1’s and 0’s. If None, use a cross-shaped structuring element (connectivity=1).
The array to store the result of the morphology. If None is passed, a new array will be allocated.
The result of the morphological dilation with values in [False, True].
Return fast binary morphological erosion of an image.
This function returns the same result as greyscale erosion but performs faster for binary images.
Morphological erosion sets a pixel at (i,j) to the minimum over all pixels in the neighborhood centered at (i,j). Erosion shrinks bright regions and enlarges dark regions.
Binary input image.
The neighborhood expressed as a 2-D array of 1’s and 0’s. If None, use a cross-shaped structuring element (connectivity=1).
The array to store the result of the morphology. If None is passed, a new array will be allocated.
The result of the morphological erosion taking values in [False, True].
Return fast binary morphological opening of an image.
This function returns the same result as greyscale opening but performs faster for binary images.
The morphological opening on an image is defined as an erosion followed by a dilation. Opening can remove small bright spots (i.e. “salt”) and connect small dark cracks. This tends to “open” up (dark) gaps between (bright) features.
Binary input image.
The neighborhood expressed as a 2-D array of 1’s and 0’s. If None, use a cross-shaped structuring element (connectivity=1).
The array to store the result of the morphology. If None is passed, a new array will be allocated.
The result of the morphological opening.
Flood Fill
Return black top hat of an image.
The black top hat of an image is defined as its morphological closing minus the original image. This operation returns the dark spots of the image that are smaller than the structuring element. Note that dark spots in the original image are bright spots after the black top hat.
Image array.
The neighborhood expressed as a 2-D array of 1’s and 0’s. If None, use cross-shaped structuring element (connectivity=1).
The array to store the result of the morphology. If None is passed, a new array will be allocated.
The result of the morphological black top hat.
See also
https://en.wikipedia.org/wiki/Top-hat_transform
Return greyscale morphological closing of an image.
The morphological closing on an image is defined as a dilation followed by an erosion. Closing can remove small dark spots (i.e. “pepper”) and connect small bright cracks. This tends to “close” up (dark) gaps between (bright) features.
Image array.
The neighborhood expressed as an array of 1’s and 0’s. If None, use cross-shaped structuring element (connectivity=1).
The array to store the result of the morphology. If None, is passed, a new array will be allocated.
The result of the morphological closing.
Compute the convex hull image of a binary image.
The convex hull is the set of pixels included in the smallest convex polygon that surround all white pixels in the input image.
Binary input image. This array is cast to bool before processing.
If True, a pixel at coordinate, e.g., (4, 7) will be represented by coordinates (3.5, 7), (4.5, 7), (4, 6.5), and (4, 7.5). This adds some “extent” to a pixel when computing the hull.
Tolerance when determining whether a point is inside the hull. Due to numerical floating point errors, a tolerance of 0 can result in some points erroneously being classified as being outside the hull.
Binary image with pixels in convex hull set to True.
https://blogs.mathworks.com/steve/2011/10/04/binary-image-convex-hull-algorithm-notes/
Compute the convex hull image of individual objects in a binary image.
The convex hull is the set of pixels included in the smallest convex polygon that surround all white pixels in the input image.
Binary input image.
Determines the neighbors of each pixel. Adjacent elements within a squared distance of connectivity from pixel center are considered neighbors.:
Binary image with pixels inside convex hull set to True.
This function uses skimage.morphology.label to define unique objects, finds the convex hull of each using convex_hull_image, and combines these regions with logical OR. Be aware the convex hulls of unconnected objects may overlap in the result. If this is suspected, consider using convex_hull_image separately on each object or adjust connectivity.
Generates a cube-shaped structuring element.
This is the 3D equivalent of a square. Every pixel along the perimeter has a chessboard distance no greater than radius (radius=floor(width/2)) pixels.
The width, height and depth of the cube.
A structuring element consisting only of ones, i.e. every pixel belongs to the neighborhood.
The data type of the structuring element.
Perform a diameter closing of the image.
Diameter closing removes all dark structures of an image with maximal extension smaller than diameter_threshold. The maximal extension is defined as the maximal extension of the bounding box. The operator is also called Bounding Box Closing. In practice, the result is similar to a morphological closing, but long and thin structures are not removed.
Technically, this operator is based on the max-tree representation of the image.
The input image for which the diameter_closing is to be calculated. This image can be of any type.
The maximal extension parameter (number of pixels). The default value is 8.
The neighborhood connectivity. The integer represents the maximum number of orthogonal steps to reach a neighbor. In 2D, it is 1 for a 4-neighborhood and 2 for a 8-neighborhood. Default value is 1.
Precomputed parent image representing the max tree of the inverted image. This function is fast, if precomputed parent and tree_traverser are provided. See Note for further details.
Precomputed traverser, where the pixels are ordered such that every pixel is preceded by its parent (except for the root which has no parent). This function is fast, if precomputed parent and tree_traverser are provided. See Note for further details.
Output image of the same shape and type as input image.
See also
If a max-tree representation (parent and tree_traverser) are given to the function, they must be calculated from the inverted image for this function, i.e.: >>> P, S = max_tree(invert(f)) >>> closed = diameter_closing(f, 3, parent=P, tree_traverser=S)
Walter, T., & Klein, J.-C. (2002). Automatic Detection of Microaneurysms in Color Fundus Images of the Human Retina by Means of the Bounding Box Closing. In A. Colosimo, P. Sirabella, A. Giuliani (Eds.), Medical Data Analysis. Lecture Notes in Computer Science, vol 2526, pp. 210-220. Springer Berlin Heidelberg. DOI:10.1007/3-540-36104-9_23
Carlinet, E., & Geraud, T. (2014). A Comparative Review of Component Tree Computation Algorithms. IEEE Transactions on Image Processing, 23(9), 3885-3895. DOI:10.1109/TIP.2014.2336551
We create an image (quadratic function with a minimum in the center and 4 additional local minima.
We can calculate the diameter closing:
All small minima with a maximal extension of 2 or less are removed. The remaining minima have all a maximal extension of at least 3.
Perform a diameter opening of the image.
Diameter opening removes all bright structures of an image with maximal extension smaller than diameter_threshold. The maximal extension is defined as the maximal extension of the bounding box. The operator is also called Bounding Box Opening. In practice, the result is similar to a morphological opening, but long and thin structures are not removed.
Technically, this operator is based on the max-tree representation of the image.
The input image for which the area_opening is to be calculated. This image can be of any type.
The maximal extension parameter (number of pixels). The default value is 8.
The neighborhood connectivity. The integer represents the maximum number of orthogonal steps to reach a neighbor. In 2D, it is 1 for a 4-neighborhood and 2 for a 8-neighborhood. Default value is 1.
Parent image representing the max tree of the image. The value of each pixel is the index of its parent in the ravelled array.
The ordered pixel indices (referring to the ravelled array). The pixels are ordered such that every pixel is preceded by its parent (except for the root which has no parent).
Output image of the same shape and type as the input image.
See also
Walter, T., & Klein, J.-C. (2002). Automatic Detection of Microaneurysms in Color Fundus Images of the Human Retina by Means of the Bounding Box Closing. In A. Colosimo, P. Sirabella, A. Giuliani (Eds.), Medical Data Analysis. Lecture Notes in Computer Science, vol 2526, pp. 210-220. Springer Berlin Heidelberg. DOI:10.1007/3-540-36104-9_23
Carlinet, E., & Geraud, T. (2014). A Comparative Review of Component Tree Computation Algorithms. IEEE Transactions on Image Processing, 23(9), 3885-3895. DOI:10.1109/TIP.2014.2336551
We create an image (quadratic function with a maximum in the center and 4 additional local maxima.
We can calculate the diameter opening:
The peaks with a maximal extension of 2 or less are removed. The remaining peaks have all a maximal extension of at least 3.
Generates a flat, diamond-shaped structuring element.
A pixel is part of the neighborhood (i.e. labeled 1) if the city block/Manhattan distance between it and the center of the neighborhood is no greater than radius.
The radius of the diamond-shaped structuring element.
The structuring element where elements of the neighborhood are 1 and 0 otherwise.
The data type of the structuring element.
Return greyscale morphological dilation of an image.
Morphological dilation sets a pixel at (i,j) to the maximum over all pixels in the neighborhood centered at (i,j). Dilation enlarges bright regions and shrinks dark regions.
Image array.
The neighborhood expressed as a 2-D array of 1’s and 0’s. If None, use cross-shaped structuring element (connectivity=1).
The array to store the result of the morphology. If None, is passed, a new array will be allocated.
shift structuring element about center point. This only affects eccentric structuring elements (i.e. selem with even numbered sides).
The result of the morphological dilation.
For uint8 (and uint16 up to a certain bit-depth) data, the lower algorithm complexity makes the skimage.filters.rank.maximum function more efficient for larger images and structuring elements.
Rank filters
Generates a flat, disk-shaped structuring element.
A pixel is within the neighborhood if the Euclidean distance between it and the origin is no greater than radius.
The radius of the disk-shaped structuring element.
The structuring element where elements of the neighborhood are 1 and 0 otherwise.
The data type of the structuring element.
Local Histogram Equalization
Entropy
Markers for watershed transform
Flood Fill
Segment human cells (in mitosis)
Rank filters
Return greyscale morphological erosion of an image.
Morphological erosion sets a pixel at (i,j) to the minimum over all pixels in the neighborhood centered at (i,j). Erosion shrinks bright regions and enlarges dark regions.
Image array.
The neighborhood expressed as an array of 1’s and 0’s. If None, use cross-shaped structuring element (connectivity=1).
The array to store the result of the morphology. If None is passed, a new array will be allocated.
shift structuring element about center point. This only affects eccentric structuring elements (i.e. selem with even numbered sides).
The result of the morphological erosion.
For uint8 (and uint16 up to a certain bit-depth) data, the lower algorithm complexity makes the skimage.filters.rank.minimum function more efficient for larger images and structuring elements.
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:
Determine all maxima of the image with height >= h.
The local maxima are defined as connected sets of pixels with equal grey level strictly greater than the grey level of all pixels in direct neighborhood of the set.
A local maximum M of height h is a local maximum for which there is at least one path joining M with an equal or higher local maximum on which the minimal value is f(M) - h (i.e. the values along the path are not decreasing by more than h with respect to the maximum’s value) and no path to an equal or higher local maximum for which the minimal value is greater.
The global maxima of the image are also found by this function.
The input image for which the maxima are to be calculated.
The minimal height of all extracted maxima.
The neighborhood expressed as an n-D array of 1’s and 0’s. Default is the ball of radius 1 according to the maximum norm (i.e. a 3x3 square for 2D images, a 3x3x3 cube for 3D images, etc.)
The local maxima of height >= h and the global maxima. The resulting image is a binary image, where pixels belonging to the determined maxima take value 1, the others take value 0.
See also
Soille, P., “Morphological Image Analysis: Principles and Applications” (Chapter 6), 2nd edition (2003), ISBN 3540429883.
We create an image (quadratic function with a maximum in the center and 4 additional constant maxima. The heights of the maxima are: 1, 21, 41, 61, 81
We can calculate all maxima with a height of at least 40:
The resulting image will contain 3 local maxima.
Determine all minima of the image with depth >= h.
The local minima are defined as connected sets of pixels with equal grey level strictly smaller than the grey levels of all pixels in direct neighborhood of the set.
A local minimum M of depth h is a local minimum for which there is at least one path joining M with an equal or lower local minimum on which the maximal value is f(M) + h (i.e. the values along the path are not increasing by more than h with respect to the minimum’s value) and no path to an equal or lower local minimum for which the maximal value is smaller.
The global minima of the image are also found by this function.
The input image for which the minima are to be calculated.
The minimal depth of all extracted minima.
The neighborhood expressed as an n-D array of 1’s and 0’s. Default is the ball of radius 1 according to the maximum norm (i.e. a 3x3 square for 2D images, a 3x3x3 cube for 3D images, etc.)
The local minima of depth >= h and the global minima. The resulting image is a binary image, where pixels belonging to the determined minima take value 1, the others take value 0.
See also
Soille, P., “Morphological Image Analysis: Principles and Applications” (Chapter 6), 2nd edition (2003), ISBN 3540429883.
We create an image (quadratic function with a minimum in the center and 4 additional constant maxima. The depth of the minima are: 1, 21, 41, 61, 81
We can calculate all minima with a depth of at least 40:
The resulting image will contain 3 local minima.
Label connected regions of an integer array.
Two pixels are connected when they are neighbors and have the same value. In 2D, they can be neighbors either in a 1- or 2-connected sense. The value refers to the maximum number of orthogonal hops to consider a pixel/voxel a neighbor:
Image to label.
Consider all pixels with this value as background pixels, and label them as 0. By default, 0-valued pixels are considered as background pixels.
Whether to return the number of assigned labels.
Maximum number of orthogonal hops to consider a pixel/voxel as a neighbor. Accepted values are ranging from 1 to input.ndim. If None, a full connectivity of input.ndim is used.
Labeled array, where all connected regions are assigned the same integer value.
Number of labels, which equals the maximum label index and is only returned if return_num is True.
See also
Christophe Fiorio and Jens Gustedt, “Two linear time Union-Find strategies for image processing”, Theoretical Computer Science 154 (1996), pp. 165-181.
Kensheng Wu, Ekow Otoo and Arie Shoshani, “Optimizing connected component labeling algorithms”, Paper LBNL-56864, 2005, Lawrence Berkeley National Laboratory (University of California), http://repositories.cdlib.org/lbnl/LBNL-56864
Find local maxima of n-dimensional array.
The local maxima are defined as connected sets of pixels with equal gray level (plateaus) strictly greater than the gray levels of all pixels in the neighborhood.
An n-dimensional array.
A structuring element used to determine the neighborhood of each evaluated pixel (True denotes a connected pixel). It must be a boolean array and have the same number of dimensions as image. If neither selem nor connectivity are given, all adjacent pixels are considered as part of the neighborhood.
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 True, the output will be a tuple of one-dimensional arrays representing the indices of local maxima in each dimension. If False, the output will be a boolean array with the same shape as image.
If true, plateaus that touch the image border are valid maxima.
If indices is false, a boolean array with the same shape as image is returned with True indicating the position of local maxima (False otherwise). If indices is true, a tuple of one-dimensional arrays containing the coordinates (indices) of all found maxima.
If allow_borders is false and any dimension of the given image is shorter than 3 samples, maxima can’t exist and a warning is shown.
See also
This function operates on the following ideas:
For each candidate:
Find local maxima by comparing to all neighboring pixels (maximal connectivity):
Find local maxima without comparing to diagonal pixels (connectivity 1):
and exclude maxima that border the image edge:
Find local minima of n-dimensional array.
The local minima are defined as connected sets of pixels with equal gray level (plateaus) strictly smaller than the gray levels of all pixels in the neighborhood.
An n-dimensional array.
A structuring element used to determine the neighborhood of each evaluated pixel (True denotes a connected pixel). It must be a boolean array and have the same number of dimensions as image. If neither selem nor connectivity are given, all adjacent pixels are considered as part of the neighborhood.
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 True, the output will be a tuple of one-dimensional arrays representing the indices of local minima in each dimension. If False, the output will be a boolean array with the same shape as image.
If true, plateaus that touch the image border are valid minima.
If indices is false, a boolean array with the same shape as image is returned with True indicating the position of local minima (False otherwise). If indices is true, a tuple of one-dimensional arrays containing the coordinates (indices) of all found minima.
See also
This function operates on the following ideas:
For each candidate:
Find local minima by comparing to all neighboring pixels (maximal connectivity):
Find local minima without comparing to diagonal pixels (connectivity 1):
and exclude minima that border the image edge:
Build the max tree from an image.
Component trees represent the hierarchical structure of the connected components resulting from sequential thresholding operations applied to an image. A connected component at one level is parent of a component at a higher level if the latter is included in the first. A max-tree is an efficient representation of a component tree. A connected component at one level is represented by one reference pixel at this level, which is parent to all other pixels at that level and to the reference pixel at the level above. The max-tree is the basis for many morphological operators, namely connected operators.
The input image for which the max-tree is to be calculated. This image can be of any type.
The neighborhood connectivity. The integer represents the maximum number of orthogonal steps to reach a neighbor. In 2D, it is 1 for a 4-neighborhood and 2 for a 8-neighborhood. Default value is 1.
Array of same shape as image. The value of each pixel is the index of its parent in the ravelled array.
The ordered pixel indices (referring to the ravelled array). The pixels are ordered such that every pixel is preceded by its parent (except for the root which has no parent).
Salembier, P., Oliveras, A., & Garrido, L. (1998). Antiextensive Connected Operators for Image and Sequence Processing. IEEE Transactions on Image Processing, 7(4), 555-570. DOI:10.1109/83.663500
Berger, C., Geraud, T., Levillain, R., Widynski, N., Baillard, A., Bertin, E. (2007). Effective Component Tree Computation with Application to Pattern Recognition in Astronomical Imaging. In International Conference on Image Processing (ICIP) (pp. 41-44). DOI:10.1109/ICIP.2007.4379949
Najman, L., & Couprie, M. (2006). Building the component tree in quasi-linear time. IEEE Transactions on Image Processing, 15(11), 3531-3539. DOI:10.1109/TIP.2006.877518
Carlinet, E., & Geraud, T. (2014). A Comparative Review of Component Tree Computation Algorithms. IEEE Transactions on Image Processing, 23(9), 3885-3895. DOI:10.1109/TIP.2014.2336551
We create a small sample image (Figure 1 from [4]) and build the max-tree.
Determine all local maxima of the image.
The local maxima are defined as connected sets of pixels with equal gray level strictly greater than the gray levels of all pixels in direct neighborhood of the set. The function labels the local maxima.
Technically, the implementation is based on the max-tree representation of an image. The function is very efficient if the max-tree representation has already been computed. Otherwise, it is preferable to use the function local_maxima.
The input image for which the maxima are to be calculated.
The neighborhood connectivity. The integer represents the maximum number of orthogonal steps to reach a neighbor. In 2D, it is 1 for a 4-neighborhood and 2 for a 8-neighborhood. Default value is 1.
The value of each pixel is the index of its parent in the ravelled array.
The ordered pixel indices (referring to the ravelled array). The pixels are ordered such that every pixel is preceded by its parent (except for the root which has no parent).
Labeled local maxima of the image.
See also
Vincent L., Proc. “Grayscale area openings and closings, their efficient implementation and applications”, EURASIP Workshop on Mathematical Morphology and its Applications to Signal Processing, Barcelona, Spain, pp.22-27, May 1993.
Soille, P., “Morphological Image Analysis: Principles and Applications” (Chapter 6), 2nd edition (2003), ISBN 3540429883. DOI:10.1007/978-3-662-05088-0
Salembier, P., Oliveras, A., & Garrido, L. (1998). Antiextensive Connected Operators for Image and Sequence Processing. IEEE Transactions on Image Processing, 7(4), 555-570. DOI:10.1109/83.663500
Najman, L., & Couprie, M. (2006). Building the component tree in quasi-linear time. IEEE Transactions on Image Processing, 15(11), 3531-3539. DOI:10.1109/TIP.2006.877518
Carlinet, E., & Geraud, T. (2014). A Comparative Review of Component Tree Computation Algorithms. IEEE Transactions on Image Processing, 23(9), 3885-3895. DOI:10.1109/TIP.2014.2336551
We create an image (quadratic function with a maximum in the center and 4 additional constant maxima.
We can calculate all local maxima:
The resulting image contains the labeled local maxima.
Compute the medial axis transform of a binary image
The image of the shape to be skeletonized.
If a mask is given, only those elements in image with a true value in mask are used for computing the medial axis.
If true, the distance transform is returned as well as the skeleton.
Medial axis transform of the image
Distance transform of the image (only returned if return_distance is True)
See also
This algorithm computes the medial axis transform of an image as the ridges of its distance transform.
Generates an octagon shaped structuring element.
For a given size of (m) horizontal and vertical sides and a given (n) height or width of slanted sides octagon is generated. The slanted sides are 45 or 135 degrees to the horizontal axis and hence the widths and heights are equal.
The size of the horizontal and vertical sides.
The height or width of the slanted sides.
The structuring element where elements of the neighborhood are 1 and 0 otherwise.
The data type of the structuring element.
Generates a octahedron-shaped structuring element.
This is the 3D equivalent of a diamond. A pixel is part of the neighborhood (i.e. labeled 1) if the city block/Manhattan distance between it and the center of the neighborhood is no greater than radius.
The radius of the octahedron-shaped structuring element.
The structuring element where elements of the neighborhood are 1 and 0 otherwise.
The data type of the structuring element.
Return greyscale morphological opening of an image.
The morphological opening on an image is defined as an erosion followed by a dilation. Opening can remove small bright spots (i.e. “salt”) and connect small dark cracks. This tends to “open” up (dark) gaps between (bright) features.
Image array.
The neighborhood expressed as an array of 1’s and 0’s. If None, use cross-shaped structuring element (connectivity=1).
The array to store the result of the morphology. If None is passed, a new array will be allocated.
The result of the morphological opening.
Perform a morphological reconstruction of an image.
Morphological reconstruction by dilation is similar to basic morphological dilation: high-intensity values will replace nearby low-intensity values. The basic dilation operator, however, uses a structuring element to determine how far a value in the input image can spread. In contrast, reconstruction uses two images: a “seed” image, which specifies the values that spread, and a “mask” image, which gives the maximum allowed value at each pixel. The mask image, like the structuring element, limits the spread of high-intensity values. Reconstruction by erosion is simply the inverse: low-intensity values spread from the seed image and are limited by the mask image, which represents the minimum allowed value.
Alternatively, you can think of reconstruction as a way to isolate the connected regions of an image. For dilation, reconstruction connects regions marked by local maxima in the seed image: neighboring pixels less-than-or-equal-to those seeds are connected to the seeded region. Local maxima with values larger than the seed image will get truncated to the seed value.
The seed image (a.k.a. marker image), which specifies the values that are dilated or eroded.
The maximum (dilation) / minimum (erosion) allowed value at each pixel.
Perform reconstruction by dilation or erosion. In dilation (or erosion), the seed image is dilated (or eroded) until limited by the mask image. For dilation, each seed value must be less than or equal to the corresponding mask value; for erosion, the reverse is true. Default is ‘dilation’.
The neighborhood expressed as an n-D array of 1’s and 0’s. Default is the n-D square of radius equal to 1 (i.e. a 3x3 square for 2D images, a 3x3x3 cube for 3D images, etc.)
The coordinates of the center of the structuring element. Default is located on the geometrical center of the selem, in that case selem dimensions must be odd.
The result of morphological reconstruction.
The algorithm is taken from [1]. Applications for greyscale reconstruction are discussed in [2] and [3].
Robinson, “Efficient morphological reconstruction: a downhill filter”, Pattern Recognition Letters 25 (2004) 1759-1767.
Vincent, L., “Morphological Grayscale Reconstruction in Image Analysis: Applications and Efficient Algorithms”, IEEE Transactions on Image Processing (1993)
Soille, P., “Morphological Image Analysis: Principles and Applications”, Chapter 6, 2nd edition (2003), ISBN 3540429883.
First, we create a sinusoidal mask image with peaks at middle and ends.
Then, we create a seed image initialized to the minimum mask value (for reconstruction by dilation, min-intensity values don’t spread) and add “seeds” to the left and right peak, but at a fraction of peak value (1).
The reconstructed image (or curve, in this case) is exactly the same as the mask image, except that the peaks are truncated to 0.5 and 0. The middle peak disappears completely: Since there were no seed values in this peak region, its reconstructed value is truncated to the surrounding value (-1).
As a more practical example, we try to extract the bright features of an image by subtracting a background image created by reconstruction.
To create the background image, set the mask image to the original image, and the seed image to the original image with an intensity offset, h.
The resulting reconstructed image looks exactly like the original image, but with the peaks of the bumps cut off. Subtracting this reconstructed image from the original image leaves just the peaks of the bumps
This operation is known as the h-dome of the image and leaves features of height h in the subtracted image.
Generates a flat, rectangular-shaped structuring element.
Every pixel in the rectangle generated for a given width and given height belongs to the neighborhood.
The number of rows of the rectangle.
The number of columns of the rectangle.
A structuring element consisting only of ones, i.e. every pixel belongs to the neighborhood.
The data type of the structuring element.
Remove contiguous holes smaller than the specified size.
The array containing the connected components of interest.
The maximum area, in pixels, of a contiguous hole that will be filled. Replaces min_size.
The connectivity defining the neighborhood of a pixel.
If True, remove the connected components in the input array itself. Otherwise, make a copy.
The input array with small holes within connected components removed.
If the input array is of an invalid type, such as float or string.
If the input array contains negative values.
If the array type is int, it is assumed that it contains already-labeled objects. The labels are not kept in the output image (this function always outputs a bool image). It is suggested that labeling is completed after using this function.
Measure region properties
Remove objects smaller than the specified size.
Expects ar to be an array with labeled objects, and removes objects smaller than min_size. If ar is bool, the image is first labeled. This leads to potentially different behavior for bool and 0-and-1 arrays.
The array containing the objects of interest. If the array type is int, the ints must be non-negative.
The smallest allowable object size.
The connectivity defining the neighborhood of a pixel. Used during labelling if ar is bool.
If True, remove the objects in the input array itself. Otherwise, make a copy.
The input array with small connected components removed.
If the input array is of an invalid type, such as float or string.
If the input array contains negative values.
Measure region properties
Compute the skeleton of a binary image.
Thinning is used to reduce each connected component in a binary image to a single-pixel wide skeleton.
A binary image containing the objects to be skeletonized. Zeros represent background, nonzero values are foreground.
Which algorithm to use. Zhang’s algorithm [Zha84] only works for 2D images, and is the default for 2D. Lee’s algorithm [Lee94] works for 2D or 3D images and is the default for 3D.
The thinned image.
See also
T.-C. Lee, R.L. Kashyap and C.-N. Chu, Building skeleton models via 3-D medial surface/axis thinning algorithms. Computer Vision, Graphics, and Image Processing, 56(6):462-478, 1994.
A fast parallel algorithm for thinning digital patterns, T. Y. Zhang and C. Y. Suen, Communications of the ACM, March 1984, Volume 27, Number 3.
Compute the skeleton of a binary image.
Thinning is used to reduce each connected component in a binary image to a single-pixel wide skeleton.
A binary image containing the objects to be skeletonized. Zeros represent background, nonzero values are foreground.
The thinned image.
See also
The method of [Lee94] uses an octree data structure to examine a 3x3x3 neighborhood of a pixel. The algorithm proceeds by iteratively sweeping over the image, and removing pixels at each iteration until the image stops changing. Each iteration consists of two steps: first, a list of candidates for removal is assembled; then pixels from this list are rechecked sequentially, to better preserve connectivity of the image.
The algorithm this function implements is different from the algorithms used by either skeletonize or medial_axis, thus for 2D images the results produced by this function are generally different.
T.-C. Lee, R.L. Kashyap and C.-N. Chu, Building skeleton models via 3-D medial surface/axis thinning algorithms. Computer Vision, Graphics, and Image Processing, 56(6):462-478, 1994.
Generates a flat, square-shaped structuring element.
Every pixel along the perimeter has a chessboard distance no greater than radius (radius=floor(width/2)) pixels.
The width and height of the square.
A structuring element consisting only of ones, i.e. every pixel belongs to the neighborhood.
The data type of the structuring element.
Generates a star shaped structuring element.
Start has 8 vertices and is an overlap of square of size 2*a + 1 with its 45 degree rotated version. The slanted sides are 45 or 135 degrees to the horizontal axis.
Parameter deciding the size of the star structural element. The side of the square array returned is 2*a + 1 + 2*floor(a / 2).
The structuring element where elements of the neighborhood are 1 and 0 otherwise.
The data type of the structuring element.
Perform morphological thinning of a binary image.
The image to be thinned.
Regardless of the value of this parameter, the thinned image is returned immediately if an iteration produces no change. If this parameter is specified it thus sets an upper bound on the number of iterations performed.
Thinned image.
See also
This algorithm [1] works by making multiple passes over the image, removing pixels matching a set of criteria designed to thin connected regions while preserving eight-connected components and 2 x 2 squares [2]. In each of the two sub-iterations the algorithm correlates the intermediate skeleton image with a neighborhood mask, then looks up each neighborhood in a lookup table indicating whether the central pixel should be deleted in that sub-iteration.
Z. Guo and R. W. Hall, “Parallel thinning with two-subiteration algorithms,” Comm. ACM, vol. 32, no. 3, pp. 359-373, 1989. DOI:10.1145/62065.62074
Lam, L., Seong-Whan Lee, and Ching Y. Suen, “Thinning Methodologies-A Comprehensive Survey,” IEEE Transactions on Pattern Analysis and Machine Intelligence, Vol 14, No. 9, p. 879, 1992. DOI:10.1109/34.161346
Deprecated function. Use skimage.segmentation.watershed instead.
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.
Return white top hat of an image.
The white top hat of an image is defined as the image minus its morphological opening. This operation returns the bright spots of the image that are smaller than the structuring element.
Image array.
The neighborhood expressed as an array of 1’s and 0’s. If None, use cross-shaped structuring element (connectivity=1).
The array to store the result of the morphology. If None is passed, a new array will be allocated.
The result of the morphological white top hat.
See also
https://en.wikipedia.org/wiki/Top-hat_transform


Perform an area closing of the image.
Area closing removes all dark structures of an image with a surface smaller than area_threshold. The output image is larger than or equal to the input image for every pixel and all local minima have at least a surface of area_threshold pixels.
Area closings are similar to morphological closings, but they do not use a fixed structuring element, but rather a deformable one, with surface = area_threshold.
In the binary case, area closings are equivalent to remove_small_holes; this operator is thus extended to gray-level images.
Technically, this operator is based on the max-tree representation of the image.
The input image for which the area_closing is to be calculated. This image can be of any type.
The size parameter (number of pixels). The default value is arbitrarily chosen to be 64.
The neighborhood connectivity. The integer represents the maximum number of orthogonal steps to reach a neighbor. In 2D, it is 1 for a 4-neighborhood and 2 for a 8-neighborhood. Default value is 1.
Parent image representing the max tree of the inverted image. The value of each pixel is the index of its parent in the ravelled array. See Note for further details.
The ordered pixel indices (referring to the ravelled array). The pixels are ordered such that every pixel is preceded by its parent (except for the root which has no parent).
Output image of the same shape and type as input image.
See also
If a max-tree representation (parent and tree_traverser) are given to the function, they must be calculated from the inverted image for this function, i.e.: >>> P, S = max_tree(invert(f)) >>> closed = diameter_closing(f, 3, parent=P, tree_traverser=S)
Vincent L., Proc. “Grayscale area openings and closings, their efficient implementation and applications”, EURASIP Workshop on Mathematical Morphology and its Applications to Signal Processing, Barcelona, Spain, pp.22-27, May 1993.
Soille, P., “Morphological Image Analysis: Principles and Applications” (Chapter 6), 2nd edition (2003), ISBN 3540429883. DOI:10.1007/978-3-662-05088-0
Salembier, P., Oliveras, A., & Garrido, L. (1998). Antiextensive Connected Operators for Image and Sequence Processing. IEEE Transactions on Image Processing, 7(4), 555-570. DOI:10.1109/83.663500
Najman, L., & Couprie, M. (2006). Building the component tree in quasi-linear time. IEEE Transactions on Image Processing, 15(11), 3531-3539. DOI:10.1109/TIP.2006.877518
Carlinet, E., & Geraud, T. (2014). A Comparative Review of Component Tree Computation Algorithms. IEEE Transactions on Image Processing, 23(9), 3885-3895. DOI:10.1109/TIP.2014.2336551
We create an image (quadratic function with a minimum in the center and 4 additional local minima.
We can calculate the area closing:
All small minima are removed, and the remaining minima have at least a size of 8.


Perform an area opening of the image.
Area opening removes all bright structures of an image with a surface smaller than area_threshold. The output image is thus the largest image smaller than the input for which all local maxima have at least a surface of area_threshold pixels.
Area openings are similar to morphological openings, but they do not use a fixed structuring element, but rather a deformable one, with surface = area_threshold. Consequently, the area_opening with area_threshold=1 is the identity.
In the binary case, area openings are equivalent to remove_small_objects; this operator is thus extended to gray-level images.
Technically, this operator is based on the max-tree representation of the image.
The input image for which the area_opening is to be calculated. This image can be of any type.
The size parameter (number of pixels). The default value is arbitrarily chosen to be 64.
The neighborhood connectivity. The integer represents the maximum number of orthogonal steps to reach a neighbor. In 2D, it is 1 for a 4-neighborhood and 2 for a 8-neighborhood. Default value is 1.
Parent image representing the max tree of the image. The value of each pixel is the index of its parent in the ravelled array.
The ordered pixel indices (referring to the ravelled array). The pixels are ordered such that every pixel is preceded by its parent (except for the root which has no parent).
Output image of the same shape and type as the input image.
See also
Vincent L., Proc. “Grayscale area openings and closings, their efficient implementation and applications”, EURASIP Workshop on Mathematical Morphology and its Applications to Signal Processing, Barcelona, Spain, pp.22-27, May 1993.
Soille, P., “Morphological Image Analysis: Principles and Applications” (Chapter 6), 2nd edition (2003), ISBN 3540429883. :DOI:10.1007/978-3-662-05088-0
Salembier, P., Oliveras, A., & Garrido, L. (1998). Antiextensive Connected Operators for Image and Sequence Processing. IEEE Transactions on Image Processing, 7(4), 555-570. :DOI:10.1109/83.663500
Najman, L., & Couprie, M. (2006). Building the component tree in quasi-linear time. IEEE Transactions on Image Processing, 15(11), 3531-3539. :DOI:10.1109/TIP.2006.877518
Carlinet, E., & Geraud, T. (2014). A Comparative Review of Component Tree Computation Algorithms. IEEE Transactions on Image Processing, 23(9), 3885-3895. :DOI:10.1109/TIP.2014.2336551
We create an image (quadratic function with a maximum in the center and 4 additional local maxima.
We can calculate the area opening:
The peaks with a surface smaller than 8 are removed.


Generates a ball-shaped structuring element.
This is the 3D equivalent of a disk. A pixel is within the neighborhood if the Euclidean distance between it and the origin is no greater than radius.
The radius of the ball-shaped structuring element.
The structuring element where elements of the neighborhood are 1 and 0 otherwise.
The data type of the structuring element.


Return fast binary morphological closing of an image.
This function returns the same result as greyscale closing but performs faster for binary images.
The morphological closing on an image is defined as a dilation followed by an erosion. Closing can remove small dark spots (i.e. “pepper”) and connect small bright cracks. This tends to “close” up (dark) gaps between (bright) features.
Binary input image.
The neighborhood expressed as a 2-D array of 1’s and 0’s. If None, use a cross-shaped structuring element (connectivity=1).
The array to store the result of the morphology. If None, is passed, a new array will be allocated.
The result of the morphological closing.


Return fast binary morphological dilation of an image.
This function returns the same result as greyscale dilation but performs faster for binary images.
Morphological dilation sets a pixel at (i,j) to the maximum over all pixels in the neighborhood centered at (i,j). Dilation enlarges bright regions and shrinks dark regions.
Binary input image.
The neighborhood expressed as a 2-D array of 1’s and 0’s. If None, use a cross-shaped structuring element (connectivity=1).
The array to store the result of the morphology. If None is passed, a new array will be allocated.
The result of the morphological dilation with values in [False, True].


Return fast binary morphological erosion of an image.
This function returns the same result as greyscale erosion but performs faster for binary images.
Morphological erosion sets a pixel at (i,j) to the minimum over all pixels in the neighborhood centered at (i,j). Erosion shrinks bright regions and enlarges dark regions.
Binary input image.
The neighborhood expressed as a 2-D array of 1’s and 0’s. If None, use a cross-shaped structuring element (connectivity=1).
The array to store the result of the morphology. If None is passed, a new array will be allocated.
The result of the morphological erosion taking values in [False, True].


Return fast binary morphological opening of an image.
This function returns the same result as greyscale opening but performs faster for binary images.
The morphological opening on an image is defined as an erosion followed by a dilation. Opening can remove small bright spots (i.e. “salt”) and connect small dark cracks. This tends to “open” up (dark) gaps between (bright) features.
Binary input image.
The neighborhood expressed as a 2-D array of 1’s and 0’s. If None, use a cross-shaped structuring element (connectivity=1).
The array to store the result of the morphology. If None is passed, a new array will be allocated.
The result of the morphological opening.


Return black top hat of an image.
The black top hat of an image is defined as its morphological closing minus the original image. This operation returns the dark spots of the image that are smaller than the structuring element. Note that dark spots in the original image are bright spots after the black top hat.
Image array.
The neighborhood expressed as a 2-D array of 1’s and 0’s. If None, use cross-shaped structuring element (connectivity=1).
The array to store the result of the morphology. If None is passed, a new array will be allocated.
The result of the morphological black top hat.
See also
https://en.wikipedia.org/wiki/Top-hat_transform


Return greyscale morphological closing of an image.
The morphological closing on an image is defined as a dilation followed by an erosion. Closing can remove small dark spots (i.e. “pepper”) and connect small bright cracks. This tends to “close” up (dark) gaps between (bright) features.
Image array.
The neighborhood expressed as an array of 1’s and 0’s. If None, use cross-shaped structuring element (connectivity=1).
The array to store the result of the morphology. If None, is passed, a new array will be allocated.
The result of the morphological closing.


Compute the convex hull image of a binary image.
The convex hull is the set of pixels included in the smallest convex polygon that surround all white pixels in the input image.
Binary input image. This array is cast to bool before processing.
If True, a pixel at coordinate, e.g., (4, 7) will be represented by coordinates (3.5, 7), (4.5, 7), (4, 6.5), and (4, 7.5). This adds some “extent” to a pixel when computing the hull.
Tolerance when determining whether a point is inside the hull. Due to numerical floating point errors, a tolerance of 0 can result in some points erroneously being classified as being outside the hull.
Binary image with pixels in convex hull set to True.
https://blogs.mathworks.com/steve/2011/10/04/binary-image-convex-hull-algorithm-notes/


Compute the convex hull image of individual objects in a binary image.
The convex hull is the set of pixels included in the smallest convex polygon that surround all white pixels in the input image.
Binary input image.
Determines the neighbors of each pixel. Adjacent elements within a squared distance of connectivity from pixel center are considered neighbors.:
Binary image with pixels inside convex hull set to True.
This function uses skimage.morphology.label to define unique objects, finds the convex hull of each using convex_hull_image, and combines these regions with logical OR. Be aware the convex hulls of unconnected objects may overlap in the result. If this is suspected, consider using convex_hull_image separately on each object or adjust connectivity.


Generates a cube-shaped structuring element.
This is the 3D equivalent of a square. Every pixel along the perimeter has a chessboard distance no greater than radius (radius=floor(width/2)) pixels.
The width, height and depth of the cube.
A structuring element consisting only of ones, i.e. every pixel belongs to the neighborhood.
The data type of the structuring element.


Perform a diameter closing of the image.
Diameter closing removes all dark structures of an image with maximal extension smaller than diameter_threshold. The maximal extension is defined as the maximal extension of the bounding box. The operator is also called Bounding Box Closing. In practice, the result is similar to a morphological closing, but long and thin structures are not removed.
Technically, this operator is based on the max-tree representation of the image.
The input image for which the diameter_closing is to be calculated. This image can be of any type.
The maximal extension parameter (number of pixels). The default value is 8.
The neighborhood connectivity. The integer represents the maximum number of orthogonal steps to reach a neighbor. In 2D, it is 1 for a 4-neighborhood and 2 for a 8-neighborhood. Default value is 1.
Precomputed parent image representing the max tree of the inverted image. This function is fast, if precomputed parent and tree_traverser are provided. See Note for further details.
Precomputed traverser, where the pixels are ordered such that every pixel is preceded by its parent (except for the root which has no parent). This function is fast, if precomputed parent and tree_traverser are provided. See Note for further details.
Output image of the same shape and type as input image.
See also
If a max-tree representation (parent and tree_traverser) are given to the function, they must be calculated from the inverted image for this function, i.e.: >>> P, S = max_tree(invert(f)) >>> closed = diameter_closing(f, 3, parent=P, tree_traverser=S)
Walter, T., & Klein, J.-C. (2002). Automatic Detection of Microaneurysms in Color Fundus Images of the Human Retina by Means of the Bounding Box Closing. In A. Colosimo, P. Sirabella, A. Giuliani (Eds.), Medical Data Analysis. Lecture Notes in Computer Science, vol 2526, pp. 210-220. Springer Berlin Heidelberg. DOI:10.1007/3-540-36104-9_23
Carlinet, E., & Geraud, T. (2014). A Comparative Review of Component Tree Computation Algorithms. IEEE Transactions on Image Processing, 23(9), 3885-3895. DOI:10.1109/TIP.2014.2336551
We create an image (quadratic function with a minimum in the center and 4 additional local minima.
We can calculate the diameter closing:
All small minima with a maximal extension of 2 or less are removed. The remaining minima have all a maximal extension of at least 3.


Perform a diameter opening of the image.
Diameter opening removes all bright structures of an image with maximal extension smaller than diameter_threshold. The maximal extension is defined as the maximal extension of the bounding box. The operator is also called Bounding Box Opening. In practice, the result is similar to a morphological opening, but long and thin structures are not removed.
Technically, this operator is based on the max-tree representation of the image.
The input image for which the area_opening is to be calculated. This image can be of any type.
The maximal extension parameter (number of pixels). The default value is 8.
The neighborhood connectivity. The integer represents the maximum number of orthogonal steps to reach a neighbor. In 2D, it is 1 for a 4-neighborhood and 2 for a 8-neighborhood. Default value is 1.
Parent image representing the max tree of the image. The value of each pixel is the index of its parent in the ravelled array.
The ordered pixel indices (referring to the ravelled array). The pixels are ordered such that every pixel is preceded by its parent (except for the root which has no parent).
Output image of the same shape and type as the input image.
See also
Walter, T., & Klein, J.-C. (2002). Automatic Detection of Microaneurysms in Color Fundus Images of the Human Retina by Means of the Bounding Box Closing. In A. Colosimo, P. Sirabella, A. Giuliani (Eds.), Medical Data Analysis. Lecture Notes in Computer Science, vol 2526, pp. 210-220. Springer Berlin Heidelberg. DOI:10.1007/3-540-36104-9_23
Carlinet, E., & Geraud, T. (2014). A Comparative Review of Component Tree Computation Algorithms. IEEE Transactions on Image Processing, 23(9), 3885-3895. DOI:10.1109/TIP.2014.2336551
We create an image (quadratic function with a maximum in the center and 4 additional local maxima.
We can calculate the diameter opening:
The peaks with a maximal extension of 2 or less are removed. The remaining peaks have all a maximal extension of at least 3.


Generates a flat, diamond-shaped structuring element.
A pixel is part of the neighborhood (i.e. labeled 1) if the city block/Manhattan distance between it and the center of the neighborhood is no greater than radius.
The radius of the diamond-shaped structuring element.
The structuring element where elements of the neighborhood are 1 and 0 otherwise.
The data type of the structuring element.


Return greyscale morphological dilation of an image.
Morphological dilation sets a pixel at (i,j) to the maximum over all pixels in the neighborhood centered at (i,j). Dilation enlarges bright regions and shrinks dark regions.
Image array.
The neighborhood expressed as a 2-D array of 1’s and 0’s. If None, use cross-shaped structuring element (connectivity=1).
The array to store the result of the morphology. If None, is passed, a new array will be allocated.
shift structuring element about center point. This only affects eccentric structuring elements (i.e. selem with even numbered sides).
The result of the morphological dilation.
For uint8 (and uint16 up to a certain bit-depth) data, the lower algorithm complexity makes the skimage.filters.rank.maximum function more efficient for larger images and structuring elements.


Generates a flat, disk-shaped structuring element.
A pixel is within the neighborhood if the Euclidean distance between it and the origin is no greater than radius.
The radius of the disk-shaped structuring element.
The structuring element where elements of the neighborhood are 1 and 0 otherwise.
The data type of the structuring element.


Return greyscale morphological erosion of an image.
Morphological erosion sets a pixel at (i,j) to the minimum over all pixels in the neighborhood centered at (i,j). Erosion shrinks bright regions and enlarges dark regions.
Image array.
The neighborhood expressed as an array of 1’s and 0’s. If None, use cross-shaped structuring element (connectivity=1).
The array to store the result of the morphology. If None is passed, a new array will be allocated.
shift structuring element about center point. This only affects eccentric structuring elements (i.e. selem with even numbered sides).
The result of the morphological erosion.
For uint8 (and uint16 up to a certain bit-depth) data, the lower algorithm complexity makes the skimage.filters.rank.minimum function more efficient for larger images and structuring elements.