mirror of
https://github.com/wassname/scikit-image.git
synced 2026-07-02 04:42:23 +08:00
Deprecating is_gray and replacing it with is_gray_2d
This commit is contained in:
@@ -52,7 +52,7 @@ __all__ = ['convert_colorspace', 'rgb2hsv', 'hsv2rgb', 'rgb2xyz', 'xyz2rgb',
|
||||
'rgb_from_gdx', 'gdx_from_rgb', 'rgb_from_hax', 'hax_from_rgb',
|
||||
'rgb_from_bro', 'bro_from_rgb', 'rgb_from_bpx', 'bpx_from_rgb',
|
||||
'rgb_from_ahx', 'ahx_from_rgb', 'rgb_from_hpx', 'hpx_from_rgb',
|
||||
'is_rgb', 'is_gray'
|
||||
'is_rgb', 'is_gray', 'is_gray_2d'
|
||||
]
|
||||
|
||||
__docformat__ = "restructuredtext en"
|
||||
@@ -60,6 +60,7 @@ __docformat__ = "restructuredtext en"
|
||||
import numpy as np
|
||||
from scipy import linalg
|
||||
from ..util import dtype
|
||||
from skimage._shared.utils import deprecated
|
||||
|
||||
|
||||
def is_rgb(image):
|
||||
@@ -73,7 +74,7 @@ def is_rgb(image):
|
||||
"""
|
||||
return (image.ndim == 3 and image.shape[2] in (3, 4))
|
||||
|
||||
|
||||
@deprecated('is_gray_2d')
|
||||
def is_gray(image):
|
||||
"""Test whether the image is gray (i.e. has only one color band).
|
||||
|
||||
@@ -83,8 +84,18 @@ def is_gray(image):
|
||||
Input image.
|
||||
|
||||
"""
|
||||
return image.ndim == 2
|
||||
return is_gray_2d(image)
|
||||
|
||||
def is_gray_2d(image):
|
||||
"""Test whether the image is 2d and grayscale.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
image : ndarray
|
||||
Input image.
|
||||
|
||||
"""
|
||||
return np.squeeze(image).ndim == 2
|
||||
|
||||
def convert_colorspace(arr, fromspace, tospace):
|
||||
"""Convert an image array to a new color space.
|
||||
|
||||
@@ -29,7 +29,7 @@ from skimage.color import (
|
||||
rgb2grey, gray2rgb,
|
||||
xyz2lab, lab2xyz,
|
||||
lab2rgb, rgb2lab,
|
||||
is_rgb, is_gray
|
||||
is_rgb, is_gray, is_gray_2d
|
||||
)
|
||||
|
||||
from skimage import data_dir, data
|
||||
@@ -232,19 +232,16 @@ class TestColorconv(TestCase):
|
||||
assert_array_almost_equal(lab2rgb(rgb2lab(img_rgb)), img_rgb)
|
||||
|
||||
def test_gray2rgb():
|
||||
x = np.array([0, 0.5, 1])
|
||||
assert_raises(ValueError, gray2rgb, x)
|
||||
|
||||
x = x.reshape((3, 1))
|
||||
x = np.array([[0, 0.5, 1], [0, 0.5, 1]])
|
||||
y = gray2rgb(x)
|
||||
|
||||
assert_equal(y.shape, (3, 1, 3))
|
||||
assert_equal(y.shape, (2, 3, 3))
|
||||
assert_equal(y.dtype, x.dtype)
|
||||
|
||||
x = np.array([[0, 128, 255]], dtype=np.uint8)
|
||||
x = np.array([[0, 128], [128, 255], [255, 0]], dtype=np.uint8)
|
||||
z = gray2rgb(x)
|
||||
|
||||
assert_equal(z.shape, (1, 3, 3))
|
||||
assert_equal(z.shape, (3, 2, 3))
|
||||
assert_equal(z[..., 0], x)
|
||||
assert_equal(z[0, 1, :], [128, 128, 128])
|
||||
|
||||
|
||||
Reference in New Issue
Block a user