internlm/SWE-Fixer-Train-110K huggingface dataset:
Repository: scikit-image/scikit-image

Issue:
0.14.2 test suite fails with `NameError: global name 'osp'`
## Description

The test suite does not pass. As far as I know `osp` is a common alias for `os.path`. Is this a typo in the code? Or related to the base python version?

## Way to reproduce
```python
pytest -vv
```

## Version information
```python
2.7.16 (default, Mar  4 2019, 19:30:43) 
[GCC 8.2.0]
Linux-4.20.2-gentoo-x86_64-Intel-R-_Core-TM-_i7-8550U_CPU_@_1.80GHz-with-gentoo-2.6
scikit-image version: 0.14.2
numpy version: 1.16.1
```
OR
```python
3.6.8 (default, Mar  4 2019, 19:32:41) 
[GCC 8.2.0]
Linux-4.20.2-gentoo-x86_64-Intel-R-_Core-TM-_i7-8550U_CPU_@_1.80GHz-with-gentoo-2.6
scikit-image version: 0.14.2
numpy version: 1.16.1
```
## My output
[build.log](https://github.com/scikit-image/scikit-image/files/2937545/build.log)





Discussion:

Resolving patch:
diff --git a/skimage/__init__.py b/skimage/__init__.py
--- a/skimage/__init__.py
+++ b/skimage/__init__.py
@@ -135,6 +135,7 @@ def _test(doctest=False, verbose=False):
 
 def _raise_build_error(e):
     # Raise a comprehensible error
+    import os.path as osp
     local_dir = osp.split(__file__)[0]
     msg = _STANDARD_MSG
     if local_dir == "skimage":


Test patch:
Repository: scikit-image/scikit-image

Issue:
Update draw.polygon example
## Description

This SO question shows that polygons are considered closed by default by `draw.polygon`, but our docstring example repeats the first vertex for no good reason, which is confusing:

https://stackoverflow.com/questions/55114005/skimage-polygon-function-why-does-the-last-vertice-repeats-in-the-polygon-docum

I suggest we remove the trailing [1, 1] from the example.


Discussion:
:+1: 

Resolving patch:
diff --git a/skimage/draw/draw.py b/skimage/draw/draw.py
--- a/skimage/draw/draw.py
+++ b/skimage/draw/draw.py
@@ -432,8 +432,8 @@ def polygon(r, c, shape=None):
     --------
     >>> from skimage.draw import polygon
     >>> img = np.zeros((10, 10), dtype=np.uint8)
-    >>> r = np.array([1, 2, 8, 1])
-    >>> c = np.array([1, 7, 4, 1])
+    >>> r = np.array([1, 2, 8])
+    >>> c = np.array([1, 7, 4])
     >>> rr, cc = polygon(r, c)
     >>> img[rr, cc] = 1
     >>> img


Test patch:
Repository: scikit-image/scikit-image

Issue:
`canny` dtype issue
This behavior changed between 0.14 and 0.15.

```
from skimage import data, feature
out = feature.canny(data.coins())
```

`out` is a blank image!  Works fine if you first do `img_as_float`.  Likely has to do with switching to our own implementation of gaussian filtering in canny.


Discussion:

Resolving patch:
diff --git a/skimage/feature/_canny.py b/skimage/feature/_canny.py
--- a/skimage/feature/_canny.py
+++ b/skimage/feature/_canny.py
@@ -157,12 +157,12 @@ def canny(image, sigma=1., low_threshold=None, high_threshold=None, mask=None,
     dtype_max = dtype_limits(image, clip_negative=False)[1]
 
     if low_threshold is None:
-        low_threshold = 0.1 * dtype_max
+        low_threshold = 0.1
     else:
         low_threshold = low_threshold / dtype_max
 
     if high_threshold is None:
-        high_threshold = 0.2 * dtype_max
+        high_threshold = 0.2
     else:
         high_threshold = high_threshold / dtype_max
 


Test patch:
diff --git a/skimage/feature/tests/test_canny.py b/skimage/feature/tests/test_canny.py
--- a/skimage/feature/tests/test_canny.py
+++ b/skimage/feature/tests/test_canny.py
@@ -104,3 +104,13 @@ def test_invalid_use_quantiles(self):
 
         self.assertRaises(ValueError, F.canny, image, use_quantiles=True,
                           low_threshold=0.5, high_threshold=-100)
+
+    def test_dtype(self):
+        """Check that the same output is produced regardless of image dtype."""
+        image_uint8 = data.camera()
+        image_float = img_as_float(image_uint8)
+
+        result_uint8 = F.canny(image_uint8)
+        result_float = F.canny(image_float)
+
+        assert_equal(result_uint8, result_float)
Repository: scikit-image/scikit-image

Issue:
Handle `normed` to `density` deprecations in `histogram` 
## Description
See https://github.com/scikit-image/scikit-image/pull/3427 and the related issues.



Discussion:
This is about matplotlib

Especially this comment: https://github.com/scikit-image/scikit-image/pull/3427#discussion_r221456658

Resolving patch:
diff --git a/doc/examples/features_detection/plot_local_binary_pattern.py b/doc/examples/features_detection/plot_local_binary_pattern.py
--- a/doc/examples/features_detection/plot_local_binary_pattern.py
+++ b/doc/examples/features_detection/plot_local_binary_pattern.py
@@ -107,7 +107,7 @@ def highlight_bars(bars, indexes):
 
 def hist(ax, lbp):
     n_bins = int(lbp.max() + 1)
-    return ax.hist(lbp.ravel(), normed=True, bins=n_bins, range=(0, n_bins),
+    return ax.hist(lbp.ravel(), density=True, bins=n_bins, range=(0, n_bins),
                    facecolor='0.5')
 
 


Test patch:
Repository: scikit-image/scikit-image

Issue:
document the use of circle_perimeter_aa with color image
## Description

I tried using circle_perimeter_aa with a color image, but ran into broadcasting issues. 

Is there a clean way to do this:

1. with a black and white circle?
2. with a color circle like (21, 244, 238)?

Here is my attempt:

```
import numpy as np
import skimage.draw as skd
img = np.zeros((500, 500, 3), dtype=np.double)
rr, cc, val = skd.circle_perimeter_aa(60, 40, 30)
img[rr, cc] = val
```

```
ValueError: shape mismatch: value array of shape (344,) could not be broadcast to indexing result of shape (344,3)
```

The closest I could get to something with the right shape is this:

```
aa = np.tile(np.expand_dims(aa, axis=-1), (1, 3)) * (21, 244, 238)
```

but I think that's incorrect....


Discussion:
You need:

```
img[rr, cc] = val[:, np.newaxis] * [1, 0, 0]
```

or

```
skd.set_color(img, (rr, cc), [1, 0, 0], alpha=val)
```

But, agreed, how to manipulate color images should be included as an example of that function, and of all drawing functions.
Worked great, thanks!

```python
rr, cc, aa = circle_perimeter_aa(coordinate[0], coordinate[1], 10, shape=frame.shape)
set_color(frame, (rr, cc), [0, 255, 255], alpha=aa)
```

Could you clarify where the origin is in this API's documentation as well?

Am I correct that the origin in the top left with coordinates ordered (y, x) where +y is down from the top left corner and +x is right from the top left corner?

Resolving patch:
diff --git a/skimage/draw/draw.py b/skimage/draw/draw.py
--- a/skimage/draw/draw.py
+++ b/skimage/draw/draw.py
@@ -550,6 +550,9 @@ def circle_perimeter_aa(r, c, radius, shape=None):
     Wu's method draws anti-aliased circle. This implementation doesn't use
     lookup table optimization.
 
+    Use the function ``draw.set_color`` to apply ``circle_perimeter_aa``
+    results to color images.
+
     References
     ----------
     .. [1] X. Wu, "An efficient antialiasing technique", In ACM SIGGRAPH
@@ -572,6 +575,11 @@ def circle_perimeter_aa(r, c, radius, shape=None):
            [  0,   0,  60, 211, 255, 211,  60,   0,   0,   0],
            [  0,   0,   0,   0,   0,   0,   0,   0,   0,   0],
            [  0,   0,   0,   0,   0,   0,   0,   0,   0,   0]], dtype=uint8)
+
+    >>> from skimage import data, draw
+    >>> image = data.chelsea()
+    >>> rr, cc, val = draw.circle_perimeter_aa(r=100, c=100, radius=75)
+    >>> draw.set_color(image, (rr, cc), [1, 0, 0], alpha=val)
     """
     return _circle_perimeter_aa(r, c, radius, shape)
 


Test patch:
Repository: scikit-image/scikit-image

Issue:
`view_as_windows` incorrectly assumes that a contiguous array is needed
See https://github.com/numpy/numpy/pull/10771#issuecomment-390881027

Mea culpa.



Discussion:
`view_as_blocks` too
Turns out my "mea culpa" is only applicable to my reviewing at the time, but if anything that may be worse.
@stefanv Is the fix as simple as removing the condition?
Yes

Resolving patch:
diff --git a/skimage/util/shape.py b/skimage/util/shape.py
--- a/skimage/util/shape.py
+++ b/skimage/util/shape.py
@@ -22,8 +22,7 @@ def view_as_blocks(arr_in, block_shape):
     Returns
     -------
     arr_out : ndarray
-        Block view of the input array.  If `arr_in` is non-contiguous, a copy
-        is made.
+        Block view of the input array.
 
     Examples
     --------
@@ -88,13 +87,6 @@ def view_as_blocks(arr_in, block_shape):
         raise ValueError("'block_shape' is not compatible with 'arr_in'")
 
     # -- restride the array to build the block view
-
-    if not arr_in.flags.contiguous:
-        warn(RuntimeWarning("Cannot provide views on a non-contiguous input "
-                            "array without copying."), stacklevel=2)
-
-    arr_in = np.ascontiguousarray(arr_in)
-
     new_shape = tuple(arr_shape // block_shape) + tuple(block_shape)
     new_strides = tuple(arr_in.strides * block_shape) + arr_in.strides
 
@@ -125,8 +117,7 @@ def view_as_windows(arr_in, window_shape, step=1):
     Returns
     -------
     arr_out : ndarray
-        (rolling) window view of the input array.   If `arr_in` is
-        non-contiguous, a copy is made.
+        (rolling) window view of the input array.
 
     Notes
     -----
@@ -242,12 +233,6 @@ def view_as_windows(arr_in, window_shape, step=1):
         raise ValueError("`window_shape` is too small")
 
     # -- build rolling window view
-    if not arr_in.flags.contiguous:
-        warn(RuntimeWarning("Cannot provide views on a non-contiguous input "
-                            "array without copying."), stacklevel=2)
-
-    arr_in = np.ascontiguousarray(arr_in)
-
     slices = tuple(slice(None, None, st) for st in step)
     window_strides = np.array(arr_in.strides)
 


Test patch:
diff --git a/skimage/util/tests/test_shape.py b/skimage/util/tests/test_shape.py
--- a/skimage/util/tests/test_shape.py
+++ b/skimage/util/tests/test_shape.py
@@ -147,8 +147,25 @@ def test_views_non_contiguous():
     A = np.arange(16).reshape((4, 4))
     A = A[::2, :]
 
-    assert_warns(RuntimeWarning, view_as_blocks, A, (2, 2))
-    assert_warns(RuntimeWarning, view_as_windows, A, (2, 2))
+    res_b = view_as_blocks(A, (2, 2))
+    res_w = view_as_windows(A, (2, 2))
+    print(res_b)
+    print(res_w)
+
+    expected_b = [[[[0,  1],
+                    [8,  9]],
+                   [[2,  3],
+                    [10, 11]]]]
+
+    expected_w = [[[[ 0,  1],
+                    [ 8,  9]],
+                   [[ 1,  2],
+                    [ 9, 10]],
+                   [[ 2,  3],
+                    [10, 11]]]]
+
+    assert_equal(res_b, expected_b)
+    assert_equal(res_w, expected_w)
 
 
 def test_view_as_windows_step_tuple():
Repository: scikit-image/scikit-image

Issue:
Regression in threshold_multiotsu
## Description

During my exploration for fixing #3980 I observed that `threshold_multiotsu` gives a different result on the `astronaut` image thanks to @sciunto https://github.com/scikit-image/scikit-image/issues/3980#issuecomment-521624136_

In fact, after refactoring,  the new version gives `0.45507812` while the original version gives `0.439453125`.

I also noticed that `threshold_multiotsu` does not warn the user that the method doesn't handle color images and do not raise error if the image has only one value as `threshold_otsu` does!

## Way to reproduce
```python
In [1]: from skimage.filters import threshold_multiotsu, threshold_otsu                                 

In [2]: from skimage.color import rgb2gray                                                              

In [3]: from skimage.data import moon, astronaut                                                        

In [4]: img = rgb2gray(astronaut())                                                                     

In [5]: threshold_multiotsu(img, 2)                                                                     
Out[5]: array([0.45507812])

```

## Version information

```                                                                               
3.7.3 (default, Mar 27 2019, 22:11:17) 
[GCC 7.3.0]
Linux-4.15.0-60-generic-x86_64-with-debian-buster-sid
scikit-image version: 0.16.dev0
numpy version: 1.16.4
```




Discussion:

Resolving patch:
diff --git a/skimage/filters/thresholding.py b/skimage/filters/thresholding.py
--- a/skimage/filters/thresholding.py
+++ b/skimage/filters/thresholding.py
@@ -1151,8 +1151,8 @@ def threshold_multiotsu(image, classes=3, nbins=256):
     momS = np.diagflat(np.arange(nbins) * prob)
 
     # step 2: calculating the first row.
-    momP[1, 2:] = np.cumsum(prob[2:])
-    momS[1, 2:] = np.cumsum(np.arange(2, nbins) * prob[2:])
+    momP[1, 2:] = prob[1] + np.cumsum(prob[2:])
+    momS[1, 2:] = prob[1] + np.cumsum(np.arange(2, nbins) * prob[2:])
 
     # step 3: the other rows are recursively computed as:
     # A[i, j] = A[1, j] - A[1, i-1] for A in {momP, momS};  i > 1 and j > i.


Test patch:
diff --git a/skimage/filters/tests/test_thresholding.py b/skimage/filters/tests/test_thresholding.py
--- a/skimage/filters/tests/test_thresholding.py
+++ b/skimage/filters/tests/test_thresholding.py
@@ -4,6 +4,7 @@
 
 from skimage import util
 from skimage import data
+from skimage import color
 from skimage.draw import circle
 from skimage._shared._warnings import expected_warnings
 from skimage.filters.thresholding import (threshold_local,
@@ -563,6 +564,9 @@ def test_multiotsu_output():
     thresholds = [64, 128]
     assert np.array_equal(thresholds, threshold_multiotsu(image))
 
+    image = color.rgb2gray(data.astronaut())
+    assert_almost_equal(threshold_multiotsu(image, 2), 0.43945312)
+
 
 @pytest.mark.parametrize("thresholding, lower, upper", [
     (threshold_otsu, 86, 88),
Repository: scikit-image/scikit-image

Issue:
DOC: simple backquotes have no special rendering in the doc
# Work plan

In skimage/

* [ ] draw/      
* [ ] external/  
* [x] filters/  #4127
* [ ] graph/       
* [ ] io/       
* [ ] metrics/     
* [ ] novice/       
* [ ] restoration/  
* [ ] segmentation/  
* [ ] _shared/    
* [ ] util/
* [ ] color/     
* [ ] data/       
* [ ] exposure/  
* [ ] feature/   
* [ ] future/   
* [ ] measure/  
* [ ] morphology/  
* [ ] transform/  
* [ ] viewer/

In doc


## Description

Example:

[Source code](https://github.com/scikit-image/scikit-image/blob/v0.15.0/skimage/color/colorconv.py#L70)
There is one word with simple backquotes and one with double.

Here is the rendering:

https://scikit-image.org/docs/stable/api/skimage.color.html#skimage.color.guess_spatial_dimensions

![Module color — skimage v0 15 0 docs](https://user-images.githubusercontent.com/335370/63651201-97d3da00-c752-11e9-812d-6853af6357c9.png)


The html code is

```
 
 <tr class="field-even field"><th class="field-name">Returns:</th><td class="field-body"><dl class="first docutils">
 <dt><strong>spatial_dims</strong> <span class="classifier-delimiter">:</span> <span class="classifier">int or None</span></dt>
 <dd><p class="first last">The number of spatial dimensions of <cite>image</cite>. If ambiguous, the value
 is <code class="docutils literal notranslate"><span class="pre">None</span></code>.</p>

```

Simple backquotes give `<cite>image</cite>`


Discussion:
This is a sad but expected difference between restructured text and markdown. The correct formatting is with double backticks. Single backticks are for links. See http://www.sphinx-doc.org/en/master/usage/restructuredtext/basics.html#external-links
Thanks for the pointer. This turns into an issue: fix all the single backticks (I know I used them in PRs...). 

Resolving patch:
diff --git a/doc/source/conf.py b/doc/source/conf.py
--- a/doc/source/conf.py
+++ b/doc/source/conf.py
@@ -138,7 +138,7 @@
 exclude_trees = []
 
 # The reST default role (used for this markup: `text`) to use for all documents.
-#default_role = None
+default_role = "autolink"
 
 # If true, '()' will be appended to :func: etc. cross-reference text.
 #add_function_parentheses = True


Test patch:
Repository: scikit-image/scikit-image

Issue:
Orientation in plot_active_contours example is broken
## Description

See https://scikit-image.org/docs/dev/auto_examples/edges/plot_active_contours.html.
Originally reported by @aisosalo.



Discussion:
caused by #4035

Resolving patch:
diff --git a/doc/examples/edges/plot_active_contours.py b/doc/examples/edges/plot_active_contours.py
--- a/doc/examples/edges/plot_active_contours.py
+++ b/doc/examples/edges/plot_active_contours.py
@@ -47,8 +47,8 @@
 
 fig, ax = plt.subplots(figsize=(7, 7))
 ax.imshow(img, cmap=plt.cm.gray)
-ax.plot(init[:, 0], init[:, 1], '--r', lw=3)
-ax.plot(snake[:, 0], snake[:, 1], '-b', lw=3)
+ax.plot(init[:, 1], init[:, 0], '--r', lw=3)
+ax.plot(snake[:, 1], snake[:, 0], '-b', lw=3)
 ax.set_xticks([]), ax.set_yticks([])
 ax.axis([0, img.shape[1], img.shape[0], 0])
 
@@ -72,8 +72,8 @@
 
 fig, ax = plt.subplots(figsize=(9, 5))
 ax.imshow(img, cmap=plt.cm.gray)
-ax.plot(init[:, 0], init[:, 1], '--r', lw=3)
-ax.plot(snake[:, 0], snake[:, 1], '-b', lw=3)
+ax.plot(init[:, 1], init[:, 0], '--r', lw=3)
+ax.plot(snake[:, 1], snake[:, 0], '-b', lw=3)
 ax.set_xticks([]), ax.set_yticks([])
 ax.axis([0, img.shape[1], img.shape[0], 0])
 


Test patch:
Repository: scikit-image/scikit-image

Issue:
Stop probability in ransac
## Description

This may be a stupid question, but what is 'm' in the formula for dynamic number of trials in documentation of RANSAC?

https://github.com/scikit-image/scikit-image/blob/b7a1fde540d90d6e8009764abeec3e89c8b76928/skimage/measure/fit.py#L691



Discussion:
Cc @ahojnnes 
This must be clarified in the docstring. The computation is done in another function and the corresponding line is https://github.com/scikit-image/scikit-image/blob/b7a1fde540d90d6e8009764abeec3e89c8b76928/skimage/measure/fit.py#L606

m is the min sample.

Resolving patch:
diff --git a/skimage/measure/fit.py b/skimage/measure/fit.py
--- a/skimage/measure/fit.py
+++ b/skimage/measure/fit.py
@@ -691,8 +691,8 @@ def ransac(data, model_class, min_samples, residual_threshold,
             N >= log(1 - probability) / log(1 - e**m)
 
         where the probability (confidence) is typically set to a high value
-        such as 0.99, and e is the current fraction of inliers w.r.t. the
-        total number of samples.
+        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.
     random_state : int, RandomState instance or None, optional
         If int, random_state is the seed used by the random number generator;
         If RandomState instance, random_state is the random number generator;


Test patch:
Repository: scikit-image/scikit-image

Issue:
use_quantiles description in canny is incorrect
## Description
The description of `use_quantiles` is "If True then treat low_threshold and high_threshold as quantiles of the edge magnitude image, rather than absolute edge magnitude values. **If True then the thresholds must be in the range [0, 1].**"

However, he thresholds must be in the range [0, maximum of the image's dtype ]

## Way to reproduce
```python
from skimage import data
from skimage.feature import canny
image = data.camera()
edge_canny = canny(image, low_threshold=50, high_threshold=150, use_quantiles=True)
# No error is produced
```

## Cause
This happens because the thresholds are divided by maximum of the image's dtype (lines 163, 168 in [_canny.py](https://github.com/scikit-image/scikit-image/blob/master/skimage/feature/_canny.py))

## Probable solution
The probable solution is not to divide the thresholds if `use_quantiles` is True or just simpler change the description.

## Version information
```python
# your output here
3.7.3 (default, Sep  5 2019, 17:14:41) 
[Clang 11.0.0 (clang-1100.0.33.8)]
Darwin-19.0.0-x86_64-i386-64bit
scikit-image version: 0.16.2
numpy version: 1.17.3
```




Discussion:
Yikes! Thanks for the report, @pigunther! I think you are right that we should not divide by the dtype max.
To fix this issue, I propose in #4342 to add the `preserve_range` argument and to divide the thresholds only if `preserve_range` is True.

Resolving patch:
diff --git a/skimage/feature/_canny.py b/skimage/feature/_canny.py
--- a/skimage/feature/_canny.py
+++ b/skimage/feature/_canny.py
@@ -159,11 +159,17 @@ def canny(image, sigma=1., low_threshold=None, high_threshold=None, mask=None,
 
     if low_threshold is None:
         low_threshold = 0.1
+    elif use_quantiles:
+        if not(0.0 <= low_threshold <= 1.0):
+            raise ValueError("Quantile thresholds must be between 0 and 1.")
     else:
         low_threshold = low_threshold / dtype_max
 
     if high_threshold is None:
         high_threshold = 0.2
+    elif use_quantiles:
+        if not(0.0 <= high_threshold <= 1.0):
+            raise ValueError("Quantile thresholds must be between 0 and 1.")
     else:
         high_threshold = high_threshold / dtype_max
 


Test patch:
diff --git a/skimage/feature/tests/test_canny.py b/skimage/feature/tests/test_canny.py
--- a/skimage/feature/tests/test_canny.py
+++ b/skimage/feature/tests/test_canny.py
@@ -105,6 +105,11 @@ def test_invalid_use_quantiles(self):
         self.assertRaises(ValueError, F.canny, image, use_quantiles=True,
                           low_threshold=0.5, high_threshold=-100)
 
+        # Example from issue #4282
+        image = data.camera()
+        self.assertRaises(ValueError, F.canny, image, use_quantiles=True,
+                          low_threshold=50, high_threshold=150)
+
     def test_dtype(self):
         """Check that the same output is produced regardless of image dtype."""
         image_uint8 = data.camera()