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

Issue:
`min_size` argument in Feltzenswalb segmentation has no effect
From Guillaume Gay on the scikit-image mailing list:

I can't see an effect of the `min_size` argument in Felzenszwalb segmentation. BTW the meaning of this argument is not very clear in the doc.  It's the first time I use this function, so I don't know whether this is a regression or not.

Here is a notebook showing the (lack of) effect of min_size:

http://nbviewer.ipython.org/7023716

/cc @ahojnnes @amueller 



Discussion:
@stefanv Is there a specific reason you ping me here?

@ahojnnes I just looked at the Git blame, and your name came up :)

Unfortunately, I cannot help here... @amueller is the original author of this implementation.

I can try to have a look tonight / on the weekend. If you don't hear from me, feel free to ping me again (possibly by mail. I have >10k github notifications).


Resolving patch:
diff --git a/skimage/segmentation/_felzenszwalb.py b/skimage/segmentation/_felzenszwalb.py
--- a/skimage/segmentation/_felzenszwalb.py
+++ b/skimage/segmentation/_felzenszwalb.py
@@ -43,10 +43,9 @@ def felzenszwalb(image, scale=1, sigma=0.8, min_size=20):
            Huttenlocher, D.P.  International Journal of Computer Vision, 2004
     """
 
-    #image = img_as_float(image)
     if image.ndim == 2:
         # assume single channel image
-        return _felzenszwalb_grey(image, scale=scale, sigma=sigma)
+        return _felzenszwalb_grey(image, scale=scale, sigma=sigma, min_size=min_size)
 
     elif image.ndim != 3:
         raise ValueError("Felzenswalb segmentation can only operate on RGB and"


Test patch:
diff --git a/skimage/segmentation/tests/test_felzenszwalb.py b/skimage/segmentation/tests/test_felzenszwalb.py
--- a/skimage/segmentation/tests/test_felzenszwalb.py
+++ b/skimage/segmentation/tests/test_felzenszwalb.py
@@ -1,7 +1,9 @@
 import numpy as np
 from numpy.testing import assert_equal, assert_array_equal
+
 from skimage._shared.testing import assert_greater
 from skimage.segmentation import felzenszwalb
+from skimage import data
 
 
 def test_grey():
@@ -18,6 +20,24 @@ def test_grey():
         hist = np.histogram(img[seg == i], bins=[0, 0.1, 0.3, 0.5, 1])[0]
         assert_greater(hist[i], 40)
 
+def test_minsize():
+    # single-channel:
+    img = data.coins()[20:168,0:128]
+    for min_size in np.arange(10, 100, 10):
+        segments = felzenszwalb(img, min_size=min_size, sigma=3)
+        counts = np.bincount(segments.ravel())
+        # actually want to test greater or equal.
+        assert_greater(counts.min() + 1, min_size)
+    # multi-channel:
+    coffee = data.coffee()[::4, ::4]
+    for min_size in np.arange(10, 100, 10):
+        segments = felzenszwalb(coffee, min_size=min_size, sigma=3)
+        counts = np.bincount(segments.ravel())
+        # actually want to test greater or equal.
+        # the construction doesn't guarantee min_size is respected
+        # after intersecting the sementations for the colors
+        assert_greater(np.mean(counts) + 1, min_size)
+
 
 def test_color():
     # very weak tests. This algorithm is pretty unstable.
Repository: scikit-image/scikit-image

Issue:
Viewer: ColorHistogram plugin does not update with new image
If a new image is opened when using the ColorHistogram viewer plugin, the color histogram plugin is not updated and if a region of the histogram is selected, the displayed image in the main viewer reverts back to the original image.



Discussion:

Resolving patch:
diff --git a/skimage/viewer/plugins/base.py b/skimage/viewer/plugins/base.py
--- a/skimage/viewer/plugins/base.py
+++ b/skimage/viewer/plugins/base.py
@@ -182,8 +182,13 @@ def _update_original_image(self, image):
         This method is called by the viewer when the original image is updated.
         """
         self.arguments[0] = image
+        self._on_new_image(image)
         self.filter_image()
 
