Repository: scikit-image/scikit-image

Issue:
adjust_gamma will change 1x1 array to a float
## Description
In some cases, `adjust_gamma` will change a 1x1 array to a float number.

## Way to reproduce
```python
img = np.ones([1,1]) # Notice: no dtype provided here
print(img) # It is a 1x1 array
img = adjust_gamma(img, 1.5)
print(img) # It is a float number
```

And if you provide the dtype, all is well.

## Version information
```python
3.7.4 (default, Aug 13 2019, 15:17:50) 
[Clang 4.0.1 (tags/RELEASE_401/final)]
Darwin-18.7.0-x86_64-i386-64bit
scikit-image version: 0.15.0
numpy version: 1.16.4
```

adjust_gamma will change 1x1 array to a float
## Description
In some cases, `adjust_gamma` will change a 1x1 array to a float number.

## Way to reproduce
```python
img = np.ones([1,1]) # Notice: no dtype provided here
print(img) # It is a 1x1 array
img = adjust_gamma(img, 1.5)
print(img) # It is a float number
```

And if you provide the dtype, all is well.

## Version information
```python
3.7.4 (default, Aug 13 2019, 15:17:50) 
[Clang 4.0.1 (tags/RELEASE_401/final)]
Darwin-18.7.0-x86_64-i386-64bit
scikit-image version: 0.15.0
numpy version: 1.16.4
```



Discussion:
@jinyu121 Thanks for reporting. What do you mean by "in some cases"? Is there cases where a 1x1 array is not turned into a float?
@jinyu121 Thanks for reporting. What do you mean by "in some cases"? Is there cases where a 1x1 array is not turned into a float?

Resolving patch:
diff --git a/skimage/exposure/exposure.py b/skimage/exposure/exposure.py
--- a/skimage/exposure/exposure.py
+++ b/skimage/exposure/exposure.py
@@ -416,7 +416,7 @@ def adjust_gamma(image, gamma=1, gain=1):
     scale = float(dtype_limits(image, True)[1] - dtype_limits(image, True)[0])
 
     out = ((image / scale) ** gamma) * scale * gain
-    return dtype(out)
+    return out.astype(dtype)
 
 
 def adjust_log(image, gain=1, inv=False):
@@ -459,7 +459,7 @@ def adjust_log(image, gain=1, inv=False):
         return dtype(out)
 
     out = np.log2(1 + image / scale) * scale * gain
-    return dtype(out)
+    return out.astype(dtype)
 
 
 def adjust_sigmoid(image, cutoff=0.5, gain=10, inv=False):
@@ -508,7 +508,7 @@ def adjust_sigmoid(image, cutoff=0.5, gain=10, inv=False):
         return dtype(out)
 
     out = (1 / (1 + np.exp(gain * (cutoff - image / scale)))) * scale
-    return dtype(out)
+    return out.astype(dtype)
 
 
 def is_low_contrast(image, fraction_threshold=0.05, lower_percentile=1,


Test patch:
diff --git a/skimage/exposure/tests/test_exposure.py b/skimage/exposure/tests/test_exposure.py
--- a/skimage/exposure/tests/test_exposure.py
+++ b/skimage/exposure/tests/test_exposure.py
@@ -376,6 +376,12 @@ def norm_brightness_err(img1, img2):
 # Test Gamma Correction
 # =====================
 
+def test_adjust_gamma_1x1_shape():
+    """Check that the shape is maintained"""
+    img = np.ones([1,1])
+    result = exposure.adjust_gamma(img, 1.5)
+    assert img.shape == result.shape
+
 
 def test_adjust_gamma_one():
     """Same image should be returned for gamma equal to one"""
@@ -437,6 +443,13 @@ def test_adjust_gamma_neggative():
 # Test Logarithmic Correction
 # ===========================
 
+def test_adjust_log_1x1_shape():
+    """Check that the shape is maintained"""
+    img = np.ones([1, 1])
+    result = exposure.adjust_log(img, 1)
+    assert img.shape == result.shape
+
+
 def test_adjust_log():
     """Verifying the output with expected results for logarithmic
     correction with multiplier constant multiplier equal to unity"""
@@ -476,6 +489,13 @@ def test_adjust_inv_log():
 # Test Sigmoid Correction
 # =======================
 
+def test_adjust_sigmoid_1x1_shape():
+    """Check that the shape is maintained"""
+    img = np.ones([1, 1])
+    result = exposure.adjust_sigmoid(img, 1, 5)
+    assert img.shape == result.shape
+
+
 def test_adjust_sigmoid_cutoff_one():
     """Verifying the output with expected results for sigmoid correction
     with cutoff equal to one and gain of 5"""