neulab/docprompting-conala huggingface dataset:
skimage.morphology.max_tree(image, connectivity=1) [source]
 
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.  Parameters 
 
imagendarray 

The input image for which the max-tree is to be calculated. This image can be of any type.  
connectivityunsigned int, optional 

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.    Returns 
 
parentndarray, int64 

Array of same shape as image. The value of each pixel is the index of its parent in the ravelled array.  
tree_traverser1D array, int64 

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).     References  
1  
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  
2  
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  
3  
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  
4  
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   Examples We create a small sample image (Figure 1 from [4]) and build the max-tree. >>> image = np.array([[15, 13, 16], [12, 12, 10], [16, 12, 14]])
>>> P, S = max_tree(image, connectivity=2)
skimage.morphology.max_tree_local_maxima(image, connectivity=1, parent=None, tree_traverser=None) [source]
 
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.  Parameters 
 
imagendarray 

The input image for which the maxima are to be calculated.  connectivity: unsigned int, optional

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: ndarray, int64, optional

The value of each pixel is the index of its parent in the ravelled array.  tree_traverser: 1D array, int64, optional

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).    Returns 
 
local_maxndarray, uint64 

Labeled local maxima of the image.      See also  
skimage.morphology.local_maxima


skimage.morphology.max_tree

  References  
