Repository: scikit-image/scikit-image

Issue:
skimage.measure.regionprops can't be applied to image with one row/column
## Description
As far as i understand `skimage.measure.regionprops` raises `TypeError('Only 2-D and 3-D images supported.')` when applied to 2D image with one row/column.
If i understood correctly it happens due to `np.squeeze` and successive assertion in `skimage.measure.regionprops`

Part of `skimage.measure.regionprops` source code which raises exception
```
    label_image = np.squeeze(label_image)
    if label_image.ndim not in (2, 3):
        raise TypeError('Only 2-D and 3-D images supported.')
```

## Way to reproduce
Minimal example
```
import numpy as np
import skimage.measure
mask = np.array([
    [1],
], dtype=np.uint8)

print(mask.ndim) #2-D image
print(skimage.measure.regionprops(mask))
```
- Operating system and version: Ubuntu 17.10 
- Python version: 3.6.3
-  scikit-image version 0.14.0

PS Sorry for my poor English



Discussion:
Your English is perfectly understandable, Kirill.  Thank you for the bug report!

I think this is indeed a bug, so would you like to file a pull request to fix it?
Adding to this, it seems to occur when there is any 1-size axis. The project I'm working on processes a mixture of 2d and 3d data, so for simplicity we attempt to process 2d data as "fake 3d" data whenever possible. This triggers what I think is probably the same bug listed in this issue.
 
```python
>>> import numpy as np
>>> from skimage.measure import regionprops

>>> x = np.arange(4).reshape(1, 2, 2)
>>> y = np.arange(4).reshape(1, 2, 2)
>>> y.shape
(1, 2, 2)

# if you pre-squeeze out the 3rd axis, it works:
>>> regionprops(np.squeeze(y), np.squeeze(x))
[<skimage.measure._regionprops._RegionProperties at 0x1111e20b8>,
 <skimage.measure._regionprops._RegionProperties at 0x1111e23c8>,
 <skimage.measure._regionprops._RegionProperties at 0x1111e2518>]

# without the squeeze, an error is triggered
>>> regionprops(y, x)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
<ipython-input-6-b46c4427f24e> in <module>()
----> 1 regionprops(y, x)

/usr/local/lib/python3.6/site-packages/skimage/measure/_regionprops.py in regionprops(label_image, intensity_image, cache, coordinates)
    563 
    564         props = _RegionProperties(sl, label, label_image, intensity_image,
--> 565                                   cache, coordinates=coordinates)
    566         regions.append(props)
    567 

/usr/local/lib/python3.6/site-packages/skimage/measure/_regionprops.py in __init__(self, slice, label, label_image, intensity_image, cache_active, coordinates)
    105         if intensity_image is not None:
    106             if not intensity_image.shape == label_image.shape:
--> 107                 raise ValueError('Label and intensity image must have the'
    108                                  'same shape.')
    109 

ValueError: Label and intensity image must have thesame shape.

```
Hello Stefan! Thank you for answer. Yes i think that i can create pull request. Only problem is how to solve this problem. Simplest solution is just remove `label_image = np.squeeze(label_image)` line. This solution allow user to directly manage shape transformation of `label_image` before `skimage.measure.regionprops` call. Also it works for me :). But there are another ways to solve this problem. For example it's possible to call `np.squeeze` only if `label_image.ndim > 3`. I am not a experienced skimage user so i don't know which solution coincides with skimage "style".
Anyway currently I'm reading `https://github.com/scikit-image/scikit-image/blob/master/CONTRIBUTING.txt`

Resolving patch:
diff --git a/skimage/measure/_regionprops.py b/skimage/measure/_regionprops.py
--- a/skimage/measure/_regionprops.py
+++ b/skimage/measure/_regionprops.py
@@ -365,6 +365,13 @@ def regionprops(label_image, intensity_image=None, cache=True,
     ----------
     label_image : (N, M) ndarray
         Labeled input image. Labels with value 0 are ignored.
+
+        .. versionchanged:: 0.14.1
+            Previously, ``label_image`` was processed by ``numpy.squeeze`` and
+            so any number of singleton dimensions was allowed. This resulted in
+            inconsistent handling of images with singleton dimensions. To
+            recover the old behaviour, use
+            ``regionprops(np.squeeze(label_image), ...)``.
     intensity_image : (N, M) ndarray, optional
         Intensity (i.e., input) image with same size as labeled image.
         Default is None.
@@ -546,8 +553,6 @@ def regionprops(label_image, intensity_image=None, cache=True,
 
     """
 
-    label_image = np.squeeze(label_image)
-
     if label_image.ndim not in (2, 3):
         raise TypeError('Only 2-D and 3-D images supported.')
 


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
@@ -63,8 +63,9 @@ def test_dtype():
 def test_ndim():
     regionprops(np.zeros((10, 10), dtype=np.int))
     regionprops(np.zeros((10, 10, 1), dtype=np.int))
-    regionprops(np.zeros((10, 10, 1, 1), dtype=np.int))
     regionprops(np.zeros((10, 10, 10), dtype=np.int))
+    regionprops(np.zeros((1, 1), dtype=np.int))
+    regionprops(np.zeros((1, 1, 1), dtype=np.int))
     with testing.raises(TypeError):
         regionprops(np.zeros((10, 10, 10, 2), dtype=np.int))