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

Issue:
Figure of edge modes example is too small
in http://scikit-image.org/docs/dev/auto_examples/plot_edge_modes.html, all 5 subplots are on a single row, resulting in tiny windows. A 2-line plot would be better.



Discussion:
I'd like to work on this. Can I take this one?

@mronian Don't ask, go for it! :)

thanks @mronian !


Resolving patch:
diff --git a/doc/examples/transform/plot_edge_modes.py b/doc/examples/transform/plot_edge_modes.py
--- a/doc/examples/transform/plot_edge_modes.py
+++ b/doc/examples/transform/plot_edge_modes.py
@@ -7,10 +7,10 @@
 interpolation in routines such as `skimage.transform.rescale` and
 `skimage.transform.resize`.
 """
-from skimage._shared.interpolation import extend_image
-import skimage.data
-import matplotlib.pyplot as plt
 import numpy as np
+import matplotlib.pyplot as plt
+
+from skimage._shared.interpolation import extend_image
 
 img = np.zeros((16, 16))
 img[:8, :8] += 1
@@ -20,18 +20,19 @@
 img[8, 8] = 4
 
 modes = ['constant', 'edge', 'wrap', 'reflect', 'symmetric']
-fig, axes = plt.subplots(1, 5, figsize=(15, 5))
+fig, axes = plt.subplots(2, 3)
+axes = axes.flatten()
+
 for n, mode in enumerate(modes):
     img_extended = extend_image(img, pad=img.shape[0], mode=mode)
     axes[n].imshow(img_extended, cmap=plt.cm.gray, interpolation='nearest')
-    axes[n].plot([15.5, 15.5], [15.5, 31.5], 'y--', linewidth=0.5)
-    axes[n].plot([31.5, 31.5], [15.5, 31.5], 'y--', linewidth=0.5)
-    axes[n].plot([15.5, 31.5], [15.5, 15.5], 'y--', linewidth=0.5)
-    axes[n].plot([15.5, 31.5], [31.5, 31.5], 'y--', linewidth=0.5)
-    axes[n].set_axis_off()
-    axes[n].set_aspect('equal')
+    axes[n].plot([15.5, 15.5, 31.5, 31.5, 15.5],
+                 [15.5, 31.5, 31.5, 15.5, 15.5], 'y--', linewidth=0.5)
     axes[n].set_title(mode)
 
+for n in range(len(axes)):
+    axes[n].set_axis_off()
+    axes[n].set_aspect('equal')
+    
 plt.tight_layout()
-
 plt.show()


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

Issue:
threshold_otsu raises exception when image is one color
Tested against current HEAD:

``` pycon
>>> import numpy as np
>>> from skimage.filters import threshold_otsu
>>> threshold_otsu(np.array([1,2,3]))
1
>>> threshold_otsu(np.array([1,1,1]))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "…/skimage/filters/thresholding.py", line 140, in threshold_otsu
    idx = np.argmax(variance12)
  File "…/numpy/core/fromnumeric.py", line 968, in argmax
    return argmax(axis, out)
ValueError: attempt to get argmax of an empty sequence
```



Discussion:
Thanks for the report. Looks like at minimum this should be caught and a more informative error raised.


Resolving patch:
diff --git a/skimage/filters/thresholding.py b/skimage/filters/thresholding.py
--- a/skimage/filters/thresholding.py
+++ b/skimage/filters/thresholding.py
@@ -129,6 +129,12 @@ def threshold_otsu(image, nbins=256):
               "grayscale images; image shape {0} looks like an RGB image"
         warnings.warn(msg.format(image.shape))
 
+    # Check if the image is multi-colored or not
+    if image.min() == image.max():
+        raise TypeError("threshold_otsu is expected to work with images " \
+                        "having more than one color. The input image seems " \
+                        "to have just one color {0}.".format(image.min()))
+
     hist, bin_centers = histogram(image.ravel(), nbins)
     hist = hist.astype(float)
 


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
@@ -1,5 +1,7 @@
 import numpy as np
-from numpy.testing import assert_equal, assert_almost_equal
+from numpy.testing import (assert_equal,
+                           assert_almost_equal,
+                           assert_raises)
 
 import skimage
 from skimage import data
@@ -162,6 +164,11 @@ def test_otsu_astro_image():
     with expected_warnings(['grayscale']):
         assert 109 < threshold_otsu(img) < 111
 
+
+def test_otsu_one_color_image():
+    img = np.ones((10, 10), dtype=np.uint8)
+    assert_raises(TypeError, threshold_otsu, img)
+
 def test_li_camera_image():
     camera = skimage.img_as_ubyte(data.camera())
     assert 63 < threshold_li(camera) < 65
Repository: scikit-image/scikit-image

Issue:
Add comment clarifying use of strided output array for generic_filter RAG construction
See [here](https://github.com/scikit-image/scikit-image/pull/1826/files#r48343523).



Discussion:

Resolving patch:
diff --git a/skimage/future/graph/rag.py b/skimage/future/graph/rag.py
--- a/skimage/future/graph/rag.py
+++ b/skimage/future/graph/rag.py
@@ -143,6 +143,13 @@ def __init__(self, label_image=None, connectivity=1, data=None, **attr):
 
         if label_image is not None:
             fp = ndi.generate_binary_structure(label_image.ndim, connectivity)
+            # In the next ``ndi.generic_filter`` function, the kwarg
+            # ``output`` is used to provide a strided array with a single
+            # 64-bit floating point number, to which the function repeatedly
+            # writes. This is done because even if we don't care about the
+            # output, without this, a float array of the same shape as the
+            # input image will be created and that could be expensive in
+            # memory consumption.
             ndi.generic_filter(
                 label_image,
                 function=_add_edge_filter,


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

Issue:
DOC: Reduce size image in plot_inpaint
In reference to #1920 
- Reduce the size of the image in  doc/examples/filters/plot_inpaint.py to show more clearly the result of the algorithm.



Discussion:
OK, I fixed my virtualenv. Now, I can work on  a patch :)

@emmanuelle Is it something like this that you had in mind?

![fig](https://framapic.org/nPfLnaBJKyrR/hLq2iA5sd285)

Hopefully we can get rid of all that space in the middle.

From sphinx, it'll look like that. it's just that I used mpl GUI and depending on the window size, the save button gives different results.
![plot_inpaint_1](https://cloud.githubusercontent.com/assets/335370/12772698/c6edfd04-ca01-11e5-84ce-175edb5a166e.png)

@sciunto I'd also add one small rectangle over the the `hair`-area.
In literature, inpainting algorithms are usually evaluated on several types of underlying data:
1. homogenical regions _[addressed]_, 
2. sharp edges along and across the defect region _[addressed]_, 
3. textures _[that's what was missing earlier, but we should address here]_, 
4. regions with smooth gradients _[kind of addressed by the overall impression]_, 
5. texts _[nobody cares, really :)]_, etc. 

I also wanted to show how it works with the boundary conditions, so what's why the left region is there. You could add one more defect region in the corner.

P.S. @sciunto btw, are you using this algorithm? I'll be so glad if the answer is yes. :)

@soupault i'm not. I just looked at the new features (a bit late, I have to admit) and I catched a typo :)


Resolving patch:
diff --git a/doc/examples/filters/plot_inpaint.py b/doc/examples/filters/plot_inpaint.py
--- a/doc/examples/filters/plot_inpaint.py
+++ b/doc/examples/filters/plot_inpaint.py
@@ -26,13 +26,13 @@
 from skimage import data, color
 from skimage.restoration import inpaint
 
-image_orig = data.astronaut()
+image_orig = data.astronaut()[0:200, 0:200]
 
 # Create mask with three defect regions: left, middle, right respectively
 mask = np.zeros(image_orig.shape[:-1])
 mask[20:60, 0:20] = 1
-mask[200:300, 150:170] = 1
-mask[50:100, 400:430] = 1
+mask[160:180, 70:155] = 1
+mask[30:60, 170:195] = 1
 
 # Defect image over the same region in each color channel
 image_defect = image_orig.copy()
@@ -60,5 +60,5 @@
 ax3.imshow(image_result)
 ax3.axis('off')
 
-plt.tight_layout()
+fig.tight_layout()
 plt.show()


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

Issue:
Temporary file from file_or_url_context is not removed on error
In case error occured in file_or_url_context (source: https://github.com/scikit-image/scikit-image/blob/master/skimage/io/util.py#L23) on `u = urlopen(resource_name)` or `f.write(u.read())` (lines https://github.com/scikit-image/scikit-image/blob/master/skimage/io/util.py#L28-L29) temporary file created with `tempfile.NamedTemporaryFile(delete=False, suffix=ext)` will not be removed.



Discussion:

Resolving patch:
diff --git a/skimage/io/util.py b/skimage/io/util.py
--- a/skimage/io/util.py
+++ b/skimage/io/util.py
@@ -24,10 +24,11 @@ def file_or_url_context(resource_name):
     """Yield name of file from the given resource (i.e. file or url)."""
     if is_url(resource_name):
         _, ext = os.path.splitext(resource_name)
-        with tempfile.NamedTemporaryFile(delete=False, suffix=ext) as f:
-            u = urlopen(resource_name)
-            f.write(u.read())
         try:
+            with tempfile.NamedTemporaryFile(delete=False, suffix=ext) as f:
+                u = urlopen(resource_name)
+                f.write(u.read())
+            # f must be closed before yielding
             yield f.name
         finally:
             os.remove(f.name)


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

Issue:
Add description to RAG's merging example
## Description

Add description to RAG's merging example or, at least, hide `TODO` from the public.

See [webpage](http://scikit-image.org/docs/dev/auto_examples/segmentation/plot_boundary_merge.html#example-segmentation-plot-boundary-merge-py) or [source code](https://github.com/scikit-image/scikit-image/blob/master/doc/examples/segmentation/plot_boundary_merge.py#L6) for some fun :).



Discussion:
Oh crap. I am guilty of that mistake. 

Me too! LOL #codereviewfail

@vighneshbirodkar Would you like to make a PR with a text for that example?

@sciunto I'm making one right now


Resolving patch:
diff --git a/doc/examples/segmentation/plot_boundary_merge.py b/doc/examples/segmentation/plot_boundary_merge.py
--- a/doc/examples/segmentation/plot_boundary_merge.py
+++ b/doc/examples/segmentation/plot_boundary_merge.py
@@ -3,7 +3,15 @@
 Hierarchical Merging of Region Boundary RAGs
 ============================================
 
-TODO: Description
+This example demonstrates how to perform hierarchical merging on region
+boundary Region Adjacency Graphs (RAGs). Region boundary RAGs can be
+constructed with the :py:func:`skimage.future.graph.rag_boundary` function.
+The regions with the lowest edge weights are successively merged until there
+is no edge with weight less than ``thresh``. The hierarchical merging is done
+through the :py:func:`skimage.future.graph.merge_hierarchical` function.
+For an example of how to construct region boundary based RAGs, see
+:any:`plot_rag_boundary`.
+
 """
 
 from skimage import data, segmentation, filters, color