1  
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.  
2  
Soille, P., “Morphological Image Analysis: Principles and Applications” (Chapter 6), 2nd edition (2003), ISBN 3540429883. DOI:10.1007/978-3-662-05088-0  
3  
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  
4  
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  
5  
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   Examples We create an image (quadratic function with a maximum in the center and 4 additional constant maxima. >>> w = 10
>>> x, y = np.mgrid[0:w,0:w]
>>> f = 20 - 0.2*((x - w/2)**2 + (y-w/2)**2)
>>> f[2:4,2:4] = 40; f[2:4,7:9] = 60; f[7:9,2:4] = 80; f[7:9,7:9] = 100
>>> f = f.astype(int)
 We can calculate all local maxima: >>> maxima = max_tree_local_maxima(f)
 The resulting image contains the labeled local maxima.
skimage.morphology.medial_axis(image, mask=None, return_distance=False) [source]
 
Compute the medial axis transform of a binary image  Parameters 
 
imagebinary ndarray, shape (M, N) 

The image of the shape to be skeletonized.  
maskbinary ndarray, shape (M, N), optional 

If a mask is given, only those elements in image with a true value in mask are used for computing the medial axis.  
return_distancebool, optional 

If true, the distance transform is returned as well as the skeleton.    Returns 
 
outndarray of bools 

Medial axis transform of the image  
distndarray of ints, optional 

Distance transform of the image (only returned if return_distance is True)      See also  
skeletonize

  Notes This algorithm computes the medial axis transform of an image as the ridges of its distance transform.  The different steps of the algorithm are as follows

 A lookup table is used, that assigns 0 or 1 to each configuration of the 3x3 binary square, whether the central pixel should be removed or kept. We want a point to be removed if it has more than one neighbor and if removing it does not change the number of connected components. The distance transform to the background is computed, as well as the cornerness of the pixel. The foreground (value of 1) points are ordered by the distance transform, then the cornerness. A cython function is called to reduce the image to its skeleton. It processes pixels in the order determined at the previous step, and removes or maintains a pixel according to the lookup table. Because of the ordering, it is possible to process all pixels in only one pass.    Examples >>> square = np.zeros((7, 7), dtype=np.uint8)
>>> square[1:-1, 2:-2] = 1
>>> square
array([[0, 0, 0, 0, 0, 0, 0],
       [0, 0, 1, 1, 1, 0, 0],
       [0, 0, 1, 1, 1, 0, 0],
       [0, 0, 1, 1, 1, 0, 0],
       [0, 0, 1, 1, 1, 0, 0],
       [0, 0, 1, 1, 1, 0, 0],
       [0, 0, 0, 0, 0, 0, 0]], dtype=uint8)
>>> medial_axis(square).astype(np.uint8)
array([[0, 0, 0, 0, 0, 0, 0],
       [0, 0, 1, 0, 1, 0, 0],
       [0, 0, 0, 1, 0, 0, 0],
       [0, 0, 0, 1, 0, 0, 0],
       [0, 0, 0, 1, 0, 0, 0],
       [0, 0, 1, 0, 1, 0, 0],
       [0, 0, 0, 0, 0, 0, 0]], dtype=uint8)
skimage.morphology.octagon(m, n, dtype=<class 'numpy.uint8'>) [source]
 
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.  Parameters 
 
mint 

The size of the horizontal and vertical sides.  
nint 

The height or width of the slanted sides.    Returns 
 
selemndarray 

The structuring element where elements of the neighborhood are 1 and 0 otherwise.    Other Parameters 
 
dtypedata-type 

The data type of the structuring element.
skimage.morphology.octahedron(radius, dtype=<class 'numpy.uint8'>) [source]
 
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.  Parameters 
 
radiusint 

The radius of the octahedron-shaped structuring element.    Returns 
 
selemndarray 

The structuring element where elements of the neighborhood are 1 and 0 otherwise.    Other Parameters 
 
dtypedata-type 

The data type of the structuring element.
skimage.morphology.opening(image, selem=None, out=None) [source]
 
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.  Parameters 
 
imagendarray 

Image array.  
selemndarray, optional 

The neighborhood expressed as an array of 1’s and 0’s. If None, use cross-shaped structuring element (connectivity=1).  
outndarray, optional 

The array to store the result of the morphology. If None is passed, a new array will be allocated.    Returns 
 
openingarray, same shape and type as image 

The result of the morphological opening.     Examples >>> # Open up gap between two bright regions (but also shrink regions)
>>> import numpy as np
>>> from skimage.morphology import square
>>> bad_connection = np.array([[1, 0, 0, 0, 1],
...                            [1, 1, 0, 1, 1],
...                            [1, 1, 1, 1, 1],
...                            [1, 1, 0, 1, 1],
...                            [1, 0, 0, 0, 1]], dtype=np.uint8)
>>> opening(bad_connection, square(3))
array([[0, 0, 0, 0, 0],
       [1, 1, 0, 1, 1],
       [1, 1, 0, 1, 1],
       [1, 1, 0, 1, 1],
       [0, 0, 0, 0, 0]], dtype=uint8)
skimage.morphology.rectangle(nrows, ncols, dtype=<class 'numpy.uint8'>) [source]
 
Generates a flat, rectangular-shaped structuring element. Every pixel in the rectangle generated for a given width and given height belongs to the neighborhood.  Parameters 
 
nrowsint 

The number of rows of the rectangle.  
ncolsint 

The number of columns of the rectangle.    Returns 
 
selemndarray 

A structuring element consisting only of ones, i.e. every pixel belongs to the neighborhood.    Other Parameters 
 
dtypedata-type 

The data type of the structuring element.     Notes  The use of width and height has been deprecated in version 0.18.0. Use nrows and ncols instead.
skimage.morphology.remove_small_holes(ar, area_threshold=64, connectivity=1, in_place=False) [source]
 
Remove contiguous holes smaller than the specified size.  Parameters 
 
arndarray (arbitrary shape, int or bool type) 

The array containing the connected components of interest.  
area_thresholdint, optional (default: 64) 

The maximum area, in pixels, of a contiguous hole that will be filled. Replaces min_size.  
connectivityint, {1, 2, …, ar.ndim}, optional (default: 1) 

The connectivity defining the neighborhood of a pixel.  
in_placebool, optional (default: False) 

If True, remove the connected components in the input array itself. Otherwise, make a copy.    Returns 
 
outndarray, same shape and type as input ar 

The input array with small holes within connected components removed.    Raises 
 TypeError

If the input array is of an invalid type, such as float or string.  ValueError

If the input array contains negative values.     Notes 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. Examples >>> from skimage import morphology
>>> a = np.array([[1, 1, 1, 1, 1, 0],
...               [1, 1, 1, 0, 1, 0],
...               [1, 0, 0, 1, 1, 0],
...               [1, 1, 1, 1, 1, 0]], bool)
>>> b = morphology.remove_small_holes(a, 2)
>>> b
array([[ True,  True,  True,  True,  True, False],
       [ True,  True,  True,  True,  True, False],
       [ True, False, False,  True,  True, False],
       [ True,  True,  True,  True,  True, False]])
>>> c = morphology.remove_small_holes(a, 2, connectivity=2)
>>> c
array([[ True,  True,  True,  True,  True, False],
       [ True,  True,  True, False,  True, False],
       [ True, False, False,  True,  True, False],
       [ True,  True,  True,  True,  True, False]])
>>> d = morphology.remove_small_holes(a, 2, in_place=True)
>>> d is a
True
skimage.morphology.remove_small_objects(ar, min_size=64, connectivity=1, in_place=False) [source]
 
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.  Parameters 
 
arndarray (arbitrary shape, int or bool type) 

The array containing the objects of interest. If the array type is int, the ints must be non-negative.  
min_sizeint, optional (default: 64) 

The smallest allowable object size.  
connectivityint, {1, 2, …, ar.ndim}, optional (default: 1) 

The connectivity defining the neighborhood of a pixel. Used during labelling if ar is bool.  
in_placebool, optional (default: False) 

If True, remove the objects in the input array itself. Otherwise, make a copy.    Returns 
 
outndarray, same shape and type as input ar 

The input array with small connected components removed.    Raises 
 TypeError

If the input array is of an invalid type, such as float or string.  ValueError

If the input array contains negative values.     Examples >>> from skimage import morphology
>>> a = np.array([[0, 0, 0, 1, 0],
...               [1, 1, 1, 0, 0],
...               [1, 1, 1, 0, 1]], bool)
>>> b = morphology.remove_small_objects(a, 6)
>>> b
array([[False, False, False, False, False],
       [ True,  True,  True, False, False],
       [ True,  True,  True, False, False]])
>>> c = morphology.remove_small_objects(a, 7, connectivity=2)
>>> c
array([[False, False, False,  True, False],
       [ True,  True,  True, False, False],
       [ True,  True,  True, False, False]])
>>> d = morphology.remove_small_objects(a, 6, in_place=True)
>>> d is a
True
skimage.morphology.skeletonize(image, *, method=None) [source]
 
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.  Parameters 
 
imagendarray, 2D or 3D 

A binary image containing the objects to be skeletonized. Zeros represent background, nonzero values are foreground.  
method{‘zhang’, ‘lee’}, optional 

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.    Returns 
 
skeletonndarray 

The thinned image.      See also  
medial_axis

  References  
Lee94  
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.  
Zha84  
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.   Examples >>> X, Y = np.ogrid[0:9, 0:9]
>>> ellipse = (1./3 * (X - 4)**2 + (Y - 4)**2 < 3**2).astype(np.uint8)
>>> ellipse
array([[0, 0, 0, 1, 1, 1, 0, 0, 0],
       [0, 0, 1, 1, 1, 1, 1, 0, 0],
       [0, 0, 1, 1, 1, 1, 1, 0, 0],
       [0, 0, 1, 1, 1, 1, 1, 0, 0],
       [0, 0, 1, 1, 1, 1, 1, 0, 0],
       [0, 0, 1, 1, 1, 1, 1, 0, 0],
       [0, 0, 1, 1, 1, 1, 1, 0, 0],
       [0, 0, 1, 1, 1, 1, 1, 0, 0],
       [0, 0, 0, 1, 1, 1, 0, 0, 0]], dtype=uint8)
>>> skel = skeletonize(ellipse)
>>> skel.astype(np.uint8)
array([[0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 1, 0, 0, 0, 0],
       [0, 0, 0, 0, 1, 0, 0, 0, 0],
       [0, 0, 0, 0, 1, 0, 0, 0, 0],
       [0, 0, 0, 0, 1, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0, 0, 0]], dtype=uint8)
skimage.morphology.skeletonize_3d(image) [source]
 
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.  Parameters 
 
imagendarray, 2D or 3D 

A binary image containing the objects to be skeletonized. Zeros represent background, nonzero values are foreground.    Returns 
 
skeletonndarray 

The thinned image.      See also  
skeletonize, medial_axis

  Notes 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. References  
Lee94  
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.
skimage.morphology.square(width, dtype=<class 'numpy.uint8'>) [source]
 
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.  Parameters 
 
widthint 

The width and height of the square.    Returns 
 
selemndarray 

A structuring element consisting only of ones, i.e. every pixel belongs to the neighborhood.    Other Parameters 
 
dtypedata-type 

The data type of the structuring element.
skimage.morphology.star(a, dtype=<class 'numpy.uint8'>) [source]
 
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.  Parameters 
 
aint 

Parameter deciding the size of the star structural element. The side of the square array returned is 2*a + 1 + 2*floor(a / 2).    Returns 
 
selemndarray 

The structuring element where elements of the neighborhood are 1 and 0 otherwise.    Other Parameters 
 
dtypedata-type 

The data type of the structuring element.
skimage.morphology.thin(image, max_iter=None) [source]
 
Perform morphological thinning of a binary image.  Parameters 
 
imagebinary (M, N) ndarray 

The image to be thinned.  
max_iterint, number of iterations, optional 

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.    Returns 
 
outndarray of bool 

Thinned image.      See also  
skeletonize, medial_axis

  Notes 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. References  
1  
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  
2  
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   Examples >>> square = np.zeros((7, 7), dtype=np.uint8)
>>> square[1:-1, 2:-2] = 1
>>> square[0, 1] =  1
>>> square
array([[0, 1, 0, 0, 0, 0, 0],
       [0, 0, 1, 1, 1, 0, 0],
       [0, 0, 1, 1, 1, 0, 0],
       [0, 0, 1, 1, 1, 0, 0],
       [0, 0, 1, 1, 1, 0, 0],
       [0, 0, 1, 1, 1, 0, 0],
       [0, 0, 0, 0, 0, 0, 0]], dtype=uint8)
>>> skel = thin(square)
>>> skel.astype(np.uint8)
array([[0, 1, 0, 0, 0, 0, 0],
       [0, 0, 1, 0, 0, 0, 0],
       [0, 0, 0, 1, 0, 0, 0],
       [0, 0, 0, 1, 0, 0, 0],
       [0, 0, 0, 1, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0],
       [0, 0, 0, 0, 0, 0, 0]], dtype=uint8)
skimage.morphology.white_tophat(image, selem=None, out=None) [source]
 
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.  Parameters 
 
imagendarray 

Image array.  
selemndarray, optional 

The neighborhood expressed as an array of 1’s and 0’s. If None, use cross-shaped structuring element (connectivity=1).  
outndarray, optional 

The array to store the result of the morphology. If None is passed, a new array will be allocated.    Returns 
 
outarray, same shape and type as image 

The result of the morphological white top hat.      See also  
black_tophat

  References  
1  
https://en.wikipedia.org/wiki/Top-hat_transform   Examples >>> # Subtract grey background from bright peak
>>> import numpy as np
>>> from skimage.morphology import square
>>> bright_on_grey = np.array([[2, 3, 3, 3, 2],
...                            [3, 4, 5, 4, 3],
...                            [3, 5, 9, 5, 3],
...                            [3, 4, 5, 4, 3],
...                            [2, 3, 3, 3, 2]], dtype=np.uint8)
>>> white_tophat(bright_on_grey, square(3))
array([[0, 0, 0, 0, 0],
       [0, 0, 1, 0, 0],
       [0, 1, 5, 1, 0],
       [0, 0, 1, 0, 0],
       [0, 0, 0, 0, 0]], dtype=uint8)