o
    :ήc                     @   s*  d Z ddlmZ ddlZddlmZ ddlmZm	Z	m
Z
mZmZ ddlmZmZ dd	d
dZddd	ddZdd Zddd	ddZe	 dd	ddZe	 dd	ddZeg dZeg dd Zeg dg dg dgZeeZeg dg dg d gd! ZeeZee Zee Zeg d"g d#g d#gZ eg d$g d%g d&gZ!ee!Z"eg d$g d'g d(gZ#ee#Z$eg d$g d)g d*gZ%ee%Z&eg d+g d,g d-gZ'ee'Z(eg d$g d.g d/gZ)ee)Z*eg d0Z+d1d2d1d3d4d5d4d3d6d7d6d3d8d9d:d3d;d<d=d3d0d>d?d3d@dAd@d3dBdBdBd3dCZ,e-fdDdEZ.eg dFg dGg dHgZ/ee/Z0eg dIg dJg dKgZ1e2e1dddf e1dLddf e1dddf< ee1Z3eg dMg dNg dKgZ4e2e4dddf e4dLddf e4dddf< ee4Z5eg dOg dPg dKgZ6e2e6dddf e6dLddf e6dddf< ee6Z7eg dQg dRg dJgZ8ee8Z9eg dSg dJg dKgZ:e2e:dddf e:dLddf e:dddf< ee:Z;eg dIg dTg dKgZ<e2e<dddf e<dLddf e<dddf< ee<Z=eg dUg dVg dWgZ>ee>Z?eg dXg dYg dKgZ@e2e@dddf e@dLddf e@dddf< ee@ZAeg dZg d[g dKgZBe2eBdddf eBdLddf eBdddf< eeBZCeg d\g d]g dKgZDe2eDdddf eDdLddf eDdddf< eeDZEd^d_ ZFe	 dd	d`daZGe	 dd	dbdcZHe	 dd	dddeZIe	 dd	dfdgZJe	ddhdd	didjZKddd	dkdlZLdd	dmdnZMe	 ddd	dqdrZNe	 ddd	dsdtZOe	 ddd	dudvZPe	 ddd	dwdxZQe	 ddd	dydzZRe	 ddd	d{d|ZSe	 dd	d}d~ZTe	 dd	ddZUe	 dd	ddZVe	 dd	ddZWe	 dd	ddZXe	 dd	ddZYe	 dd	ddZZdd Z[e	 dd	ddZ\dddZ]e	 dd	ddZ^e	 dd	ddZ_e	 dd	ddZ`e	 dd	ddZae	 dd	ddZbe	 dd	ddZce	 dd	ddZde	 dd	ddZee	 dd	ddZfe	 dd	ddZgdS )a  Functions for converting between color spaces.

The "central" color space in this module is RGB, more specifically the linear
sRGB color space using D65 as a white-point [1]_.  This represents a
standard monitor (w/o gamma correction). For a good FAQ on color spaces see
[2]_.

The API consists of functions to convert to and from RGB as defined above, as
well as a generic function to convert to and from any supported color space
(which is done through RGB in most cases).


Supported color spaces
----------------------
* RGB : Red Green Blue.
        Here the sRGB standard [1]_.
* HSV : Hue, Saturation, Value.
        Uniquely defined when related to sRGB [3]_.
* RGB CIE : Red Green Blue.
        The original RGB CIE standard from 1931 [4]_. Primary colors are 700 nm
        (red), 546.1 nm (blue) and 435.8 nm (green).
* XYZ CIE : XYZ
        Derived from the RGB CIE color space. Chosen such that
        ``x == y == z == 1/3`` at the whitepoint, and all color matching
        functions are greater than zero everywhere.
* LAB CIE : Lightness, a, b
        Colorspace derived from XYZ CIE that is intended to be more
        perceptually uniform
* LUV CIE : Lightness, u, v
        Colorspace derived from XYZ CIE that is intended to be more
        perceptually uniform
* LCH CIE : Lightness, Chroma, Hue
        Defined in terms of LAB CIE.  C and H are the polar representation of
        a and b.  The polar angle C is defined to be on ``(0, 2*pi)``

:author: Nicolas Pinto (rgb2hsv)
:author: Ralf Gommers (hsv2rgb)
:author: Travis Oliphant (XYZ and RGB CIE functions)
:author: Matt Terry (lab2lch)
:author: Alex Izvorski (yuv2rgb, rgb2yuv and related)

:license: modified BSD

References
----------
.. [1] Official specification of sRGB, IEC 61966-2-1:1999.
.. [2] http://www.poynton.com/ColorFAQ.html
.. [3] https://en.wikipedia.org/wiki/HSL_and_HSV
.. [4] https://en.wikipedia.org/wiki/CIE_1931_color_space
    )warnN)linalg   )_supported_float_typechannel_as_last_axisidentity
reshape_ndslice_at_axis)dtypedtype_limitschannel_axisc             
   C   s   t ttttttttd	}t t	t
ttttttd	}| }| }||vr/d|  }t|||vr>d|  }t||| || | |d|dS )a  Convert an image array to a new color space.

    Valid color spaces are:
        'RGB', 'HSV', 'RGB CIE', 'XYZ', 'YUV', 'YIQ', 'YPbPr', 'YCbCr', 'YDbDr'

    Parameters
    ----------
    arr : (..., 3, ...) array_like
        The image to convert. By default, the final dimension denotes
        channels.
    fromspace : str
        The color space to convert from. Can be specified in lower case.
    tospace : str
        The color space to convert to. Can be specified in lower case.
    channel_axis : int, optional
        This parameter indicates which axis of the array corresponds to
        channels.

        .. versionadded:: 0.19
           ``channel_axis`` was added in 0.19.

    Returns
    -------
    out : (..., 3, ...) ndarray
        The converted image. Same dimensions as input.

    Raises
    ------
    ValueError
        If fromspace is not a valid color space
    ValueError
        If tospace is not a valid color space

    Notes
    -----
    Conversion is performed through the "central" RGB color space,
    i.e. conversion from XYZ to HSV is implemented as ``XYZ -> RGB -> HSV``
    instead of directly.

    Examples
    --------
    >>> from skimage import data
    >>> img = data.astronaut()
    >>> img_hsv = convert_colorspace(img, 'RGB', 'HSV')
    )	rgbhsvzrgb ciexyzyuvyiqypbprycbcrydbdrz`fromspace` has to be one of z`tospace` has to be one of r   )r   hsv2rgb
rgbcie2rgbxyz2rgbyuv2rgbyiq2rgb	ypbpr2rgb	ycbcr2rgb	ydbdr2rgbrgb2hsv
rgb2rgbciergb2xyzrgb2yuvrgb2yiq	rgb2ypbpr	rgb2ycbcr	rgb2ydbdrlowerkeys
ValueError)arr	fromspacetospacer   fromdicttodictmsg r0   >/tmp/pip-target-vg8gfxp4/lib/python/skimage/color/colorconv.pyconvert_colorspace?   s(   .r2   Fc                C   sZ   t | } | j| dkrd| j }t|t| j}|t jkr$tj}ntj}|| |dS )zVCheck the shape of the array and convert it to
    floating point representation.
       z;the input array must have size 3 along `channel_axis`, got 