diff --git a/doc/examples/segmentation/plot_rag_boundary.py b/doc/examples/segmentation/plot_rag_boundary.py
--- a/doc/examples/segmentation/plot_rag_boundary.py
+++ b/doc/examples/segmentation/plot_rag_boundary.py
@@ -3,8 +3,13 @@
 Region Boundary based RAGs
 ==========================
 
-This example demonstrates construction of region boundary based RAGs with the
-`rag_boundary` function.
+Construct a region boundary RAG with the ``rag_boundary`` function. The
+function  :py:func:`skimage.future.graph.rag_boundary` takes an
+``edge_map`` argument, which gives the significance of a feature (such as
+edges) being present at each pixel. In a region boundary RAG, the edge weight
+between two regions is the average value of the corresponding pixels in
+``edge_map`` along their shared boundary.
+
 """
 from skimage.future import graph
 from skimage import data, segmentation, color, filters, io


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

Issue:
Add bbox_area in region properties?
From #2116 
## Description

maybe you should add something like bbox_area in region properties. I know about label.image.size, but it not obvious to.



Discussion:
:+1: from me.


Resolving patch:
diff --git a/skimage/measure/_regionprops.py b/skimage/measure/_regionprops.py
--- a/skimage/measure/_regionprops.py
+++ b/skimage/measure/_regionprops.py
@@ -21,6 +21,7 @@
 PROPS = {
     'Area': 'area',
     'BoundingBox': 'bbox',
+    'BoundingBoxArea': 'bbox_area',
     'CentralMoments': 'moments_central',
     'Centroid': 'centroid',
     'ConvexArea': 'convex_area',
@@ -121,6 +122,9 @@ def bbox(self):
         return tuple([self._slice[i].start for i in range(self._ndim)] +
                      [self._slice[i].stop for i in range(self._ndim)])
 
+    def bbox_area(self):
+        return self._label_image.size
+
     def centroid(self):
         return tuple(self.coords.mean(axis=0))
 
@@ -374,6 +378,8 @@ def regionprops(label_image, intensity_image=None, cache=True):
         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)``.
+    **bbox_area** : int
+        Number of pixels of bounding box.
     **centroid** : array
         Centroid coordinate tuple ``(row, col)``.
     **convex_area** : int


Test patch:
diff --git a/skimage/measure/tests/test_regionprops.py b/skimage/measure/tests/test_regionprops.py
--- a/skimage/measure/tests/test_regionprops.py
+++ b/skimage/measure/tests/test_regionprops.py
@@ -77,6 +77,9 @@ def test_bbox():
     bbox = regionprops(SAMPLE_3D)[0].bbox
     assert_array_almost_equal(bbox, (1, 1, 1, 4, 3, 3))
 
+def test_bbox_area():
+    bbox_area = regionprops(SAMPLE)[0].bbox_area
+    assert_array_almost_equal(bbox_area, SAMPLE.shape[0] * SAMPLE.shape[1])
 
 def test_moments_central():
     mu = regionprops(SAMPLE)[0].moments_central
Repository: scikit-image/scikit-image

Issue:
Remove unused `_shared.extend_image`
## Description

I propose to remove `extend_image` (https://github.com/scikit-image/scikit-image/blob/master/skimage/_shared/interpolation.pyx#L12), as it duplicates the behaviour of `skimage.util.pad`, and it is not really used anywhere (https://github.com/scikit-image/scikit-image/search?utf8=%E2%9C%93&q=extend_image).



Discussion:
👍 ! It probably predates pad but now is definitely superseded by it.


Resolving patch:
diff --git a/doc/examples/transform/plot_edge_modes.py b/doc/examples/transform/plot_edge_modes.py
--- a/doc/examples/transform/plot_edge_modes.py
+++ b/doc/examples/transform/plot_edge_modes.py
@@ -10,7 +10,8 @@
 import numpy as np
 import matplotlib.pyplot as plt
 
-from skimage._shared.interpolation import extend_image
+from skimage.util import pad
+
 
 img = np.zeros((16, 16))
 img[:8, :8] += 1
@@ -21,18 +22,18 @@
 
 modes = ['constant', 'edge', 'wrap', 'reflect', 'symmetric']
 fig, axes = plt.subplots(2, 3)
-axes = axes.flatten()
+ax = axes.flatten()
 
 for n, mode in enumerate(modes):
-    img_extended = extend_image(img, pad=img.shape[0], mode=mode)
-    axes[n].imshow(img_extended, cmap=plt.cm.gray, interpolation='nearest')
-    axes[n].plot([15.5, 15.5, 31.5, 31.5, 15.5],
-                 [15.5, 31.5, 31.5, 15.5, 15.5], 'y--', linewidth=0.5)
-    axes[n].set_title(mode)
+    img_padded = pad(img, pad_width=img.shape[0], mode=mode)
+    ax[n].imshow(img_padded, cmap=plt.cm.gray, interpolation='nearest')
+    ax[n].plot([15.5, 15.5, 31.5, 31.5, 15.5],
+               [15.5, 31.5, 31.5, 15.5, 15.5], 'y--', linewidth=0.5)
+    ax[n].set_title(mode)
 
-for n in range(len(axes)):
-    axes[n].set_axis_off()
-    axes[n].set_aspect('equal')
+for a in ax:
+    a.set_axis_off()
+    a.set_aspect('equal')
     
 plt.tight_layout()
 plt.show()


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

Issue:
slightly confusing docstring for black_tophat
black_tophat is currently documented to return

```
    Returns
    -------
    opening : array, same shape and type as `image`
       The result of the black top filter.
```

The name of the return value should probably be changed to something like `out` (it's not an opening) and the text to `of the black top hat filter` (or whatever is used for the white tophat).



Discussion:
@anntzer That's right. Would you like to start a PR?

Also, for the return value, we can get inspiration from https://docs.scipy.org/doc/scipy-0.16.1/reference/generated/scipy.ndimage.morphology.black_tophat.html

Nah, it's yours 😃


Resolving patch:
diff --git a/skimage/morphology/grey.py b/skimage/morphology/grey.py
--- a/skimage/morphology/grey.py
+++ b/skimage/morphology/grey.py
@@ -427,8 +427,8 @@ def black_tophat(image, selem=None, out=None):
 
     Returns
     -------
-    opening : array, same shape and type as `image`
-       The result of the black top filter.
+    out : array, same shape and type as `image`
+        The result of the morphological black top hat.
 
     Examples
     --------


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

Issue:
Wavelet denoising fails on odd-sized dimension images
From @grlee77 https://github.com/scikit-image/scikit-image/pull/2461#issuecomment-273717628

If you truncate the odd-sized dimension from 451 to 450 this issue will not occur.  This is a known issue with odd-sized inputs with `dwtn/idwtn` (https://github.com/PyWavelets/pywt/issues/80)

The proper fix is probably for to have `denoise_wavelet` itself either:
- [ ] raise an error if any non-channels dimension of the input has odd size


@stsievert Would you like to fit that in a new PR?


Discussion:

Resolving patch:
diff --git a/skimage/restoration/_denoise.py b/skimage/restoration/_denoise.py
--- a/skimage/restoration/_denoise.py
+++ b/skimage/restoration/_denoise.py
@@ -429,6 +429,10 @@ def _wavelet_threshold(img, wavelet, threshold=None, sigma=None, mode='soft',
     """
     wavelet = pywt.Wavelet(wavelet)
 
