mirror of
https://github.com/wassname/scikit-image.git
synced 2026-06-29 06:09:25 +08:00
Add function to guesstimate number of spatial dimensions
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
from .colorconv import (convert_colorspace,
|
||||
guess_spatial_dimensions,
|
||||
rgb2hsv,
|
||||
hsv2rgb,
|
||||
rgb2xyz,
|
||||
@@ -45,6 +46,7 @@ from .colorlabel import color_dict, label2rgb
|
||||
|
||||
|
||||
__all__ = ['convert_colorspace',
|
||||
'guess_spatial_dimensions',
|
||||
'rgb2hsv',
|
||||
'hsv2rgb',
|
||||
'rgb2xyz',
|
||||
|
||||
@@ -49,6 +49,37 @@ from ..util import dtype
|
||||
from skimage._shared.utils import deprecated
|
||||
|
||||
|
||||
def guess_spatial_dimensions(image):
|
||||
"""Make an educated guess about whether an image has a channels dimension.
|
||||
|
||||
Parameters
|
||||
----------
|
||||
image : ndarray
|
||||
The input image.
|
||||
|
||||
Returns
|
||||
-------
|
||||
spatial_dims : int or None
|
||||
The number of spatial dimensions of `image`. If ambiguous, the value
|
||||
is `None`.
|
||||
|
||||
Raises
|
||||
------
|
||||
ValueError
|
||||
If the image array has less than two or more than four dimensions.
|
||||
"""
|
||||
if image.ndim == 2:
|
||||
return 2
|
||||
if image.ndim == 3 and image.shape[-1] != 3:
|
||||
return 3
|
||||
if image.ndim == 3 and image.shape[-1] == 3:
|
||||
return None
|
||||
if image.ndim == 4 and image.shape[-1] == 3:
|
||||
return 3
|
||||
else:
|
||||
raise ValueError("Expected 2D, 3D, or 4D array, got %iD." % image.ndim)
|
||||
|
||||
|
||||
@deprecated()
|
||||
def is_rgb(image):
|
||||
"""Test whether the image is RGB or RGBA.
|
||||
|
||||
Reference in New Issue
Block a user