force_copy)	np
asanyarrayshaper)   r   r
   float32img_as_float32img_as_float64)r*   r5   r   r/   float_dtype_funcr0   r0   r1   _prepare_colorarray   s   


r>   c                 C   s2   t | ts	td| | k s| |krtdd S )Nzchannel_axis must be an integerz%channel_axis exceeds array dimensions)
isinstanceint	TypeErrorr6   	AxisError)r   ndimr0   r0   r1   _validate_channel_axis   s
   

rD      rF   rF   c          	      C   s  t | }t||j ||j }|j| dkr!d|j }t|t|j}|t jkr1t	|}nt
|}t ||j}t|dkrOtdt| dt |dk s]t |dkratdt||j|}|ttdd|d	 }|ttd|d	 }t jd| | ||  ddd
}|S )a&  RGBA to RGB conversion using alpha blending [1]_.

    Parameters
    ----------
    rgba : (..., 4, ...) array_like
        The image in RGBA format. By default, the final dimension denotes
        channels.
    background : array_like
        The color of the background to blend the image with (3 floats
        between 0 to 1 - the RGB value of the background).
    channel_axis : int, optional
        This parameter indicates which axis of the array corresponds to
        channels.

        .. versionadded:: 0.19
           ``channel_axis`` was added in 0.19.

    Returns
    -------
    out : (..., 3, ...) ndarray
        The image in RGB format. Same dimensions as input.

    Raises
    ------
    ValueError
        If `rgba` is not at least 2D with shape (..., 4, ...).

    References
    ----------
    .. [1] https://en.wikipedia.org/wiki/Alpha_compositing#Alpha_blending

    Examples
    --------
    >>> from skimage import color
    >>> from skimage import data
    >>> img_rgba = data.logo()
    >>> img_rgb = color.rgba2rgb(img_rgba)
       z;the input array must have size 4 along `channel_axis`, got r3   z>background must be an array-like containing 3 RGB values. Got z itemsr   rF   z5background RGB values must be floats between 0 and 1.axisa_mina_max)r6   r7   rD   rC   r8   r)   r   r
   r9   r:   r;   ravelastypelenanyr   r	   sliceclip)	rgba
backgroundr   r*   r/   r<   alphachannelsoutr0   r0   r1   rgba2rgb   s4   
'




rX   c                C   sr  | j dk}|r| tjdf } t| dd}t|}|d}|d}tjdd}|| }d||dk< |d |k}	||	df ||	d	f  ||	  ||	d
f< |d |k}	d||	d	f ||	d
f  ||	   ||	d
f< |d |k}	d||	d
f ||	df  ||	   ||	d
f< |d d d }
d|
|dk< tjdi | |
|d< ||d< ||d< d
|t|< |rtj	|d
d}|S )a  RGB to HSV color space conversion.

    Parameters
    ----------
    rgb : (..., 3, ...) array_like
        The image in RGB format. By default, the final dimension denotes
        channels.
    channel_axis : int, optional
        This parameter indicates which axis of the array corresponds to
        channels.

        .. versionadded:: 0.19
           ``channel_axis`` was added in 0.19.

    Returns
    -------
    out : (..., 3, ...) ndarray
        The image in HSV format. Same dimensions as input.

    Raises
    ------
    ValueError
        If `rgb` is not at least 2-D with shape (..., 3, ...).

    Notes
    -----
    Conversion between RGB and HSV color spaces results in some loss of
    precision, due to integer arithmetic and rounding [1]_.

    References
    ----------
    .. [1] https://en.wikipedia.org/wiki/HSL_and_HSV

    Examples
    --------
    >>> from skimage import color
    >>> from skimage import data
    >>> img = data.astronaut()
    >>> img_hsv = color.rgb2hsv(img)
    rF   .r   r   ignore)invalid        .r   r   r   .rF   g       @.r         @g      @      ?rH   Nr0   )
rC   r6   newaxisr>   
empty_likemaxptpseterrisnansqueeze)r   r   input_is_one_pixelr*   rW   out_vdeltaold_settingsout_sidxout_hr0   r0   r1   r      s4   
*


(,,r   c          
      C   s   t | dd}t|d d }|d d | }|d d|d   }|d d||d    }|d dd| |d    }|d }tj|||gddtjd }t|ttj|||fddtj|||fddtj|||fddtj|||fddtj|||fddtj|||fddg}	|	S )	a  HSV to RGB color space conversion.

    Parameters
    ----------
    hsv : (..., 3, ...) array_like
        The image in HSV format. By default, the final dimension denotes
        channels.
    channel_axis : int, optional
        This parameter indicates which axis of the array corresponds to
        channels.

        .. versionadded:: 0.19
           ``channel_axis`` was added in 0.19.

    Returns
    -------
    out : (..., 3, ...) ndarray
        The image in RGB format. Same dimensions as input.

    Raises
    ------
    ValueError
        If `hsv` is not at least 2-D with shape (..., 3, ...).

    Notes
    -----
    Conversion between RGB and HSV color spaces results in some loss of
    precision, due to integer arithmetic and rounding [1]_.

    References
    ----------
    .. [1] https://en.wikipedia.org/wiki/HSL_and_HSV

    Examples
    --------
    >>> from skimage import data
    >>> img = data.astronaut()
    >>> img_hsv = rgb2hsv(img)
    >>> img_rgb = hsv2rgb(img_hsv)
    r   r   r\      r^   rF   r]   rH   )r>   r6   floorstackrN   uint8choose)
r   r   r*   hifpqtvrW   r0   r0   r1   r   >  s$   * r   )i  g@g<{@)gmЦmz?gX0Ҏu?g߼xV4r?g     j@)gƈDe?g	m9?gX9?)g_8?g	m9?gUy?)gKJ̓?g8n?gtBh?)g\(\?gףp=
?g?)e/?gH.?g0r.Ņ?)r[   g{Gz?Gz?rz   g333333?gjq?gL
F%u?)r   r   r   )gA`"?gbX9?gv/?)gxÅ¿gx|ҿg}?)g>?gb!zgE)g6?gQ#VѿgԿ)g?gR4Ag(q?)g4($ſgm3տ      ?)r}   gɑڿgܸд)gX9^P@gV-`@gK8@)gtBgER      \@)r~   gMrWgX962)gܿgK7AgS?)gSgB`"?g-?)g'@j?r`   gyuk?)gJA(Q?rF   gf?)gƿ`?rF   ga!?)210R)gN5z?rF   gt
L?)g;?rF   g$?)gh}a?rF   gr~?)gB\Vդ!?rF   gJ?)gIf?rF   gpBg?)g#Z?rF   g%vu??)gW?rF   gJA_?)gq@?rF   g|?)g&?rF   g~?)g5{v?rF   gs"cr?)gO	V?rF   g 7+?)gQ8D?rF   g3l]?)gT芔d?rF   gN?)gG6?rF   g	?M?)r`   r`   r`   )ABCD50D55D65D75Ec              	   C   sN   |   } |  }ztjt|  | |dW S  ty&   td|  d| dw )a9  Get the XYZ coordinates of the given illuminant and observer [1]_.

    Parameters
    ----------
    illuminant : {"A", "B", "C", "D50", "D55", "D65", "D75", "E"}, optional
        The name of the illuminant (the function is NOT case sensitive).
    observer : {"2", "10", "R"}, optional
        One of: 2-degree observer, 10-degree observer, or 'R' observer as in
        R function grDevices::convertColor.
    dtype: dtype, optional
        Output data type.

    Returns
    -------
    out : array
        Array with 3 elements containing the XYZ coordinates of the given
        illuminant.

    Raises
    ------
    ValueError
        If either the illuminant or the observer angle are not supported or
        unknown.

    References
    ----------
    .. [1] https://en.wikipedia.org/wiki/Standard_illuminant
    r
   z*Unknown illuminant/observer combination (`z`, `z`))upperr6   asarrayilluminantsKeyErrorr)   )
