Repository: scikit-image/scikit-image

Issue:
`segmentation.watershed` returns wrong data type
### Description:

The documentation of `segmentation.watershed` says that:

> ### Returns
>   **out**: ndarray
>   A labeled matrix of the same type and shape as markers

[[0.18.x]](https://scikit-image.org/docs/0.18.x/api/skimage.segmentation.html#skimage.segmentation.watershed) [[0.19.x]](https://scikit-image.org/docs/0.19.x/api/skimage.segmentation.html#skimage.segmentation.watershed)

I have tested this with 0.18.1:

```python
import skimage.segmentation
import numpy as np
print(skimage.segmentation.watershed(np.zeros((100, 100)), np.zeros((100, 100), np.uint16)).dtype)
```

Gives `int32` but `uint16` is expected.

### Way to reproduce:

```Python
import skimage.segmentation
import numpy as np
print(skimage.segmentation.watershed(np.zeros((100, 100)), np.zeros((100, 100), np.uint16)).dtype)
```


### Traceback or output:

```Shell
int32
```


### Version information:

```Shell
3.8.5 (default, Sep  4 2020, 07:30:14) 
[GCC 7.3.0]
Linux-5.8.0-36-generic-x86_64-with-glibc2.10
scikit-image version: 0.18.1
numpy version: 1.20.3
```



Discussion:
Confirmed on `0.20.0.dev0+git20221013.385b3cae5`. Could be fixed by returning correct dtype (ideal) or by changing docs.


Resolving patch:
diff --git a/skimage/segmentation/_watershed.py b/skimage/segmentation/_watershed.py
--- a/skimage/segmentation/_watershed.py
+++ b/skimage/segmentation/_watershed.py
@@ -79,7 +79,7 @@ def _validate_inputs(image, markers, mask, connectivity):
                        f'shape as `image` (shape {image.shape})')
             raise ValueError(message)
     return (image.astype(np.float64),
-            markers.astype(np.int32),
+            markers,
             mask.astype(np.int8))
 
 


Test patch:
diff --git a/skimage/segmentation/tests/test_watershed.py b/skimage/segmentation/tests/test_watershed.py
--- a/skimage/segmentation/tests/test_watershed.py
+++ b/skimage/segmentation/tests/test_watershed.py
@@ -392,6 +392,15 @@ def test_watershed12(self):
         for lab, area in zip(range(4), [34,74,74,74]):
             self.assertTrue(np.sum(ws == lab) == area)
 
+    def test_watershed_input_not_modified(self):
+        """Test to ensure input markers are not modified."""
+        image = np.random.default_rng().random(size=(21, 21))
+        markers = np.zeros((21, 21), dtype=np.uint8)
+        markers[[5, 5, 15, 15], [5, 15, 5, 15]] = [1, 2, 3, 4]
+        original_markers = np.copy(markers)
+        result = watershed(image, markers)
+        np.testing.assert_equal(original_markers, markers)
+        assert not np.all(result == markers)
 
 
 def test_compact_watershed():
@@ -426,6 +435,17 @@ def test_numeric_seed_watershed():
     np.testing.assert_equal(compact, expected)
 
 
+@pytest.mark.parametrize(
+    'dtype', [np.uint8, np.int8, np.uint16, np.int16,
+              np.uint32, np.int32, np.uint64, np.int64]
+)
+def test_watershed_output_dtype(dtype):
+    image = np.zeros((100, 100))
+    markers = np.zeros((100, 100), dtype)
+    out = watershed(image, markers)
+    assert out.dtype == markers.dtype
+
+
 def test_incorrect_markers_shape():
     image = np.ones((5, 6))
     markers = np.ones((5, 7))