scikit-image/scikit-image — pull request #727 by jni (2013-09-09 04:03:48+00:00)
Title: Fix type hierarchy check in remove_small_objects

Another whoopsies fix from me.

`skimage.morphology.remove_small_objects` is neat and useful but currently does *not* accept unsigned integer input! That is because when I was checking for valid input types, I wrote:

```python
if not (ar.dtype == bool or np.issubdtype(ar.dtype, int)):
```

This results in the following error:

```python
In [1]: x = np.array([1, 0, 2, 2], dtype=np.int8)

In [2]: from skimage.morphology import remove_small_objects

In [3]: remove_small_objects(x, 2)
Out[3]: array([0, 0, 2, 2], dtype=int8)

In [4]: remove_small_objects(x.astype(np.uint8), 2)
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
in ()
----> 1 remove_small_objects(x.astype(np.uint8), 2)

/Users/nuneziglesiasj/venv/skimdev/lib/python2.7/site-packages/scikit_image-0.9dev-py2.7-macosx-10.5-x86_64.egg/skimage/morphology/misc.pyc in remove_small_objects(ar, min_size, connectivity, in_place)
55 if not (ar.dtype == bool or np.issubdtype(ar.dtype, int)):
56 raise TypeError("Only bool or integer image types are supported. "
---> 57 "Got %s." % ar.dtype)
58
59 if in_place:

TypeError: Only bool or integer image types are supported. Got uint8.
```

It looks like the Python built-in type `int` resolves in numpy to `np.signedinteger` rather than `np.integer`, the latter of which [encompasses](http://docs.scipy.org/doc/numpy/reference/arrays.scalars.html) both signed and unsigned. The following line allows both signed and unsigned integer input (in addition to `bool`):

```python
if not (ar.dtype == bool or np.issubdtype(ar.dtype, np.integer)):
```

I've added a test with unsigned input to prevent regression of this bug.