illuminantobserverr
   r0   r0   r1   get_xyz_coords  s   
r   )?gffffff?g(\?)gQ?r{   g)\(?)gHzG?=
ףp=?g(\?)r   gI+?gM?)gx&?r   gE?)r[   r[   r[   rF   )g܋?g*&
?gPﹺ?)g+GN?gcl0?=?gh)'?)g5F?g}o?gZ9Z!?)gm?g?g҈}?)g$+\b?gI
n<?gt?)gA?gTf?gqמ?)g*g\?g%Zx?g˙
?)g<R!?g:H?gi o?)gL?gūmG?g׼?)ge6ȷ?gx?g9Kl?)gzBy?g5Ĥ?g8oX?)gv?g1x==[?gZ4?)g@A?g(?g-5`?)glF?g>#K?gʨ2A?)g뉮?gFx$?g߽?)g&c`?g8?gH?)gq-s?g|	?g!?c                 C   s   t |}|| j|j S )a_  Do the color space conversion.

    Parameters
    ----------
    matrix : array_like
        The 3x3 matrix to use.
    arr : (..., 3, ...) array_like
        The input array. By default, the final dimension denotes
        channels.

    Returns
    -------
    out : (..., 3, ...) ndarray
        The converted array. Same dimensions as input.
    )r>   TrN   r
   )matrixr*   r0   r0   r1   _convertu  s   r   c                C   sV   t t| }|dk}dt|| d d ||< ||   d9  < tj|dd|d |S )	a$  XYZ to RGB color space conversion.

    Parameters
    ----------
    xyz : (..., 3, ...) array_like
        The image in XYZ format. By default, the final dimension denotes
        channels.
    channel_axis : int, optional
        This parameter indicates which axis of the array corresponds to
        channels.

        .. versionadded:: 0.19
           ``channel_axis`` was added in 0.19.

    Returns
    -------
    out : (..., 3, ...) ndarray
        The image in RGB format. Same dimensions as input.

    Raises
    ------
    ValueError
        If `xyz` is not at least 2-D with shape (..., 3, ...).

    Notes
    -----
    The CIE XYZ color space is derived from the CIE RGB color space. Note
    however that this function converts to sRGB.

    References
    ----------
    .. [1] https://en.wikipedia.org/wiki/CIE_1931_color_space

    Examples
    --------
    >>> from skimage import data
    >>> from skimage.color import rgb2xyz, xyz2rgb
    >>> img = data.astronaut()
    >>> img_xyz = rgb2xyz(img)
    >>> img_rgb = xyz2rgb(img_xyz)
    gsåi?zG?g?)\(?ףp=
)@r   rF   rW   )r   rgb_from_xyzr6   powerrR   )r   r   r*   maskr0   r0   r1   r     s   
-r   c                C   sX   t | dd }|dk}t|| d d d||< ||   d  < |tj|j S )a  RGB to XYZ color space conversion.

    Parameters
    ----------
    rgb : (..., 3, ...) array_like
        The image in RGB format. By default, the final dimension denotes
        channels.
    channel_axis : int, optional
        This parameter indicates which axis of the array corresponds to
        channels.

        .. versionadded:: 0.19
           ``channel_axis`` was added in 0.19.

    Returns
    -------
    out : (..., 3, ...) ndarray
        The image in XYZ format. Same dimensions as input.

    Raises
    ------
    ValueError
        If `rgb` is not at least 2-D with shape (..., 3, ...).

    Notes
    -----
    The CIE XYZ color space is derived from the CIE RGB color space. Note
    however that this function converts from sRGB.

    References
    ----------
    .. [1] https://en.wikipedia.org/wiki/CIE_1931_color_space

    Examples
    --------
    >>> from skimage import data
    >>> img = data.astronaut()
    >>> img_xyz = rgb2xyz(img)
    r   r   g?ܵ?r   r   g333333@r   )r>   copyr6   r   xyz_from_rgbr   rN   r
   )r   r   r*   r   r0   r0   r1   r!     s
   +r!   c                C   
   t t| S )ay  RGB to RGB CIE color space conversion.

    Parameters
    ----------
    rgb : (..., 3, ...) array_like
        The image in RGB format. By default, the final dimension denotes
        channels.
    channel_axis : int, optional
        This parameter indicates which axis of the array corresponds to
        channels.

        .. versionadded:: 0.19
           ``channel_axis`` was added in 0.19.

    Returns
    -------
    out : (..., 3, ...) ndarray
        The image in RGB CIE format. Same dimensions as input.

    Raises
    ------
    ValueError
        If `rgb` is not at least 2-D with shape (..., 3, ...).

    References
    ----------
    .. [1] https://en.wikipedia.org/wiki/CIE_1931_color_space

    Examples
    --------
    >>> from skimage import data
    >>> from skimage.color import rgb2rgbcie
    >>> img = data.astronaut()
    >>> img_rgbcie = rgb2rgbcie(img)
    )r   rgbcie_from_rgbr   r   r0   r0   r1   r      s   
%r    c                C   r   )a  RGB CIE to RGB color space conversion.

    Parameters
    ----------
    rgbcie : (..., 3, ...) array_like
        The image in RGB CIE format. By default, the final dimension denotes
        channels.
    channel_axis : int, optional
        This parameter indicates which axis of the array corresponds to
        channels.

        .. versionadded:: 0.19
           ``channel_axis`` was added in 0.19.

    Returns
    -------
    out : (..., 3, ...) ndarray
        The image in RGB format. Same dimensions as input.

    Raises
    ------
    ValueError
        If `rgbcie` is not at least 2-D with shape (..., 3, ...).

    References
    ----------
    .. [1] https://en.wikipedia.org/wiki/CIE_1931_color_space

    Examples
    --------
    >>> from skimage import data
    >>> from skimage.color import rgb2rgbcie, rgbcie2rgb
    >>> img = data.astronaut()
    >>> img_rgbcie = rgb2rgbcie(img)
    >>> img_rgb = rgbcie2rgb(img_rgbcie)
    )r   rgb_from_rgbcie)rgbcier   r0   r0   r1   r     s   
&r   )multichannel_outputc                C   s$   t | } tjg d| jd}| | S )a  Compute luminance of an RGB image.

    Parameters
    ----------
    rgb : (..., 3, ...) array_like
        The image in RGB format. By default, the final dimension denotes
        channels.

    Returns
    -------
    out : ndarray
        The luminance image - an array which is the same size as the input
        array, but with the channel dimension removed.

    Raises
    ------
    ValueError
        If `rgb` is not at least 2-D with shape (..., 3, ...).

    Notes
    -----
    The weights used in this conversion are calibrated for contemporary
    CRT phosphors::

        Y = 0.2125 R + 0.7154 G + 0.0721 B

    If there is an alpha channel present, it is ignored.

    References
    ----------
    .. [1] http://poynton.ca/PDFs/ColorFAQ.pdf

    Examples
    --------
    >>> from skimage.color import rgb2gray
    >>> from skimage import data
    >>> img = data.astronaut()
    >>> img_gray = rgb2gray(img)
    r|   r   )r>   r6   arrayr
   )r   r   coeffsr0   r0   r1   rgb2grayB  s   )r   c                C   s   t | }t|dd\}}|du r|}t ||js%td|jj dd t |r5t j|j	||jd}n