+    # original_extent is used to workaround PyWavelets issue #80
+    # odd-sized input results in an image with 1 extra sample after waverecn
+    original_extent = [slice(s) for s in img.shape]
+
     # Determine the number of wavelet decomposition levels
     if wavelet_levels is None:
         # Determine the maximum number of possible levels for img
@@ -467,7 +471,7 @@ def _wavelet_threshold(img, wavelet, threshold=None, sigma=None, mode='soft',
                                                 mode=mode) for key in level}
                            for thresh, level in zip(threshold, dcoeffs)]
     denoised_coeffs = [coeffs[0]] + denoised_detail
-    return pywt.waverecn(denoised_coeffs, wavelet)
+    return pywt.waverecn(denoised_coeffs, wavelet)[original_extent]
 
 
 def denoise_wavelet(img, sigma=None, wavelet='db1', mode='soft',


Test patch:
diff --git a/skimage/restoration/tests/test_denoise.py b/skimage/restoration/tests/test_denoise.py
--- a/skimage/restoration/tests/test_denoise.py
+++ b/skimage/restoration/tests/test_denoise.py
@@ -323,7 +323,13 @@ def test_no_denoising_for_small_h():
 
 def test_wavelet_denoising():
     rstate = np.random.RandomState(1234)
-    for img, multichannel in [(astro_gray, False), (astro, True)]:
+
+    # version with one odd-sized dimension
+    astro_gray_odd = astro_gray[:, :-1]
+    astro_odd = astro[:, :-1]
+
+    for img, multichannel in [(astro_gray, False), (astro_gray_odd, False),
+                              (astro_odd, True)]:
         sigma = 0.1
         noisy = img + sigma * rstate.randn(*(img.shape))
         noisy = np.clip(noisy, 0, 1)
Repository: scikit-image/scikit-image

Issue:
Expose truncate parameter in skimage.filters.gaussian
[`skimage.filters.gaussian`](http://scikit-image.org/docs/dev/api/skimage.filters.html#skimage.filters.gaussian) calls into [`scipy.ndi.gaussian_filter`](https://docs.scipy.org/doc/scipy-0.15.1/reference/generated/scipy.ndimage.filters.gaussian_filter.html#scipy.ndimage.filters.gaussian_filter), however the underlying function takes in a `truncate` parameter, but this is not exposed in `skimage`.


Discussion:
@cancan101 Hi! Feel free to submit a PR!
It will require scipy 0.14. We will need to merge #2254 before. I agree with @soupault If you want to submit a PR, feel free :)
>It will require scipy 0.14

Hmm, why? There are ways to pass arguments without being explicit.
OK, we can always rewrite the function to make [0.13 and lower work](https://docs.scipy.org/doc/scipy-0.13.0/reference/generated/scipy.ndimage.filters.gaussian_filter.html#scipy.ndimage.filters.gaussian_filter), but if we want to take the easiest slope, with [0.14](https://docs.scipy.org/doc/scipy-0.13.0/reference/generated/scipy.ndimage.filters.gaussian_filter.html#scipy.ndimage.filters.gaussian_filter) it's as easy as adding two lines and we are close to bump scipy's version.

Frankly, I'm not a big fan to add code for workarounds when it could be avoided as it increases the effort both at the implementation stage and for maintenance. 
We now require 0.17! =)

Resolving patch:
diff --git a/skimage/filters/_gaussian.py b/skimage/filters/_gaussian.py
--- a/skimage/filters/_gaussian.py
+++ b/skimage/filters/_gaussian.py
@@ -19,8 +19,8 @@ def _convert_input(image, preserve_range):
 
 
 def gaussian(image, sigma=1, output=None, mode='nearest', cval=0,
-             multichannel=None, preserve_range=False):
-    """Multi-dimensional Gaussian filter
+             multichannel=None, preserve_range=False, truncate=4.0):
+    """Multi-dimensional Gaussian filter.
 
     Parameters
     ----------
@@ -50,6 +50,8 @@ def gaussian(image, sigma=1, output=None, mode='nearest', cval=0,
     preserve_range : bool, optional
         Whether to keep the original range of values. Otherwise, the input
         image is converted according to the conventions of `img_as_float`.
+    truncate : float, optional
+        Truncate the filter at this many standard deviations.
 
     Returns
     -------
@@ -114,4 +116,5 @@ def gaussian(image, sigma=1, output=None, mode='nearest', cval=0,
         if len(sigma) != image.ndim:
             sigma = np.concatenate((np.asarray(sigma), [0]))
     image = convert_to_float(image, preserve_range)
-    return ndi.gaussian_filter(image, sigma, mode=mode, cval=cval)
+    return ndi.gaussian_filter(image, sigma, mode=mode, cval=cval,
+                               truncate=truncate)


Test patch: