(file, dtype=np.float32, color=True, alpha=None)
Read an image from a file.

    This function reads an image from given file. The image is CHW format and
    the range of its value is :math:`[0, 255]`. If :obj:`color = True`, the
    order of the channels is RGB.

    The backend used by :func:`read_image` is configured by
    :obj:`chainer.global_config.cv_read_image_backend`.
    Two backends are supported: "cv2" and "PIL".
    If this is :obj:`None`, "cv2" is used whenever "cv2" is installed,
    and "PIL" is used when "cv2" is not installed.

    Args:
        file (string or file-like object): A path of image file or
            a file-like object of image.
        dtype: The type of array. The default value is :obj:`~numpy.float32`.
        color (bool): This option determines the number of channels.
            If :obj:`True`, the number of channels is three. In this case,
            the order of the channels is RGB. This is the default behaviour.
            If :obj:`False`, this function returns a grayscale image.
        alpha (None or {'ignore', 'blend_with_white', 'blend_with_black'}): \
            Choose how RGBA images are handled. By default, an error is raised.
            Here are the other possible behaviors:

            * `'ignore'`: Ignore alpha channel.
            * `'blend_with_white'`: Blend RGB image multiplied by alpha on \
                 a white image.
            * `'blend_with_black'`: Blend RGB image multiplied by alpha on \
                 a black image.

    Returns:
        ~numpy.ndarray: An image.
Read an image from a file.
Read an image from a file .
def read_image(file, dtype=np.float32, color=True, alpha=None):
    """Read an image from a file.

    This function reads an image from given file. The image is CHW format and
    the range of its value is :math:`[0, 255]`. If :obj:`color = True`, the
    order of the channels is RGB.

    The backend used by :func:`read_image` is configured by
    :obj:`chainer.global_config.cv_read_image_backend`.
    Two backends are supported: "cv2" and "PIL".
    If this is :obj:`None`, "cv2" is used whenever "cv2" is installed,
    and "PIL" is used when "cv2" is not installed.

    Args:
        file (string or file-like object): A path of image file or
            a file-like object of image.
        dtype: The type of array. The default value is :obj:`~numpy.float32`.
        color (bool): This option determines the number of channels.
            If :obj:`True`, the number of channels is three. In this case,
            the order of the channels is RGB. This is the default behaviour.
            If :obj:`False`, this function returns a grayscale image.
        alpha (None or {'ignore', 'blend_with_white', 'blend_with_black'}): \
            Choose how RGBA images are handled. By default, an error is raised.
            Here are the other possible behaviors:

            * `'ignore'`: Ignore alpha channel.
            * `'blend_with_white'`: Blend RGB image multiplied by alpha on \
                 a white image.
            * `'blend_with_black'`: Blend RGB image multiplied by alpha on \
                 a black image.

    Returns:
        ~numpy.ndarray: An image.
    """
    if chainer.config.cv_read_image_backend is None:
        if _cv2_available:
            return _read_image_cv2(file, dtype, color, alpha)
        else:
            return _read_image_pil(file, dtype, color, alpha)
    elif chainer.config.cv_read_image_backend == 'cv2':
        if not _cv2_available:
            raise ValueError('cv2 is not installed even though '
                             'chainer.config.cv_read_image_backend == \'cv2\'')
        return _read_image_cv2(file, dtype, color, alpha)
    elif chainer.config.cv_read_image_backend == 'PIL':
        return _read_image_pil(file, dtype, color, alpha)
    else:
        raise ValueError('chainer.config.cv_read_image_backend should be '
                         'either "cv2" or "PIL".')
def read_image ( file , dtype = np . float32 , color = True , alpha = None ) : if chainer . config . cv_read_image_backend is None : if _cv2_available : return _read_image_cv2 ( file , dtype , color , alpha ) else : return _read_image_pil ( file , dtype , color , alpha ) elif chainer . config . cv_read_image_backend == 'cv2' : if not _cv2_available : raise ValueError ( 'cv2 is not installed even though ' 'chainer.config.cv_read_image_backend == \'cv2\'' ) return _read_image_cv2 ( file , dtype , color , alpha ) elif chainer . config . cv_read_image_backend == 'PIL' : return _read_image_pil ( file , dtype , color , alpha ) else : raise ValueError ( 'chainer.config.cv_read_image_backend should be ' 'either "cv2" or "PIL".' )