|j	|j	kr?t
dt j|fd	 |f |d
}|S )a  Create a RGBA representation of a gray-level image.

    Parameters
    ----------
    image : array_like
        Input image.
    alpha : array_like, optional
        Alpha channel of the output image. It may be a scalar or an
        array that can be broadcast to ``image``. If not specified it is
        set to the maximum limit corresponding to the ``image`` dtype.
    channel_axis : int, optional
        This parameter indicates which axis of the output array will correspond
        to channels.

        .. versionadded:: 0.19
           ``channel_axis`` was added in 0.19.

    Returns
    -------
    rgba : ndarray
        RGBA image. A new dimension of length 4 is added to input
        image shape.
    F)clip_negativeNz+alpha cannot be safely cast to image dtype r   
stacklevelr   z"alpha.shape must match image.shaper3   rH   )r6   r   r   can_castr
   r   nameisscalarfullr8   r)   rq   )imagerU   r   r*   	alpha_min	alpha_maxrS   r0   r0   r1   	gray2rgbap  s   

r   c                C   s   t jd| f |dS )a  Create an RGB representation of a gray-level image.

    Parameters
    ----------
    image : array_like
        Input image.
    channel_axis : int, optional
        This parameter indicates which axis of the output array will correspond
        to channels.

    Returns
    -------
    rgb : (..., 3, ...) ndarray
        RGB image. A new dimension of length 3 is added to input image.

    Notes
    -----
    If the input is a 1-dimensional image of shape ``(M, )``, the output
    will be shape ``(M, 3)``.
    r3   rH   )r6   rq   )r   r   r0   r0   r1   gray2rgb  s   r   r   r   c                C   s   t | dd}t|||j}|| }|dk}t|| ||< d||   d || < |d |d |d }}}	d	| d
 }
d||  }d||	  }tjdd |
||fD ddS )aC  XYZ to CIE-LAB color space conversion.

    Parameters
    ----------
    xyz : (..., 3, ...) array_like
        The image in XYZ format. By default, the final dimension denotes
        channels.
    illuminant : {"A", "B", "C", "D50", "D55", "D65", "D75", "E"}, optional
        The name of the illuminant (the function is NOT case sensitive).
    observer : {"2", "10", "R"}, optional
        One of: 2-degree observer, 10-degree observer, or 'R' observer as in
        R function grDevices::convertColor.
    channel_axis : int, optional
        This parameter indicates which axis of the array corresponds to
        channels.

        .. versionadded:: 0.19
           ``channel_axis`` was added in 0.19.

    Returns
    -------
    out : (..., 3, ...) ndarray
        The image in CIE-LAB format. Same dimensions as input.

    Raises
    ------
    ValueError
        If `xyz` is not at least 2-D with shape (..., 3, ...).
    ValueError
        If either the illuminant or the observer angle is unsupported or
        unknown.

    Notes
    -----
    By default Observer="2", Illuminant="D65". CIE XYZ tristimulus values
    x_ref=95.047, y_ref=100., z_ref=108.883. See function `get_xyz_coords` for
    a list of supported illuminants.

    References
    ----------
    .. [1] http://www.easyrgb.com/index.php?X=MATH&H=07
    .. [2] https://en.wikipedia.org/wiki/Lab_color_space

    Examples
    --------
    >>> from skimage import data
    >>> from skimage.color import rgb2xyz, xyz2lab
    >>> img = data.astronaut()
    >>> img_xyz = rgb2xyz(img)
    >>> img_lab = xyz2lab(img_xyz)
    r   r   玬2#?S%@{a?r\   r]   r^         ]@      0@     @@      i@c                 S      g | ]	}|d t jf qS .r6   ra   ).0xr0   r0   r1   
<listcomp>      zxyz2lab.<locals>.<listcomp>rH   )r>   r   r
   r6   cbrtconcatenate)r   r   r   r   r*   xyz_ref_whiter   r   yzLabr0   r0   r1   xyz2lab  s   5r   c                C   s   t | dd }|d |d |d }}}|d d }|d | }	||d	  }
t|
d
k rEt|
d
k }td|d
 j dd d
|
|< tj|	||
gdd}|dk}t|| d||< ||  d d || < t	||}||9 }|S )al  CIE-LAB to XYZcolor space conversion.

    Parameters
    ----------
    lab : (..., 3, ...) array_like
        The image in Lab format. By default, the final dimension denotes
        channels.
    illuminant : {"A", "B", "C", "D50", "D55", "D65", "D75", "E"}, optional
        The name of the illuminant (the function is NOT case sensitive).
    observer : {"2", "10", "R"}, optional
        The aperture angle of the observer.
    channel_axis : int, optional
        This parameter indicates which axis of the array corresponds to
        channels.

        .. versionadded:: 0.19
           ``channel_axis`` was added in 0.19.

    Returns
    -------
    out : (..., 3, ...) ndarray
        The image in XYZ format. Same dimensions as input.

    Raises
    ------
    ValueError
        If `lab` is not at least 2-D with shape (..., 3, ...).
    ValueError
        If either the illuminant or the observer angle are not supported or
        unknown.
    UserWarning
        If any of the pixels are invalid (Z < 0).

    Notes
    -----
    By default Observer="2", Illuminant="D65". CIE XYZ tristimulus values x_ref
    = 95.047, y_ref = 100., z_ref = 108.883. See function 'get_xyz_coords' for
    a list of supported illuminants.

    References
    ----------
    .. [1] http://www.easyrgb.com/index.php?X=MATH&H=07
    .. [2] https://en.wikipedia.org/wiki/Lab_color_space
    r   r   r\   r]   r^   r   r   r   r   r   z+Color data out of range: Z < 0 in %s pixelsr   r   rH   gSy{?      @r   r   )
r>   r   r6   rP   nonzeror   sizerq   r   r   )labr   r   r   r*   r   r   r   r   r   r   rZ   rW   r   r   r0   r0   r1   lab2xyz  s$   .
r   c                C   s   t t| ||S )a  Conversion from the sRGB color space (IEC 61966-2-1:1999)
    to the CIE Lab colorspace under the given illuminant and observer.

    Parameters
    ----------
    rgb : (..., 3, ...) array_like
        The image in RGB format. By default, the final dimension denotes
        channels.
    illuminant : {"A", "B", "C", "D50", "D55", "D65", "D75", "E"}, optional
        The name of the illuminant (the function is NOT case sensitive).
    observer : {"2", "10", "R"}, optional
        The aperture angle of the observer.
    channel_axis : int, optional
        This parameter indicates which axis of the array corresponds to
        channels.

        .. versionadded:: 0.19
           ``channel_axis`` was added in 0.19.

    Returns
    -------
    out : (..., 3, ...) ndarray
        The image in Lab format. Same dimensions as input.

    Raises
    ------
    ValueError
        If `rgb` is not at least 2-D with shape (..., 3, ...).

    Notes
    -----
    RGB is a device-dependent color space so, if you use this function, be
    sure that the image you are analyzing has been mapped to the sRGB color
    space.

    This function uses rgb2xyz and xyz2lab.
    By default Observer="2", Illuminant="D65". CIE XYZ tristimulus values
    x_ref=95.047, y_ref=100., z_ref=108.883. See function `get_xyz_coords` for
    a list of supported illuminants.

    References
    ----------
    .. [1] https://en.wikipedia.org/wiki/Standard_illuminant
    )r   r!   )r   r   r   r   r0   r0   r1   rgb2labE  s   .r   c                C   s   t t| ||S )a  Lab to RGB color space conversion.

    Parameters
    ----------
    lab : (..., 3, ...) array_like
        The image in Lab format. By default, the final dimension denotes
        channels.
    illuminant : {"A", "B", "C", "D50", "D55", "D65", "D75", "E"}, optional
        The name of the illuminant (the function is NOT case sensitive).
    observer : {"2", "10", "R"}, optional
        The aperture angle of the observer.
    channel_axis : int, optional
        This parameter indicates which axis of the array corresponds to
        channels.

        .. versionadded:: 0.19
           ``channel_axis`` was added in 0.19.

    Returns
    -------
    out : (..., 3, ...) ndarray
        The image in RGB format. Same dimensions as input.

    Raises
    ------
    ValueError
        If `lab` is not at least 2-D with shape (..., 3, ...).

    Notes
    -----
    This function uses lab2xyz and xyz2rgb.
    By default Observer="2", Illuminant="D65". CIE XYZ tristimulus values
    x_ref=95.047, y_ref=100., z_ref=108.883. See function `get_xyz_coords` for
    a list of supported illuminants.

    References
    ----------
    .. [1] https://en.wikipedia.org/wiki/Standard_illuminant
    )r   r   )r   r   r   r   r0   r0   r1   lab2rgbv  s   )r   c                   sD  | j dk}|r| tjdf } t| dd}|d |d |d }}}ttj tt||}	||	d  }
|
dk}d	t	|
|  d
 |
|< d|
|   |
| < d|	d  g d|	  }d|	d  g d|	  } fdd} fdd}d|
 |||||  }d|
 |||||  }tj
|
||gdd}|rtj|dd}|S )a$  XYZ to CIE-Luv color space conversion.

    Parameters
    ----------
    xyz : (..., 3, ...) array_like
        The image in XYZ format. By default, the final dimension denotes
        channels.
    illuminant : {"A", "B", "C", "D50", "D55", "D65", "D75", "E"}, optional
        The name of the illuminant (the function is NOT case sensitive).
    observer : {"2", "10", "R"}, optional
        The aperture angle of the observer.
    channel_axis : int, optional
        This parameter indicates which axis of the array corresponds to
        channels.

        .. versionadded:: 0.19
           ``channel_axis`` was added in 0.19.

    Returns
    -------
    out : (..., 3, ...) ndarray
        The image in CIE-Luv format. Same dimensions as input.

    Raises
    ------
    ValueError
        If `xyz` is not at least 2-D with shape (..., 3, ...).
    ValueError
        If either the illuminant or the observer angle are not supported or
        unknown.

    Notes
    -----
    By default XYZ conversion weights use observer=2A. Reference whitepoint
    for D65 Illuminant, with XYZ tristimulus values of ``(95.047, 100.,
    108.883)``. See function 'get_xyz_coords' for a list of supported
    illuminants.

    References
    ----------
    .. [1] http://www.easyrgb.com/index.php?X=MATH&H=16#text16
    .. [2] https://en.wikipedia.org/wiki/CIELUV

    Examples
    --------
    >>> from skimage import data
    >>> from skimage.color import rgb2xyz, xyz2luv
    >>> img = data.astronaut()
    >>> img_xyz = rgb2xyz(img)
    >>> img_luv = xyz2luv(img_xyz)
    rF   .r   r   r\   r]   r^   r   r   r   fffff:@rG   r   rF      r3   	   c                    s    d|  | d|  d|     S )Nr_         .@r   r0   XYZepsr0   r1   fu      zxyz2luv.<locals>.fuc                    s    d| | d|  d|     S )Ng      "@r   r   r0   r   r   r0   r1   fv  r   zxyz2luv.<locals>.fv      *@rH   )rC   r6   ra   r>   finfofloatr   r   r   r   rq   rg   )r   r   r   r   rh   r*   r   r   r   r   r   r   u0v0r   r   ury   rW   r0   r   r1   xyz2luv  s*   
5r   c                C   sT  t | dd }|d |d |d }}}ttj}| }	|	dk}
t|	|
 d d d	|	|
< |	|
  d
 |	|
 < t||}|	|d 9 }	tg d}d|d  ||  }d|d  ||  }||d| |   }||d| |   }d|	 d| d  }|d | d| | |	  d|  }|| d	|   }tj	dd ||	|fD ddS )aE  CIE-Luv to XYZ color space conversion.

    Parameters
    ----------
    luv : (..., 3, ...) array_like
        The image in CIE-Luv format. By default, the final dimension denotes
        channels.
    illuminant : {"A", "B", "C", "D50", "D55", "D65", "D75", "E"}, optional
        The name of the illuminant (the function is NOT case sensitive).
    observer : {"2", "10", "R"}, optional
        The aperture angle of the observer.
    channel_axis : int, optional
        This parameter indicates which axis of the array corresponds to
        channels.

        .. versionadded:: 0.19
           ``channel_axis`` was added in 0.19.

    Returns
    -------
    out : (..., 3, ...) ndarray
        The image in XYZ format. Same dimensions as input.

    Raises
    ------
    ValueError
        If `luv` is not at least 2-D with shape (..., 3, ...).
    ValueError
        If either the illuminant or the observer angle are not supported or
        unknown.

    Notes
    -----
    XYZ conversion weights use observer=2A. Reference whitepoint for D65
    Illuminant, with XYZ tristimulus values of ``(95.047, 100., 108.883)``. See
    function 'get_xyz_coords' for a list of supported illuminants.

    References
    ----------
    .. [1] http://www.easyrgb.com/index.php?X=MATH&H=16#text16
    .. [2] https://en.wikipedia.org/wiki/CIELUV
    r   r   r\   r]   r^   gV-@r   r   r   r   rF   r   rG   r   r   r   r3      r      c                 S   r   r   r   )r   rw   r0   r0   r1   r   G  r   zluv2xyz.<locals>.<listcomp>rH   )