+    def _on_new_image(self, image):
+        """Override this method to update your plugin for new images."""
+        pass
+
     @property
     def filtered_image(self):
         """Return filtered image."""
diff --git a/skimage/viewer/plugins/color_histogram.py b/skimage/viewer/plugins/color_histogram.py
--- a/skimage/viewer/plugins/color_histogram.py
+++ b/skimage/viewer/plugins/color_histogram.py
@@ -20,7 +20,10 @@ def attach(self, image_viewer):
         super(ColorHistogram, self).attach(image_viewer)
 
         self.rect_tool = RectangleTool(self.ax, on_release=self.ab_selected)
-        self.lab_image = color.rgb2lab(image_viewer.image)
+        self._on_new_image(image_viewer.image)
+
+    def _on_new_image(self, image):
+        self.lab_image = color.rgb2lab(image)
 
         # Calculate color histogram in the Lab colorspace:
         L, a, b = self.lab_image.T
diff --git a/skimage/viewer/plugins/plotplugin.py b/skimage/viewer/plugins/plotplugin.py
--- a/skimage/viewer/plugins/plotplugin.py
+++ b/skimage/viewer/plugins/plotplugin.py
@@ -47,3 +47,7 @@ def add_plot(self):
             bgcolor = str(bgcolor / 255.)
         self.fig.patch.set_facecolor(bgcolor)
         self.layout.addWidget(self.canvas, self.row, 0)
+
+    def _update_original_image(self, image):
+        super(PlotPlugin, self)._update_original_image(image)
+        self.redraw()


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

Issue:
Don't hard-code cython command
At the moment, the `_build.py` script assumes the Cython command is `cython`, but on my system I have `cython-2.7` and `cython-3.3`. I think one should use the `Cython` module rather than hard-code the command.



Discussion:
Do you know how to ask Cython to compile a file programmatically?

I'll submit a pull request!


Resolving patch:
diff --git a/setup.py b/setup.py
old mode 100644
new mode 100755
--- a/setup.py
+++ b/setup.py
@@ -21,10 +21,14 @@
 PYTHON_VERSION      = (2, 5)
 DEPENDENCIES        = {
                         'numpy': (1, 6),
-                        'Cython': (0, 17),
                         'six': (1, 3),
                       }
 
+# Only require Cython if we have a developer checkout
+if VERSION.endswith('dev'):
+    DEPENDENCIES['Cython'] = (0, 17)
+
+
 
 import os
 import sys
diff --git a/skimage/_build.py b/skimage/_build.py
--- a/skimage/_build.py
+++ b/skimage/_build.py
@@ -3,7 +3,6 @@
 import hashlib
 import subprocess
 
-
 # WindowsError is not defined on unix systems
 try:
     WindowsError
@@ -26,7 +25,7 @@ def cython(pyx_files, working_path=''):
         return
 
     try:
-        import Cython
+        from Cython.Build import cythonize
     except ImportError:
         # If cython is not found, we do nothing -- the build will make use of
         # the distributed .c files
@@ -39,24 +38,7 @@ def cython(pyx_files, working_path=''):
             if not _changed(pyxfile):
                 continue
 
-            c_file = pyxfile[:-4] + '.c'
-
-            # run cython compiler
-            cmd = 'cython -o %s %s' % (c_file, pyxfile)
-            print(cmd)
-
-            try:
-                subprocess.call(['cython', '-o', c_file, pyxfile])
-            except WindowsError:
-                # On Windows cython.exe may be missing if Cython was installed
-                # via distutils. Run the cython.py script instead.
-                subprocess.call(
-                    [sys.executable,
-                     os.path.join(os.path.dirname(sys.executable),
-                                  'Scripts', 'cython.py'),
-                     '-o', c_file, pyxfile],
-                    shell=True)
-
+            cythonize(pyxfile)
 
 def _md5sum(f):
     m = hashlib.new('md5')


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

Issue:
Viewer: LabelPainter overlay does not update with new loaded image
Reproduce: open the Watershed demo, then load another image of a different `shape`. The overlay won't cover the entire image, and when watershed is called there will be a shape mismatch.



Discussion:

Resolving patch:
diff --git a/skimage/viewer/canvastools/painttool.py b/skimage/viewer/canvastools/painttool.py
--- a/skimage/viewer/canvastools/painttool.py
+++ b/skimage/viewer/canvastools/painttool.py
@@ -50,8 +50,7 @@ def __init__(self, ax, overlay_shape, radius=5, alpha=0.3, on_move=None,
         self.alpha = alpha
         self.cmap = LABELS_CMAP
         self._overlay_plot = None
-        self._shape = overlay_shape
-        self.overlay = np.zeros(overlay_shape, dtype='uint8')
+        self.shape = overlay_shape
 
         self._cursor = plt.Rectangle((0, 0), 0, 0, **props)
         self._cursor.set_visible(False)
@@ -109,6 +108,19 @@ def overlay(self, image):
             self._overlay_plot.set_data(image)
         self.redraw()
 
+    @property
+    def shape(self):
+        return self._shape
+
+    @shape.setter
+    def shape(self, shape):
+        self._shape = shape
+        if not self._overlay_plot is None:
+            self._overlay_plot.set_extent((-0.5, shape[1] + 0.5,
+                                           shape[0] + 0.5, -0.5))
+            self.radius = self._radius
+        self.overlay = np.zeros(shape, dtype='uint8')
+
     def _on_key_press(self, event):
         if event.key == 'enter':
             self.callback_on_enter(self.geometry)
diff --git a/skimage/viewer/plugins/labelplugin.py b/skimage/viewer/plugins/labelplugin.py
--- a/skimage/viewer/plugins/labelplugin.py
+++ b/skimage/viewer/plugins/labelplugin.py
@@ -43,6 +43,10 @@ def attach(self, image_viewer):
         self.paint_tool.label = self._label_widget.index = 1
         self.artists.append(self.paint_tool)
 
+    def _on_new_image(self, image):
+        """Update plugin for new images."""
+        self.paint_tool.shape = image.shape
+
     def on_enter(self, overlay):
         pass
 


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

Issue:
Sphinx link from corner_peaks to peak_local_max broken
Currently the Sphinx link from corner_peaks to peak_local_max is broken:
http://scikit-image.org/docs/dev/api/skimage.feature.html#corner-peaks

![screen shot 2014-03-01 at 15 01 30](https://f.cloud.github.com/assets/852409/2301529/1940e5ae-a14a-11e3-9502-8c8613d4ace2.png)



Discussion:
What's the correct way to fix this?

The correct way to reference other methods is 

```
:py:meth:`methodname`
```

But I just tested this, it works otherwise but not in the parameters or return section
http://sphinx-doc.org/domains.html#role-py:meth

There should be a way to auto-fill these sections from another function. I've seen it before, but don't recall the exact method...

@JDWarner I could not find a way to do so... The `:py:meth:`methodname`` syntax does not work in this case as Sphinx interprets the "See ..." as a parameter.

Time to upgrade to the latest version of numpydoc

So, updating to the newest numydoc version did not help here.


Resolving patch:
diff --git a/skimage/feature/corner.py b/skimage/feature/corner.py
--- a/skimage/feature/corner.py
+++ b/skimage/feature/corner.py
@@ -746,11 +746,8 @@ def corner_peaks(image, min_distance=10, threshold_abs=0, threshold_rel=0.1,
 
     Parameters
     ----------
-    See `skimage.feature.peak_local_max`.
-
-    Returns
-    -------
-    See `skimage.feature.peak_local_max`.
+    * : *
+        See :py:meth:`skimage.feature.peak_local_max`.
 
     Examples
     --------


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

Issue:
Error revealed by numpy 1.9.0r1
```
======================================================================
ERROR: test_join.test_relabel_sequential_offset1
----------------------------------------------------------------------
Traceback (most recent call last):
  File "X:\Python27-x64\lib\site-packages\nose\case.py", line 197, in runTest
    self.test(*self.arg)
  File "X:\Python27-x64\lib\site-packages\skimage\segmentation\tests\test_join.py", line 30, in test_relabel_sequential_offset1
    ar_relab, fw, inv = relabel_sequential(ar)
  File "X:\Python27-x64\lib\site-packages\skimage\segmentation\_join.py", line 127, in relabel_sequential
    forward_map[labels0] = np.arange(offset, offset + len(labels0) + 1)
ValueError: shape mismatch: value array of shape (6,) could not be broadcast to indexing result of shape (5,)
```

The `+ 1` is incorrect.



Discussion:

Resolving patch:
diff --git a/skimage/segmentation/_join.py b/skimage/segmentation/_join.py
--- a/skimage/segmentation/_join.py
+++ b/skimage/segmentation/_join.py
@@ -124,7 +124,7 @@ def relabel_sequential(label_field, offset=1):
     if m == len(labels0):  # nothing to do, already 1...n labels
         return label_field, labels, labels
     forward_map = np.zeros(m + 1, int)
-    forward_map[labels0] = np.arange(offset, offset + len(labels0) + 1)
+    forward_map[labels0] = np.arange(offset, offset + len(labels0))
     if not (labels == 0).any():
         labels = np.concatenate(([0], labels))
     inverse_map = np.zeros(offset - 1 + len(labels), dtype=np.intp)


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

Issue:
filter.threshold_isodata fails on 16-bit int images
The problem is the following line in threshholding.py:threshold_isodata():

```
    binnums = np.arange(pmf.size, dtype=np.uint8)
```

Obviously the histogram bin numbers for images with more than 255 intensity levels don't get generated properly, leading to hilarity. Changing that to dtype=np.uint16 should do the trick for 8- and 16-bit images, and float images as long as the nbins parameter is < 2**16. (This wouldn't work for 32-bit integer images -- are these even supported though?)



Discussion:
Hey @zachrahan, just to make sure I understand, the values we need to represent in `binnums` are anything up to `nbins`, right?

ie, what's failing is having more than 2**8 bins, rather than having a 16 bit image?


Resolving patch:
diff --git a/skimage/filter/thresholding.py b/skimage/filter/thresholding.py
--- a/skimage/filter/thresholding.py
+++ b/skimage/filter/thresholding.py
@@ -243,7 +243,7 @@ def threshold_isodata(image, nbins=256):
     cpmfl = np.cumsum(pmf, dtype=np.float32)
     cpmfh = np.cumsum(pmf[::-1], dtype=np.float32)[::-1]
 
-    binnums = np.arange(pmf.size, dtype=np.uint8)
+    binnums = np.arange(pmf.size, dtype=np.min_scalar_type(nbins))
     # l and h contain average value of pixels in sum of bins, calculated
     # from lower to higher and from higher to lower respectively.
     l = np.ma.divide(np.cumsum(pmf * binnums, dtype=np.float32), cpmfl)


Test patch:
diff --git a/skimage/filter/tests/test_thresholding.py b/skimage/filter/tests/test_thresholding.py
--- a/skimage/filter/tests/test_thresholding.py
+++ b/skimage/filter/tests/test_thresholding.py
@@ -67,6 +67,12 @@ def test_isodata_blank_zero(self):
     def test_isodata_linspace(self):
         assert -63.8 < threshold_isodata(np.linspace(-127, 0, 256)) < -63.6
 
+    def test_isodata_16bit(self):
+        np.random.seed(0)
+        imfloat = np.random.rand(256, 256)
+        t = threshold_isodata(imfloat, nbins=1024)
+        assert 0.49 < t < 0.51
+
     def test_threshold_adaptive_generic(self):
         def func(arr):
             return arr.sum() / arr.shape[0]
Repository: scikit-image/scikit-image

Issue:
NameError on del version when init has ImportError
In `__init__.py`, `del version` gives `NameError` when `ImportError` happens.

```
try:
    from .version import version as __version__
except ImportError:
    __version__ = "unbuilt-dev"
del version
```

should be

```
try:
    from .version import version as __version__
except ImportError:
    __version__ = "unbuilt-dev"
else:
    del version
```



Discussion:

Resolving patch:
diff --git a/skimage/__init__.py b/skimage/__init__.py
--- a/skimage/__init__.py
+++ b/skimage/__init__.py
@@ -69,7 +69,8 @@
     from .version import version as __version__
 except ImportError:
     __version__ = "unbuilt-dev"
-del version
+else:
+    del version
 
 
 try:


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

Issue:
canny edge detection throws AttributeError exception
I was trying out http://scikit-image.org/docs/dev/auto_examples/plot_canny.html 

And the following lines of code:
# Generate noisy image of a square

im = np.zeros((128, 128))
im[32:-32, 32:-32] = 1

im = ndimage.rotate(im, 15, mode='constant')
im = ndimage.gaussian_filter(im, 4)
im += 0.2 \* np.random.random(im.shape)
# Compute the Canny filter for two values of sigma

edges1 = filter.canny(im)

 produced this:

Traceback (most recent call last):
  File "<stdin>", line 2, in <module>
  File "/home/abc/virtualenvs/activepython/lib/python2.7/site-packages/scikit_image-0.11dev-py2.7-linux-x86_64.egg/skimage/_shared/utils.py", line 46, in __call__
    msg = 'Call to deprecated function `%s`.' % func.**name**
AttributeError: 'numpy.ndarray' object has no attribute '**name**'

Any guess? Seems I'm using the latest version of scikit-image. 



Discussion:

Resolving patch:
diff --git a/skimage/filter/__init__.py b/skimage/filter/__init__.py
--- a/skimage/filter/__init__.py
+++ b/skimage/filter/__init__.py
@@ -19,7 +19,7 @@
                         (restoration.denoise_tv_chambolle)
 
 # Backward compatibility v<0.11
-@deprecated
+@deprecated('skimage.feature.canny')
 def canny(*args, **kwargs):
     # Hack to avoid circular import
     from skimage.feature._canny import canny as canny_


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

Issue:
RuntimeWarning in Blob detection excercise
I've followed the Skimage tutorial on detecting features with Difference of Gaussian. I've used different images taken from the web (jpeg RGB and even grayscale). With some pictures I got the following 

C:\Users\Me\Anaconda\lib\site-packages\skimage\feature\blob.py:55.
RuntimeWarning: invalid value encountered in arccos acos1 = arccos((d *\* 2 + r1 *\* 2 - r2 *\* 2) / (2 \* d \* r1))

I've used PyCharm to write down my code and here is the starting code (I've changed it lately a little bit, but I still have this warning with some pics):

```
from matplotlib import pyplot as plt
from skimage import data
from skimage.feature import blob_dog
from skimage.color import rgb2gray

image = data.imread('Img.png')
image_gray = rgb2gray(image)

blobs_dog = blob_dog(image_gray, max_sigma=30, threshold=.1)

blobs = [blobs_dog]
colors = ['red']
titles = ['Difference of Gaussian']
sequence = zip(blobs, colors, titles)

for blobs, color, title in sequence:
    fig, ax = plt.subplots(1, 1)
    ax.set_title(title)
    ax.imshow(image_gray, interpolation='nearest')
    for blob in blobs:
        y, x, r = blob
        c = plt.Circle((x, y), r, color=color, linewidth=1, fill=False)
        ax.add_patch(c)

plt.show()
```



Discussion:
I'm guessing this is due to some approximation errors. I imagine the right thing here is to use `np.clip`, but it would be good to have a minimal image with which to test this... CC @vighneshbirodkar @stefanv

With [this one](http://upload.wikimedia.org/wikipedia/commons/d/d4/Batumi_Merry-Go-Round.jpg) I have that problem, for instance.

Hey

I still get the output after this . Are you able to see the blobs ? 

The ideal thing to do here would be to check the ratio before computing arccos and handle the condition . 

@vighneshbirodkar what does "handle the condition" mean? If it means clipping to [-1, 1], that can be done automatically by `np.clip`. The only reason I haven't submitted a PR yet is that I'm not sure something worse than a floating point approximation is causing this bug. Are you? =)

@vighneshbirodkar Yes, I had the output as well, with the blobs, but with some pictures I also had this Warning (at least on Pycharm, I didn't have it using Ipython Notebook).


Resolving patch:
diff --git a/skimage/feature/blob.py b/skimage/feature/blob.py
--- a/skimage/feature/blob.py
+++ b/skimage/feature/blob.py
@@ -53,8 +53,14 @@ def _blob_overlap(blob1, blob2):
     if d <= abs(r1 - r2):
         return 1
 
-    acos1 = arccos((d ** 2 + r1 ** 2 - r2 ** 2) / (2 * d * r1))
-    acos2 = arccos((d ** 2 + r2 ** 2 - r1 ** 2) / (2 * d * r2))
+    ratio1 = (d ** 2 + r1 ** 2 - r2 ** 2) / (2 * d * r1)
+    ratio1 = np.clip(ratio1, -1, 1)
+    acos1 = arccos(ratio1)
+
+    ratio2 = (d ** 2 + r2 ** 2 - r1 ** 2) / (2 * d * r2)
+    ratio2 = np.clip(ratio2, -1, 1)
+    acos2 = arccos(ratio2)
+
     a = -d + r2 + r1
     b = d - r2 + r1
     c = d + r2 - r1


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

Issue:
label2rgb has no default in place for bg_color
```
image_label_overlay = label2rgb(selected_labels, image=image, bg_label=0, kind='avg')
```

```
/home/stefan/src/scikit-image/skimage/color/colorlabel.py in _label2rgb_avg(label_field, image, bg_label, bg_color)
    209     if bg.any():
    210         labels = labels[labels != bg_label]
--> 211         out[bg] = bg_color
    212     for label in labels:
    213         mask = (label_field == label).nonzero()

TypeError: int() argument must be a string or a number, not 'NoneType'
```



Discussion:

Resolving patch:
diff --git a/skimage/color/colorlabel.py b/skimage/color/colorlabel.py
--- a/skimage/color/colorlabel.py
+++ b/skimage/color/colorlabel.py
@@ -64,7 +64,7 @@ def _match_label_with_color(label, colors, bg_label, bg_color):
 
 
 def label2rgb(label, image=None, colors=None, alpha=0.3,
-              bg_label=-1, bg_color=None, image_alpha=1, kind='overlay'):
+              bg_label=-1, bg_color=(0, 0, 0), image_alpha=1, kind='overlay'):
     """Return an RGB image where color-coded labels are painted over the image.
 
     Parameters


Test patch:
diff --git a/skimage/color/tests/test_colorlabel.py b/skimage/color/tests/test_colorlabel.py
--- a/skimage/color/tests/test_colorlabel.py
+++ b/skimage/color/tests/test_colorlabel.py
@@ -91,9 +91,12 @@ def test_leave_labels_alone():
     assert_array_equal(labels, labels_saved)
 
 def test_avg():
+    # label image
     label_field = np.array([[1, 1, 1, 2],
                             [1, 2, 2, 2],
                             [3, 3, 3, 3]], dtype=np.uint8)
+
+    # color image
     r = np.array([[1., 1., 0., 0.],
                   [0., 0., 1., 1.],
                   [0., 0., 0., 0.]])
@@ -104,7 +107,8 @@ def test_avg():
                   [0., 1., 1., 1.],
                   [0., 0., 1., 1.]])
     image = np.dstack((r, g, b))
-    out = label2rgb(label_field, image, kind='avg')
+
+    # reference label-colored image
     rout = np.array([[0.5, 0.5, 0.5, 0.5],
                      [0.5, 0.5, 0.5, 0.5],
                      [0. , 0. , 0. , 0. ]])
@@ -115,14 +119,22 @@ def test_avg():
                      [0. , 1. , 1. , 1. ],
                      [0.5, 0.5, 0.5, 0.5]])
     expected_out = np.dstack((rout, gout, bout))
+
+    # test standard averaging
+    out = label2rgb(label_field, image, kind='avg')
     assert_array_equal(out, expected_out)
 
+    # test averaging with custom background value
     out_bg = label2rgb(label_field, image, bg_label=2, bg_color=(0, 0, 0),
                        kind='avg')
     expected_out_bg = expected_out.copy()
     expected_out_bg[label_field == 2] = 0
     assert_array_equal(out_bg, expected_out_bg)
 
+    # test default background color
+    out_bg = label2rgb(label_field, image, bg_label=2, kind='avg')
+    assert_array_equal(out_bg, expected_out_bg)
+
 
 def test_negative_intensity():
     labels = np.arange(100).reshape(10, 10)