mirror of
https://github.com/wassname/scikit-image.git
synced 2026-07-26 13:37:17 +08:00
Removing is_gray() and is_rgb()
This commit is contained in:
@@ -51,8 +51,7 @@ __all__ = ['convert_colorspace', 'rgb2hsv', 'hsv2rgb', 'rgb2xyz', 'xyz2rgb',
|
||||
'rgb_from_bex', 'bex_from_rgb', 'rgb_from_rbd', 'rbd_from_rgb',
|
||||
'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_gray_2d'
|
||||
'rgb_from_ahx', 'ahx_from_rgb', 'rgb_from_hpx', 'hpx_from_rgb'
|
||||
]
|
||||
|
||||
__docformat__ = "restructuredtext en"
|
||||
@@ -63,40 +62,6 @@ from ..util import dtype
|
||||
from skimage._shared.utils import deprecated
|
||||
|
||||
|
||||
def is_rgb(image):
|
||||
"""Test whether the image is RGB or RGBA.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
image : ndarray
|
||||
Input 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).
|
||||
|
||||
Parameters
|
||||
----------
|
||||
image : ndarray
|
||||
Input image.
|
||||
|
||||
"""
|
||||
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.
|
||||
|
||||
@@ -663,9 +628,9 @@ def gray2rgb(image):
|
||||
If the input is not 2-dimensional.
|
||||
|
||||
"""
|
||||
if is_rgb(image):
|
||||
if np.squeeze(image).ndim == 3 and image.shape[2] in (3, 4):
|
||||
return image
|
||||
elif is_gray(image):
|
||||
elif np.squeeze(image).ndim == 2:
|
||||
return np.dstack((image, image, image))
|
||||
else:
|
||||
raise ValueError("Input image expected to be RGB, RGBA or gray.")
|
||||
|
||||
@@ -28,8 +28,7 @@ from skimage.color import (
|
||||
convert_colorspace,
|
||||
rgb2grey, gray2rgb,
|
||||
xyz2lab, lab2xyz,
|
||||
lab2rgb, rgb2lab,
|
||||
is_rgb, is_gray, is_gray_2d
|
||||
lab2rgb, rgb2lab
|
||||
)
|
||||
|
||||
from skimage import data_dir, data
|
||||
@@ -252,16 +251,5 @@ def test_gray2rgb_rgb():
|
||||
assert_equal(x, y)
|
||||
|
||||
|
||||
def test_is_rgb():
|
||||
color = data.lena()
|
||||
gray = data.camera()
|
||||
|
||||
assert is_rgb(color)
|
||||
assert not is_gray(color)
|
||||
|
||||
assert is_gray(gray)
|
||||
assert not is_gray(color)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
run_module_suite()
|
||||
|
||||
Reference in New Issue
Block a user