r>   r   r6   r   r   r   r   r   r   r   )luvr   r   r   r*   r   r   ry   r   r   r   r   
uv_weightsr   r   r   r   cr   r   r0   r0   r1   luv2xyz  s$   ,
$r   c                C      t t| S )a|  RGB to CIE-Luv color space conversion.

    Parameters
    ----------
    rgb : (..., 3, ...) array_like
        The image in RGB format. By default, the final dimension denotes
        channels.
    channel_axis : int, optional
        This parameter indicates which axis of the array corresponds to
        channels.

        .. versionadded:: 0.19
           ``channel_axis`` was added in 0.19.

    Returns
    -------
    out : (..., 3, ...) ndarray
        The image in CIE Luv format. Same dimensions as input.

    Raises
    ------
    ValueError
        If `rgb` is not at least 2-D with shape (..., 3, ...).

    Notes
    -----
    This function uses rgb2xyz and xyz2luv.

    References
    ----------
    .. [1] http://www.easyrgb.com/index.php?X=MATH&H=16#text16
    .. [2] http://www.easyrgb.com/index.php?X=MATH&H=02#text2
    .. [3] https://en.wikipedia.org/wiki/CIELUV
    )r   r!   r   r0   r0   r1   rgb2luvJ  s   $r   c                C   r   )a  Luv to RGB color space conversion.

    Parameters
    ----------
    luv : (..., 3, ...) array_like
        The image in CIE Luv format. By default, the final dimension denotes
        channels.

    Returns
    -------
    out : (..., 3, ...) ndarray
        The image in RGB format. Same dimensions as input.

    Raises
    ------
    ValueError
        If `luv` is not at least 2-D with shape (..., 3, ...).

    Notes
    -----
    This function uses luv2xyz and xyz2rgb.
    )r   r   )r   r   r0   r0   r1   luv2rgbq  s   r   c                C   
   t | tS )a  RGB to Haematoxylin-Eosin-DAB (HED) color space conversion.

    Parameters
    ----------
    rgb : (..., 3, ...) array_like
        The image in RGB format. By default, the final dimension denotes
        channels.
    channel_axis : int, optional
        This parameter indicates which axis of the array corresponds to
        channels.

        .. versionadded:: 0.19
           ``channel_axis`` was added in 0.19.

    Returns
    -------
    out : (..., 3, ...) ndarray
        The image in HED format. Same dimensions as input.

    Raises
    ------
    ValueError
        If `rgb` is not at least 2-D with shape (..., 3, ...).

    References
    ----------
    .. [1] A. C. Ruifrok and D. A. Johnston, "Quantification of histochemical
           staining by color deconvolution.," Analytical and quantitative
           cytology and histology / the International Academy of Cytology [and]
           American Society of Cytology, vol. 23, no. 4, pp. 291-9, Aug. 2001.

    Examples
    --------
    >>> from skimage import data
    >>> from skimage.color import rgb2hed
    >>> ihc = data.immunohistochemistry()
    >>> ihc_hed = rgb2hed(ihc)
    )separate_stainshed_from_rgbr   r0   r0   r1   rgb2hed  s   
(r   c                C   r   )a  Haematoxylin-Eosin-DAB (HED) to RGB color space conversion.

    Parameters
    ----------
    hed : (..., 3, ...) array_like
        The image in the HED color space. By default, the final dimension
        denotes channels.
    channel_axis : int, optional
        This parameter indicates which axis of the array corresponds to
        channels.

        .. versionadded:: 0.19
           ``channel_axis`` was added in 0.19.

    Returns
    -------
    out : (..., 3, ...) ndarray
        The image in RGB. Same dimensions as input.

    Raises
    ------
    ValueError
        If `hed` is not at least 2-D with shape (..., 3, ...).

    References
    ----------
    .. [1] A. C. Ruifrok and D. A. Johnston, "Quantification of histochemical
           staining by color deconvolution.," Analytical and quantitative
           cytology and histology / the International Academy of Cytology [and]
           American Society of Cytology, vol. 23, no. 4, pp. 291-9, Aug. 2001.

    Examples
    --------
    >>> from skimage import data
    >>> from skimage.color import rgb2hed, hed2rgb
    >>> ihc = data.immunohistochemistry()
    >>> ihc_hed = rgb2hed(ihc)
    >>> ihc_rgb = hed2rgb(ihc_hed)
    )combine_stainsrgb_from_hed)hedr   r0   r0   r1   hed2rgb  s   
)r   c                C   sN   t | ddd} tj| d| d td}t| | | }tj|d|d |S )u  RGB to stain color space conversion.

    Parameters
    ----------
    rgb : (..., 3, ...) array_like
        The image in RGB format. By default, the final dimension denotes
        channels.
    conv_matrix: ndarray
        The stain separation matrix as described by G. Landini [1]_.
    channel_axis : int, optional
        This parameter indicates which axis of the array corresponds to
        channels.

        .. versionadded:: 0.19
           ``channel_axis`` was added in 0.19.

    Returns
    -------
    out : (..., 3, ...) ndarray
        The image in stain color space. Same dimensions as input.

    Raises
    ------
    ValueError
        If `rgb` is not at least 2-D with shape (..., 3, ...).

    Notes
    -----
    Stain separation matrices available in the ``color`` module and their
    respective colorspace:

    * ``hed_from_rgb``: Hematoxylin + Eosin + DAB
    * ``hdx_from_rgb``: Hematoxylin + DAB
    * ``fgx_from_rgb``: Feulgen + Light Green
    * ``bex_from_rgb``: Giemsa stain : Methyl Blue + Eosin
    * ``rbd_from_rgb``: FastRed + FastBlue +  DAB
    * ``gdx_from_rgb``: Methyl Green + DAB
    * ``hax_from_rgb``: Hematoxylin + AEC
    * ``bro_from_rgb``: Blue matrix Anilline Blue + Red matrix Azocarmine                        + Orange matrix Orange-G
    * ``bpx_from_rgb``: Methyl Blue + Ponceau Fuchsin
    * ``ahx_from_rgb``: Alcian Blue + Hematoxylin
    * ``hpx_from_rgb``: Hematoxylin + PAS

    This implementation borrows some ideas from DIPlib [2]_, e.g. the
    compensation using a small value to avoid log artifacts when
    calculating the Beer-Lambert law.

    References
    ----------
    .. [1] https://web.archive.org/web/20160624145052/http://www.mecourse.com/landinig/software/cdeconv/cdeconv.html
    .. [2] https://github.com/DIPlib/diplib/
    .. [3] A. C. Ruifrok and D. A. Johnston, “Quantification of histochemical
           staining by color deconvolution,” Anal. Quant. Cytol. Histol., vol.
           23, no. 4, pp. 291–299, Aug. 2001.

    Examples
    --------
    >>> from skimage import data
    >>> from skimage.color import separate_stains, hdx_from_rgb
    >>> ihc = data.immunohistochemistry()
    >>> ihc_hdx = separate_stains(ihc, hdx_from_rgb)
    Tr   )r5   r   ư>r   r   )r>   r6   maximumlog)r   conv_matrixr   
log_adjuststainsr0   r0   r1   r     s   A
r   c                C   s@   t | dd} td }| |  | }t|}tj|dddS )uc  Stain to RGB color space conversion.

    Parameters
    ----------
    stains : (..., 3, ...) array_like
        The image in stain color space. By default, the final dimension denotes
        channels.
    conv_matrix: ndarray
        The stain separation matrix as described by G. Landini [1]_.
    channel_axis : int, optional
        This parameter indicates which axis of the array corresponds to
        channels.

        .. versionadded:: 0.19
           ``channel_axis`` was added in 0.19.

    Returns
    -------
    out : (..., 3, ...) ndarray
        The image in RGB format. Same dimensions as input.

    Raises
    ------
    ValueError
        If `stains` is not at least 2-D with shape (..., 3, ...).

    Notes
    -----
    Stain combination matrices available in the ``color`` module and their
    respective colorspace:

    * ``rgb_from_hed``: Hematoxylin + Eosin + DAB
    * ``rgb_from_hdx``: Hematoxylin + DAB
    * ``rgb_from_fgx``: Feulgen + Light Green
    * ``rgb_from_bex``: Giemsa stain : Methyl Blue + Eosin
    * ``rgb_from_rbd``: FastRed + FastBlue +  DAB
    * ``rgb_from_gdx``: Methyl Green + DAB
    * ``rgb_from_hax``: Hematoxylin + AEC
    * ``rgb_from_bro``: Blue matrix Anilline Blue + Red matrix Azocarmine                        + Orange matrix Orange-G
    * ``rgb_from_bpx``: Methyl Blue + Ponceau Fuchsin
    * ``rgb_from_ahx``: Alcian Blue + Hematoxylin
    * ``rgb_from_hpx``: Hematoxylin + PAS

    References
    ----------
    .. [1] https://web.archive.org/web/20160624145052/http://www.mecourse.com/landinig/software/cdeconv/cdeconv.html
    .. [2] A. C. Ruifrok and D. A. Johnston, “Quantification of histochemical
           staining by color deconvolution,” Anal. Quant. Cytol. Histol., vol.
           23, no. 4, pp. 291–299, Aug. 2001.

    Examples
    --------
    >>> from skimage import data
    >>> from skimage.color import (separate_stains, combine_stains,
    ...                            hdx_from_rgb, rgb_from_hdx)
    >>> ihc = data.immunohistochemistry()
    >>> ihc_hdx = separate_stains(ihc, hdx_from_rgb)
    >>> ihc_rgb = combine_stains(ihc_hdx, rgb_from_hdx)
    r   r   r   r   rF   rJ   )r>   r6   r   exprR   )r   r   r   r   log_rgbr   r0   r0   r1   r   /  s
   >
r   c                C   s4   t | }|d |d }}t||\|d< |d< |S )au  CIE-LAB to CIE-LCH color space conversion.

    LCH is the cylindrical representation of the LAB (Cartesian) colorspace

    Parameters
    ----------
    lab : (..., 3, ...) array_like
        The N-D image in CIE-LAB format. The last (``N+1``-th) dimension must
        have at least 3 elements, corresponding to the ``L``, ``a``, and ``b``
        color channels. Subsequent elements are copied.
    channel_axis : int, optional
        This parameter indicates which axis of the array corresponds to
        channels.

        .. versionadded:: 0.19
           ``channel_axis`` was added in 0.19.

    Returns
    -------
    out : (..., 3, ...) ndarray
        The image in LCH format, in a N-D array with same shape as input `lab`.

    Raises
    ------
    ValueError
        If `lch` does not have at least 3 color channels (i.e. l, a, b).

    Notes
    -----
    The Hue is expressed as an angle between ``(0, 2*pi)``

    Examples
    --------
    >>> from skimage import data
    >>> from skimage.color import rgb2lab, lab2lch
    >>> img = data.astronaut()
    >>> img_lab = rgb2lab(img)
    >>> img_lch = lab2lch(img_lab)
    r]   r^   )_prepare_lab_array_cart2polar_2pi)r   r   lchr   r   r0   r0   r1   lab2lchw  s   )r  c                 C   s>   t | |t || }}|t |dk dt j d7 }||fS )zconvert cartesian coordinates to polar (uses non-standard theta range!)

    NON-STANDARD RANGE! Maps to ``(0, 2*pi)`` rather than usual ``(-pi, +pi)``
    r[   r   r   )r6   hypotarctan2wherepi)r   r   rrx   r0   r0   r1   r    s   r  c                C   sD   t | } | d | d }}|t| |t| | d< | d< | S )aD  CIE-LCH to CIE-LAB color space conversion.

    LCH is the cylindrical representation of the LAB (Cartesian) colorspace

    Parameters
    ----------
    lch : (..., 3, ...) array_like
        The N-D image in CIE-LCH format. The last (``N+1``-th) dimension must
        have at least 3 elements, corresponding to the ``L``, ``a``, and ``b``
        color channels.  Subsequent elements are copied.
    channel_axis : int, optional
        This parameter indicates which axis of the array corresponds to
        channels.

        .. versionadded:: 0.19
           ``channel_axis`` was added in 0.19.

    Returns
    -------
    out : (..., 3, ...) ndarray
        The image in LAB format, with same shape as input `lch`.

    Raises
    ------
    ValueError
        If `lch` does not have at least 3 color channels (i.e. l, c, h).

    Examples
    --------
    >>> from skimage import data
    >>> from skimage.color import rgb2lab, lch2lab, lab2lch
    >>> img = data.astronaut()
    >>> img_lab = rgb2lab(img)
    >>> img_lch = lab2lch(img_lab)
    >>> img_lab2 = lch2lab(img_lch)
    r]   r^   )r  r6   cossin)r  r   r   hr0   r0   r1   lch2lab  s   &&r  Tc                 C   sR   t | } | j}|d dk rtdt| j}|t jkr tj}ntj}|| |dS )zEnsure input for lab2lch, lch2lab are well-posed.

    Arrays must be in floating point and have at least 3 elements in
    last dimension.  Return a new array.
    r   r3   z*Input array has less than 3 color channelsr4   )	r6   r   r8   r)   r   r
   r9   r:   r;   )r*   r5   r8   r<   r=   r0   r0   r1   r    s   


r  c                C   r   )aR  RGB to YUV color space conversion.

    Parameters
    ----------
    rgb : (..., 3, ...) array_like
        The image in RGB format. By default, the final dimension denotes
        channels.
    channel_axis : int, optional
        This parameter indicates which axis of the array corresponds to
        channels.

        .. versionadded:: 0.19
           ``channel_axis`` was added in 0.19.

    Returns
    -------
    out : (..., 3, ...) ndarray
        The image in YUV format. Same dimensions as input.

    Raises
    ------
    ValueError
        If `rgb` is not at least 2-D with shape (..., 3, ...).

    Notes
    -----
    Y is between 0 and 1.  Use YCbCr instead of YUV for the color space
    commonly used by video codecs, where Y ranges from 16 to 235.

    References
    ----------
    .. [1] https://en.wikipedia.org/wiki/YUV
    )r   yuv_from_rgbr   r0   r0   r1   r"        
#r"   c                C   r   )ag  RGB to YIQ color space conversion.

    Parameters
    ----------
    rgb : (..., 3, ...) array_like
        The image in RGB format. By default, the final dimension denotes
        channels.
    channel_axis : int, optional
        This parameter indicates which axis of the array corresponds to
        channels.

        .. versionadded:: 0.19
           ``channel_axis`` was added in 0.19.

    Returns
    -------
    out : (..., 3, ...) ndarray
        The image in YIQ format. Same dimensions as input.

    Raises
    ------
    ValueError
        If `rgb` is not at least 2-D with shape (..., 3, ...).
    )r   yiq_from_rgbr   r0   r0   r1   r#        
