We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Error in documentation for watershed
The [documentation for watershed](https://scikit-image.org/docs/dev/api/skimage.segmentation.html#skimage.segmentation.watershed) says

> image : ndarray (2-D, 3-D, …) of integers
> Data array where the lowest value points are labeled first.

But when I look into the code and the [official example](https://scikit-image.org/docs/dev/auto_examples/segmentation/plot_watershed.html), it seems that watershed is actually dealing with float arrays, not integer arrays. I think this might be a mistake in the documentation. If not, please explain how so. If so, I would be happy if someone - who knows how - could correct the documentation.

--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `skimage/segmentation/_watershed.py`
Content:
```
1 """watershed.py - watershed algorithm
2 
3 This module implements a watershed algorithm that apportions pixels into
4 marked basins. The algorithm uses a priority queue to hold the pixels
5 with the metric for the priority queue being pixel value, then the time
6 of entry into the queue - this settles ties in favor of the closest marker.
7 
8 Some ideas taken from
9 Soille, "Automated Basin Delineation from Digital Elevation Models Using
10 Mathematical Morphology", Signal Processing 20 (1990) 171-182.
11 
12 The most important insight in the paper is that entry time onto the queue
13 solves two problems: a pixel should be assigned to the neighbor with the
14 largest gradient or, if there is no gradient, pixels on a plateau should
15 be split between markers on opposite sides.
16 
17 Originally part of CellProfiler, code licensed under both GPL and BSD licenses.
18 Website: http://www.cellprofiler.org
19 
20 Copyright (c) 2003-2009 Massachusetts Institute of Technology
21 Copyright (c) 2009-2011 Broad Institute
22 All rights reserved.
23 
24 Original author: Lee Kamentsky
25 """
26 
27 import numpy as np
28 from scipy import ndimage as ndi
29 
30 from . import _watershed_cy
31 from ..morphology.extrema import local_minima
32 from ..morphology._util import (_validate_connectivity,
33                                 _offsets_to_raveled_neighbors)
34 from ..util import crop, regular_seeds
35 
36 
37 def _validate_inputs(image, markers, mask, connectivity):
38     """Ensure that all inputs to watershed have matching shapes and types.
39 
40     Parameters
41     ----------
42     image : array
43         The input image.
44     markers : int or array of int
45         The marker image.
46     mask : array, or None
47         A boolean mask, True where we want to compute the watershed.
48     connectivity : int in {1, ..., image.ndim}
49         The connectivity of the neighborhood of a pixel.
50 
51     Returns
52     -------
53     image, markers, mask : arrays
54         The validated and formatted arrays. Image will have dtype float64,
55         markers int32, and mask int8. If ``None`` was given for the mask,
56         it is a volume of all 1s.
57 
58     Raises
59     ------
60     ValueError
61         If the shapes of the given arrays don't match.
62     """
63     n_pixels = image.size
64     if mask is None:
65         # Use a complete `True` mask if none is provided
66         mask = np.ones(image.shape, bool)
67     else:
68         mask = np.asanyarray(mask, dtype=bool)
69         n_pixels = np.sum(mask)
70         if mask.shape != image.shape:
71             message = ("`mask` (shape {}) must have same shape as "
72                        "`image` (shape {})".format(mask.shape, image.shape))
73             raise ValueError(message)
74     if markers is None:
75         markers_bool = local_minima(image, connectivity=connectivity) * mask
76         footprint = ndi.generate_binary_structure(markers_bool.ndim, connectivity)
77         markers = ndi.label(markers_bool, structure=footprint)[0]
78     elif not isinstance(markers, (np.ndarray, list, tuple)):
79         # not array-like, assume int
80         # given int, assume that number of markers *within mask*.
81         markers = regular_seeds(image.shape,
82                                 int(markers / (n_pixels / image.size)))
83         markers *= mask
84     else:
85         markers = np.asanyarray(markers) * mask
86         if markers.shape != image.shape:
87             message = ("`markers` (shape {}) must have same shape as "
88                        "`image` (shape {})".format(markers.shape, image.shape))
89             raise ValueError(message)
90     return (image.astype(np.float64),
91             markers.astype(np.int32),
92             mask.astype(np.int8))
93 
94 
95 def watershed(image, markers=None, connectivity=1, offset=None, mask=None,
96               compactness=0, watershed_line=False):
97     """Find watershed basins in `image` flooded from given `markers`.
98 
99     Parameters
100     ----------
101     image : ndarray (2-D, 3-D, ...) of integers
102         Data array where the lowest value points are labeled first.
103     markers : int, or ndarray of int, same shape as `image`, optional
104         The desired number of markers, or an array marking the basins with the
105         values to be assigned in the label matrix. Zero means not a marker. If
106         ``None`` (no markers given), the local minima of the image are used as
107         markers.
108     connectivity : ndarray, optional
109         An array with the same number of dimensions as `image` whose
110         non-zero elements indicate neighbors for connection.
111         Following the scipy convention, default is a one-connected array of
112         the dimension of the image.
113     offset : array_like of shape image.ndim, optional
114         offset of the connectivity (one offset per dimension)
115     mask : ndarray of bools or 0s and 1s, optional
116         Array of same shape as `image`. Only points at which mask == True
117         will be labeled.
118     compactness : float, optional
119         Use compact watershed [3]_ with given compactness parameter.
120         Higher values result in more regularly-shaped watershed basins.
121     watershed_line : bool, optional
122         If watershed_line is True, a one-pixel wide line separates the regions
123         obtained by the watershed algorithm. The line has the label 0.
124 
125     Returns
126     -------
127     out : ndarray
128         A labeled matrix of the same type and shape as markers
129 
130     See Also
131     --------
132     skimage.segmentation.random_walker : random walker segmentation
133         A segmentation algorithm based on anisotropic diffusion, usually
134         slower than the watershed but with good results on noisy data and
135         boundaries with holes.
136 
137     Notes
138     -----
139     This function implements a watershed algorithm [1]_ [2]_ that apportions
140     pixels into marked basins. The algorithm uses a priority queue to hold
141     the pixels with the metric for the priority queue being pixel value, then
142     the time of entry into the queue - this settles ties in favor of the
143     closest marker.
144 
145     Some ideas taken from
146     Soille, "Automated Basin Delineation from Digital Elevation Models Using
147     Mathematical Morphology", Signal Processing 20 (1990) 171-182
148 
149     The most important insight in the paper is that entry time onto the queue
150     solves two problems: a pixel should be assigned to the neighbor with the
151     largest gradient or, if there is no gradient, pixels on a plateau should
152     be split between markers on opposite sides.
153 
154     This implementation converts all arguments to specific, lowest common
155     denominator types, then passes these to a C algorithm.
156 
157     Markers can be determined manually, or automatically using for example
158     the local minima of the gradient of the image, or the local maxima of the
159     distance function to the background for separating overlapping objects
160     (see example).
161 
162     References
163     ----------
164     .. [1] https://en.wikipedia.org/wiki/Watershed_%28image_processing%29
165 
166     .. [2] http://cmm.ensmp.fr/~beucher/wtshed.html
167 
168     .. [3] Peer Neubert & Peter Protzel (2014). Compact Watershed and
169            Preemptive SLIC: On Improving Trade-offs of Superpixel Segmentation
170            Algorithms. ICPR 2014, pp 996-1001. :DOI:`10.1109/ICPR.2014.181`
171            https://www.tu-chemnitz.de/etit/proaut/publications/cws_pSLIC_ICPR.pdf
172 
173     Examples
174     --------
175     The watershed algorithm is useful to separate overlapping objects.
176 
177     We first generate an initial image with two overlapping circles:
178 
179     >>> x, y = np.indices((80, 80))
180     >>> x1, y1, x2, y2 = 28, 28, 44, 52
181     >>> r1, r2 = 16, 20
182     >>> mask_circle1 = (x - x1)**2 + (y - y1)**2 < r1**2
183     >>> mask_circle2 = (x - x2)**2 + (y - y2)**2 < r2**2
184     >>> image = np.logical_or(mask_circle1, mask_circle2)
185 
186     Next, we want to separate the two circles. We generate markers at the
187     maxima of the distance to the background:
188 
189     >>> from scipy import ndimage as ndi
190     >>> distance = ndi.distance_transform_edt(image)
191     >>> from skimage.feature import peak_local_max
192     >>> local_maxi = peak_local_max(distance, labels=image,
193     ...                             footprint=np.ones((3, 3)),
194     ...                             indices=False)
195     >>> markers = ndi.label(local_maxi)[0]
196 
197     Finally, we run the watershed on the image and markers:
198 
199     >>> labels = watershed(-distance, markers, mask=image)
200 
201     The algorithm works also for 3-D images, and can be used for example to
202     separate overlapping spheres.
203     """
204     image, markers, mask = _validate_inputs(image, markers, mask, connectivity)
205     connectivity, offset = _validate_connectivity(image.ndim, connectivity,
206                                                   offset)
207 
208     # pad the image, markers, and mask so that we can use the mask to
209     # keep from running off the edges
210     pad_width = [(p, p) for p in offset]
211     image = np.pad(image, pad_width, mode='constant')
212     mask = np.pad(mask, pad_width, mode='constant').ravel()
213     output = np.pad(markers, pad_width, mode='constant')
214 
215     flat_neighborhood = _offsets_to_raveled_neighbors(
216         image.shape, connectivity, center=offset)
217     marker_locations = np.flatnonzero(output)
218     image_strides = np.array(image.strides, dtype=np.intp) // image.itemsize
219 
220     _watershed_cy.watershed_raveled(image.ravel(),
221                                     marker_locations, flat_neighborhood,
222                                     mask, image_strides, compactness,
223                                     output.ravel(),
224                                     watershed_line)
225 
226     output = crop(output, pad_width, copy=True)
227 
228     return output
229
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/skimage/segmentation/_watershed.py b/skimage/segmentation/_watershed.py
--- a/skimage/segmentation/_watershed.py
+++ b/skimage/segmentation/_watershed.py
@@ -98,7 +98,7 @@
 
     Parameters
     ----------
-    image : ndarray (2-D, 3-D, ...) of integers
+    image : ndarray (2-D, 3-D, ...)
         Data array where the lowest value points are labeled first.
     markers : int, or ndarray of int, same shape as `image`, optional
         The desired number of markers, or an array marking the basins with the

{"golden_diff": "diff --git a/skimage/segmentation/_watershed.py b/skimage/segmentation/_watershed.py\n--- a/skimage/segmentation/_watershed.py\n+++ b/skimage/segmentation/_watershed.py\n@@ -98,7 +98,7 @@\n \n     Parameters\n     ----------\n-    image : ndarray (2-D, 3-D, ...) of integers\n+    image : ndarray (2-D, 3-D, ...)\n         Data array where the lowest value points are labeled first.\n     markers : int, or ndarray of int, same shape as `image`, optional\n         The desired number of markers, or an array marking the basins with the\n", "issue": "Error in documentation for watershed\nThe [documentation for watershed](https://scikit-image.org/docs/dev/api/skimage.segmentation.html#skimage.segmentation.watershed) says\r\n\r\n> image : ndarray (2-D, 3-D, \u2026) of integers\r\n> Data array where the lowest value points are labeled first.\r\n\r\nBut when I look into the code and the [official example](https://scikit-image.org/docs/dev/auto_examples/segmentation/plot_watershed.html), it seems that watershed is actually dealing with float arrays, not integer arrays. I think this might be a mistake in the documentation. If not, please explain how so. If so, I would be happy if someone - who knows how - could correct the documentation.\n", "before_files": [{"content": "\"\"\"watershed.py - watershed algorithm\n\nThis module implements a watershed algorithm that apportions pixels into\nmarked basins. The algorithm uses a priority queue to hold the pixels\nwith the metric for the priority queue being pixel value, then the time\nof entry into the queue - this settles ties in favor of the closest marker.\n\nSome ideas taken from\nSoille, \"Automated Basin Delineation from Digital Elevation Models Using\nMathematical Morphology\", Signal Processing 20 (1990) 171-182.\n\nThe most important insight in the paper is that entry time onto the queue\nsolves two problems: a pixel should be assigned to the neighbor with the\nlargest gradient or, if there is no gradient, pixels on a plateau should\nbe split between markers on opposite sides.\n\nOriginally part of CellProfiler, code licensed under both GPL and BSD licenses.\nWebsite: http://www.cellprofiler.org\n\nCopyright (c) 2003-2009 Massachusetts Institute of Technology\nCopyright (c) 2009-2011 Broad Institute\nAll rights reserved.\n\nOriginal author: Lee Kamentsky\n\"\"\"\n\nimport numpy as np\nfrom scipy import ndimage as ndi\n\nfrom . import _watershed_cy\nfrom ..morphology.extrema import local_minima\nfrom ..morphology._util import (_validate_connectivity,\n                                _offsets_to_raveled_neighbors)\nfrom ..util import crop, regular_seeds\n\n\ndef _validate_inputs(image, markers, mask, connectivity):\n    \"\"\"Ensure that all inputs to watershed have matching shapes and types.\n\n    Parameters\n    ----------\n    image : array\n        The input image.\n    markers : int or array of int\n        The marker image.\n    mask : array, or None\n        A boolean mask, True where we want to compute the watershed.\n    connectivity : int in {1, ..., image.ndim}\n        The connectivity of the neighborhood of a pixel.\n\n    Returns\n    -------\n    image, markers, mask : arrays\n        The validated and formatted arrays. Image will have dtype float64,\n        markers int32, and mask int8. If ``None`` was given for the mask,\n        it is a volume of all 1s.\n\n    Raises\n    ------\n    ValueError\n        If the shapes of the given arrays don't match.\n    \"\"\"\n    n_pixels = image.size\n    if mask is None:\n        # Use a complete `True` mask if none is provided\n        mask = np.ones(image.shape, bool)\n    else:\n        mask = np.asanyarray(mask, dtype=bool)\n        n_pixels = np.sum(mask)\n        if mask.shape != image.shape:\n            message = (\"`mask` (shape {}) must have same shape as \"\n                       \"`image` (shape {})\".format(mask.shape, image.shape))\n            raise ValueError(message)\n    if markers is None:\n        markers_bool = local_minima(image, connectivity=connectivity) * mask\n        footprint = ndi.generate_binary_structure(markers_bool.ndim, connectivity)\n        markers = ndi.label(markers_bool, structure=footprint)[0]\n    elif not isinstance(markers, (np.ndarray, list, tuple)):\n        # not array-like, assume int\n        # given int, assume that number of markers *within mask*.\n        markers = regular_seeds(image.shape,\n                                int(markers / (n_pixels / image.size)))\n        markers *= mask\n    else:\n        markers = np.asanyarray(markers) * mask\n        if markers.shape != image.shape:\n            message = (\"`markers` (shape {}) must have same shape as \"\n                       \"`image` (shape {})\".format(markers.shape, image.shape))\n            raise ValueError(message)\n    return (image.astype(np.float64),\n            markers.astype(np.int32),\n            mask.astype(np.int8))\n\n\ndef watershed(image, markers=None, connectivity=1, offset=None, mask=None,\n              compactness=0, watershed_line=False):\n    \"\"\"Find watershed basins in `image` flooded from given `markers`.\n\n    Parameters\n    ----------\n    image : ndarray (2-D, 3-D, ...) of integers\n        Data array where the lowest value points are labeled first.\n    markers : int, or ndarray of int, same shape as `image`, optional\n        The desired number of markers, or an array marking the basins with the\n        values to be assigned in the label matrix. Zero means not a marker. If\n        ``None`` (no markers given), the local minima of the image are used as\n        markers.\n    connectivity : ndarray, optional\n        An array with the same number of dimensions as `image` whose\n        non-zero elements indicate neighbors for connection.\n        Following the scipy convention, default is a one-connected array of\n        the dimension of the image.\n    offset : array_like of shape image.ndim, optional\n        offset of the connectivity (one offset per dimension)\n    mask : ndarray of bools or 0s and 1s, optional\n        Array of same shape as `image`. Only points at which mask == True\n        will be labeled.\n    compactness : float, optional\n        Use compact watershed [3]_ with given compactness parameter.\n        Higher values result in more regularly-shaped watershed basins.\n    watershed_line : bool, optional\n        If watershed_line is True, a one-pixel wide line separates the regions\n        obtained by the watershed algorithm. The line has the label 0.\n\n    Returns\n    -------\n    out : ndarray\n        A labeled matrix of the same type and shape as markers\n\n    See Also\n    --------\n    skimage.segmentation.random_walker : random walker segmentation\n        A segmentation algorithm based on anisotropic diffusion, usually\n        slower than the watershed but with good results on noisy data and\n        boundaries with holes.\n\n    Notes\n    -----\n    This function implements a watershed algorithm [1]_ [2]_ that apportions\n    pixels into marked basins. The algorithm uses a priority queue to hold\n    the pixels with the metric for the priority queue being pixel value, then\n    the time of entry into the queue - this settles ties in favor of the\n    closest marker.\n\n    Some ideas taken from\n    Soille, \"Automated Basin Delineation from Digital Elevation Models Using\n    Mathematical Morphology\", Signal Processing 20 (1990) 171-182\n\n    The most important insight in the paper is that entry time onto the queue\n    solves two problems: a pixel should be assigned to the neighbor with the\n    largest gradient or, if there is no gradient, pixels on a plateau should\n    be split between markers on opposite sides.\n\n    This implementation converts all arguments to specific, lowest common\n    denominator types, then passes these to a C algorithm.\n\n    Markers can be determined manually, or automatically using for example\n    the local minima of the gradient of the image, or the local maxima of the\n    distance function to the background for separating overlapping objects\n    (see example).\n\n    References\n    ----------\n    .. [1] https://en.wikipedia.org/wiki/Watershed_%28image_processing%29\n\n    .. [2] http://cmm.ensmp.fr/~beucher/wtshed.html\n\n    .. [3] Peer Neubert & Peter Protzel (2014). Compact Watershed and\n           Preemptive SLIC: On Improving Trade-offs of Superpixel Segmentation\n           Algorithms. ICPR 2014, pp 996-1001. :DOI:`10.1109/ICPR.2014.181`\n           https://www.tu-chemnitz.de/etit/proaut/publications/cws_pSLIC_ICPR.pdf\n\n    Examples\n    --------\n    The watershed algorithm is useful to separate overlapping objects.\n\n    We first generate an initial image with two overlapping circles:\n\n    >>> x, y = np.indices((80, 80))\n    >>> x1, y1, x2, y2 = 28, 28, 44, 52\n    >>> r1, r2 = 16, 20\n    >>> mask_circle1 = (x - x1)**2 + (y - y1)**2 < r1**2\n    >>> mask_circle2 = (x - x2)**2 + (y - y2)**2 < r2**2\n    >>> image = np.logical_or(mask_circle1, mask_circle2)\n\n    Next, we want to separate the two circles. We generate markers at the\n    maxima of the distance to the background:\n\n    >>> from scipy import ndimage as ndi\n    >>> distance = ndi.distance_transform_edt(image)\n    >>> from skimage.feature import peak_local_max\n    >>> local_maxi = peak_local_max(distance, labels=image,\n    ...                             footprint=np.ones((3, 3)),\n    ...                             indices=False)\n    >>> markers = ndi.label(local_maxi)[0]\n\n    Finally, we run the watershed on the image and markers:\n\n    >>> labels = watershed(-distance, markers, mask=image)\n\n    The algorithm works also for 3-D images, and can be used for example to\n    separate overlapping spheres.\n    \"\"\"\n    image, markers, mask = _validate_inputs(image, markers, mask, connectivity)\n    connectivity, offset = _validate_connectivity(image.ndim, connectivity,\n                                                  offset)\n\n    # pad the image, markers, and mask so that we can use the mask to\n    # keep from running off the edges\n    pad_width = [(p, p) for p in offset]\n    image = np.pad(image, pad_width, mode='constant')\n    mask = np.pad(mask, pad_width, mode='constant').ravel()\n    output = np.pad(markers, pad_width, mode='constant')\n\n    flat_neighborhood = _offsets_to_raveled_neighbors(\n        image.shape, connectivity, center=offset)\n    marker_locations = np.flatnonzero(output)\n    image_strides = np.array(image.strides, dtype=np.intp) // image.itemsize\n\n    _watershed_cy.watershed_raveled(image.ravel(),\n                                    marker_locations, flat_neighborhood,\n                                    mask, image_strides, compactness,\n                                    output.ravel(),\n                                    watershed_line)\n\n    output = crop(output, pad_width, copy=True)\n\n    return output\n", "path": "skimage/segmentation/_watershed.py"}], "after_files": [{"content": "\"\"\"watershed.py - watershed algorithm\n\nThis module implements a watershed algorithm that apportions pixels into\nmarked basins. The algorithm uses a priority queue to hold the pixels\nwith the metric for the priority queue being pixel value, then the time\nof entry into the queue - this settles ties in favor of the closest marker.\n\nSome ideas taken from\nSoille, \"Automated Basin Delineation from Digital Elevation Models Using\nMathematical Morphology\", Signal Processing 20 (1990) 171-182.\n\nThe most important insight in the paper is that entry time onto the queue\nsolves two problems: a pixel should be assigned to the neighbor with the\nlargest gradient or, if there is no gradient, pixels on a plateau should\nbe split between markers on opposite sides.\n\nOriginally part of CellProfiler, code licensed under both GPL and BSD licenses.\nWebsite: http://www.cellprofiler.org\n\nCopyright (c) 2003-2009 Massachusetts Institute of Technology\nCopyright (c) 2009-2011 Broad Institute\nAll rights reserved.\n\nOriginal author: Lee Kamentsky\n\"\"\"\n\nimport numpy as np\nfrom scipy import ndimage as ndi\n\nfrom . import _watershed_cy\nfrom ..morphology.extrema import local_minima\nfrom ..morphology._util import (_validate_connectivity,\n                                _offsets_to_raveled_neighbors)\nfrom ..util import crop, regular_seeds\n\n\ndef _validate_inputs(image, markers, mask, connectivity):\n    \"\"\"Ensure that all inputs to watershed have matching shapes and types.\n\n    Parameters\n    ----------\n    image : array\n        The input image.\n    markers : int or array of int\n        The marker image.\n    mask : array, or None\n        A boolean mask, True where we want to compute the watershed.\n    connectivity : int in {1, ..., image.ndim}\n        The connectivity of the neighborhood of a pixel.\n\n    Returns\n    -------\n    image, markers, mask : arrays\n        The validated and formatted arrays. Image will have dtype float64,\n        markers int32, and mask int8. If ``None`` was given for the mask,\n        it is a volume of all 1s.\n\n    Raises\n    ------\n    ValueError\n        If the shapes of the given arrays don't match.\n    \"\"\"\n    n_pixels = image.size\n    if mask is None:\n        # Use a complete `True` mask if none is provided\n        mask = np.ones(image.shape, bool)\n    else:\n        mask = np.asanyarray(mask, dtype=bool)\n        n_pixels = np.sum(mask)\n        if mask.shape != image.shape:\n            message = (\"`mask` (shape {}) must have same shape as \"\n                       \"`image` (shape {})\".format(mask.shape, image.shape))\n            raise ValueError(message)\n    if markers is None:\n        markers_bool = local_minima(image, connectivity=connectivity) * mask\n        footprint = ndi.generate_binary_structure(markers_bool.ndim, connectivity)\n        markers = ndi.label(markers_bool, structure=footprint)[0]\n    elif not isinstance(markers, (np.ndarray, list, tuple)):\n        # not array-like, assume int\n        # given int, assume that number of markers *within mask*.\n        markers = regular_seeds(image.shape,\n                                int(markers / (n_pixels / image.size)))\n        markers *= mask\n    else:\n        markers = np.asanyarray(markers) * mask\n        if markers.shape != image.shape:\n            message = (\"`markers` (shape {}) must have same shape as \"\n                       \"`image` (shape {})\".format(markers.shape, image.shape))\n            raise ValueError(message)\n    return (image.astype(np.float64),\n            markers.astype(np.int32),\n            mask.astype(np.int8))\n\n\ndef watershed(image, markers=None, connectivity=1, offset=None, mask=None,\n              compactness=0, watershed_line=False):\n    \"\"\"Find watershed basins in `image` flooded from given `markers`.\n\n    Parameters\n    ----------\n    image : ndarray (2-D, 3-D, ...)\n        Data array where the lowest value points are labeled first.\n    markers : int, or ndarray of int, same shape as `image`, optional\n        The desired number of markers, or an array marking the basins with the\n        values to be assigned in the label matrix. Zero means not a marker. If\n        ``None`` (no markers given), the local minima of the image are used as\n        markers.\n    connectivity : ndarray, optional\n        An array with the same number of dimensions as `image` whose\n        non-zero elements indicate neighbors for connection.\n        Following the scipy convention, default is a one-connected array of\n        the dimension of the image.\n    offset : array_like of shape image.ndim, optional\n        offset of the connectivity (one offset per dimension)\n    mask : ndarray of bools or 0s and 1s, optional\n        Array of same shape as `image`. Only points at which mask == True\n        will be labeled.\n    compactness : float, optional\n        Use compact watershed [3]_ with given compactness parameter.\n        Higher values result in more regularly-shaped watershed basins.\n    watershed_line : bool, optional\n        If watershed_line is True, a one-pixel wide line separates the regions\n        obtained by the watershed algorithm. The line has the label 0.\n\n    Returns\n    -------\n    out : ndarray\n        A labeled matrix of the same type and shape as markers\n\n    See Also\n    --------\n    skimage.segmentation.random_walker : random walker segmentation\n        A segmentation algorithm based on anisotropic diffusion, usually\n        slower than the watershed but with good results on noisy data and\n        boundaries with holes.\n\n    Notes\n    -----\n    This function implements a watershed algorithm [1]_ [2]_ that apportions\n    pixels into marked basins. The algorithm uses a priority queue to hold\n    the pixels with the metric for the priority queue being pixel value, then\n    the time of entry into the queue - this settles ties in favor of the\n    closest marker.\n\n    Some ideas taken from\n    Soille, \"Automated Basin Delineation from Digital Elevation Models Using\n    Mathematical Morphology\", Signal Processing 20 (1990) 171-182\n\n    The most important insight in the paper is that entry time onto the queue\n    solves two problems: a pixel should be assigned to the neighbor with the\n    largest gradient or, if there is no gradient, pixels on a plateau should\n    be split between markers on opposite sides.\n\n    This implementation converts all arguments to specific, lowest common\n    denominator types, then passes these to a C algorithm.\n\n    Markers can be determined manually, or automatically using for example\n    the local minima of the gradient of the image, or the local maxima of the\n    distance function to the background for separating overlapping objects\n    (see example).\n\n    References\n    ----------\n    .. [1] https://en.wikipedia.org/wiki/Watershed_%28image_processing%29\n\n    .. [2] http://cmm.ensmp.fr/~beucher/wtshed.html\n\n    .. [3] Peer Neubert & Peter Protzel (2014). Compact Watershed and\n           Preemptive SLIC: On Improving Trade-offs of Superpixel Segmentation\n           Algorithms. ICPR 2014, pp 996-1001. :DOI:`10.1109/ICPR.2014.181`\n           https://www.tu-chemnitz.de/etit/proaut/publications/cws_pSLIC_ICPR.pdf\n\n    Examples\n    --------\n    The watershed algorithm is useful to separate overlapping objects.\n\n    We first generate an initial image with two overlapping circles:\n\n    >>> x, y = np.indices((80, 80))\n    >>> x1, y1, x2, y2 = 28, 28, 44, 52\n    >>> r1, r2 = 16, 20\n    >>> mask_circle1 = (x - x1)**2 + (y - y1)**2 < r1**2\n    >>> mask_circle2 = (x - x2)**2 + (y - y2)**2 < r2**2\n    >>> image = np.logical_or(mask_circle1, mask_circle2)\n\n    Next, we want to separate the two circles. We generate markers at the\n    maxima of the distance to the background:\n\n    >>> from scipy import ndimage as ndi\n    >>> distance = ndi.distance_transform_edt(image)\n    >>> from skimage.feature import peak_local_max\n    >>> local_maxi = peak_local_max(distance, labels=image,\n    ...                             footprint=np.ones((3, 3)),\n    ...                             indices=False)\n    >>> markers = ndi.label(local_maxi)[0]\n\n    Finally, we run the watershed on the image and markers:\n\n    >>> labels = watershed(-distance, markers, mask=image)\n\n    The algorithm works also for 3-D images, and can be used for example to\n    separate overlapping spheres.\n    \"\"\"\n    image, markers, mask = _validate_inputs(image, markers, mask, connectivity)\n    connectivity, offset = _validate_connectivity(image.ndim, connectivity,\n                                                  offset)\n\n    # pad the image, markers, and mask so that we can use the mask to\n    # keep from running off the edges\n    pad_width = [(p, p) for p in offset]\n    image = np.pad(image, pad_width, mode='constant')\n    mask = np.pad(mask, pad_width, mode='constant').ravel()\n    output = np.pad(markers, pad_width, mode='constant')\n\n    flat_neighborhood = _offsets_to_raveled_neighbors(\n        image.shape, connectivity, center=offset)\n    marker_locations = np.flatnonzero(output)\n    image_strides = np.array(image.strides, dtype=np.intp) // image.itemsize\n\n    _watershed_cy.watershed_raveled(image.ravel(),\n                                    marker_locations, flat_neighborhood,\n                                    mask, image_strides, compactness,\n                                    output.ravel(),\n                                    watershed_line)\n\n    output = crop(output, pad_width, copy=True)\n\n    return output\n", "path": "skimage/segmentation/_watershed.py"}]}