r#   c                C   r   )a  RGB to YPbPr color space conversion.

    Parameters
    ----------
    rgb : (..., 3, ...) array_like
        The image in RGB format. By default, the final dimension denotes
        channels.
    channel_axis : int, optional
        This parameter indicates which axis of the array corresponds to
        channels.

        .. versionadded:: 0.19
           ``channel_axis`` was added in 0.19.

    Returns
    -------
    out : (..., 3, ...) ndarray
        The image in YPbPr format. Same dimensions as input.

    Raises
    ------
    ValueError
        If `rgb` is not at least 2-D with shape (..., 3, ...).

    References
    ----------
    .. [1] https://en.wikipedia.org/wiki/YPbPr
    )r   ypbpr_from_rgbr   r0   r0   r1   r$   3     
r$   c                C   s>   t t| }|d  d7  < |d  d7  < |d  d7  < |S )aP  RGB to YCbCr color space conversion.

    Parameters
    ----------
    rgb : (..., 3, ...) array_like
        The image in RGB format. By default, the final dimension denotes
        channels.
    channel_axis : int, optional
        This parameter indicates which axis of the array corresponds to
        channels.

        .. versionadded:: 0.19
           ``channel_axis`` was added in 0.19.

    Returns
    -------
    out : (..., 3, ...) ndarray
        The image in YCbCr format. Same dimensions as input.

    Raises
    ------
    ValueError
        If `rgb` is not at least 2-D with shape (..., 3, ...).

    Notes
    -----
    Y is between 16 and 235. This is the color space commonly used by video
    codecs; it is sometimes incorrectly called "YUV".

    References
    ----------
    .. [1] https://en.wikipedia.org/wiki/YCbCr
    r\      r]      r^   )r   ycbcr_from_rgbr   r   r*   r0   r0   r1   r%   T  s
   
#r%   c                C   s   t t| }|S )aD  RGB to YDbDr color space conversion.

    Parameters
    ----------
    rgb : (..., 3, ...) array_like
        The image in RGB format. By default, the final dimension denotes
        channels.
    channel_axis : int, optional
        This parameter indicates which axis of the array corresponds to
        channels.

        .. versionadded:: 0.19
           ``channel_axis`` was added in 0.19.

    Returns
    -------
    out : (..., 3, ...) ndarray
        The image in YDbDr format. Same dimensions as input.

    Raises
    ------
    ValueError
        If `rgb` is not at least 2-D with shape (..., 3, ...).

    Notes
    -----
    This is the color space commonly used by video codecs. It is also the
    reversible color transform in JPEG2000.

    References
    ----------
    .. [1] https://en.wikipedia.org/wiki/YDbDr
    )r   ydbdr_from_rgbr  r0   r0   r1   r&   ~  s   
#r&   c                C   r   )a  YUV to RGB color space conversion.

    Parameters
    ----------
    yuv : (..., 3, ...) array_like
        The image in YUV format. By default, the final dimension denotes
        channels.

    Returns
    -------
    out : (..., 3, ...) ndarray
        The image in RGB format. Same dimensions as input.

    Raises
    ------
    ValueError
        If `yuv` is not at least 2-D with shape (..., 3, ...).

    References
    ----------
    .. [1] https://en.wikipedia.org/wiki/YUV
    )r   rgb_from_yuv)r   r   r0   r0   r1   r     s   
r   c                C   r   )ag  YIQ to RGB color space conversion.

    Parameters
    ----------
    yiq : (..., 3, ...) array_like
        The image in YIQ format. By default, the final dimension denotes
        channels.
    channel_axis : int, optional
        This parameter indicates which axis of the array corresponds to
        channels.

        .. versionadded:: 0.19
           ``channel_axis`` was added in 0.19.

    Returns
    -------
    out : (..., 3, ...) ndarray
        The image in RGB format. Same dimensions as input.

    Raises
    ------
    ValueError
        If `yiq` is not at least 2-D with shape (..., 3, ...).
    )r   rgb_from_yiq)r   r   r0   r0   r1   r     r  r   c                C   r   )a  YPbPr to RGB color space conversion.

    Parameters
    ----------
    ypbpr : (..., 3, ...) array_like
        The image in YPbPr format. By default, the final dimension denotes
        channels.
    channel_axis : int, optional
        This parameter indicates which axis of the array corresponds to
        channels.

        .. versionadded:: 0.19
           ``channel_axis`` was added in 0.19.

    Returns
    -------
    out : (..., 3, ...) ndarray
        The image in RGB format. Same dimensions as input.

    Raises
    ------
    ValueError
        If `ypbpr` is not at least 2-D with shape (..., 3, ...).

    References
    ----------
    .. [1] https://en.wikipedia.org/wiki/YPbPr
    )r   rgb_from_ypbpr)r   r   r0   r0   r1   r     r  r   c                C   sB   |   }|d  d8  < |d  d8  < |d  d8  < tt|S )aT  YCbCr to RGB color space conversion.

    Parameters
    ----------
    ycbcr : (..., 3, ...) array_like
        The image in YCbCr format. By default, the final dimension denotes
        channels.
    channel_axis : int, optional
        This parameter indicates which axis of the array corresponds to
        channels.

        .. versionadded:: 0.19
           ``channel_axis`` was added in 0.19.

    Returns
    -------
    out : (..., 3, ...) ndarray
        The image in RGB format. Same dimensions as input.

    Raises
    ------
    ValueError
        If `ycbcr` is not at least 2-D with shape (..., 3, ...).

    Notes
    -----
    Y is between 16 and 235. This is the color space commonly used by video
    codecs; it is sometimes incorrectly called "YUV".

    References
    ----------
    .. [1] https://en.wikipedia.org/wiki/YCbCr
    r\   r  r]   r  r^   )r   r   rgb_from_ycbcr)r   r   r*   r0   r0   r1   r     s
   #
r   c                C   r   )aI  YDbDr to RGB color space conversion.

    Parameters
    ----------
    ydbdr : (..., 3, ...) array_like
        The image in YDbDr format. By default, the final dimension denotes
        channels.
    channel_axis : int, optional
        This parameter indicates which axis of the array corresponds to
        channels.

        .. versionadded:: 0.19
           ``channel_axis`` was added in 0.19.

    Returns
    -------
    out : (..., 3, ...) ndarray
        The image in RGB format. Same dimensions as input.

    Raises
    ------
    ValueError
        If `ydbdr` is not at least 2-D with shape (..., 3, ...).

    Notes
    -----
    This is the color space commonly used by video codecs, also called the
    reversible color transform in JPEG2000.

    References
    ----------
    .. [1] https://en.wikipedia.org/wiki/YDbDr
    )r   rgb_from_ydbdr)r   r   r0   r0   r1   r   (  r  r   )F)rE   )N)r   r   )T)h__doc__warningsr   numpyr6   scipyr   _shared.utilsr   r   r   r   r	   utilr
   r   r2   r>   rD   rX   r   r   r   cie_primariessb_primariesr   invr   xyz_from_rgbciergbcie_from_xyzr   r   gray_from_rgbr  r  r  r  r  r  r  r  r  r  lab_ref_whiter   r   r   r   r   rgb_from_hdxcrosshdx_from_rgbrgb_from_fgxfgx_from_rgb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_rgbr   r   r!   r    r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r"   r#   r$   r%   r&   r   r   r   r   r   r0   r0   r0   r1   <module>   s   3DGYA















,

0

0

0



0

0



0

0

0
41'(-+JF0+\J&*+KG/

,% )& )