def load_image_imread(file, shape=None, max_range=1.0):
    '''
    Load image from file like object.

    :param file: Image contents
    :type file: file like object.
    :param shape: shape of output array
        e.g. (3, 128, 192) : n_color, height, width.
    :type shape: tuple of int
    :param float max_range: the value of return array ranges from 0 to `max_range`.

    :return: numpy array

    '''
    img255 = imread(
        file)  # return value is from zero to 255 (even if the image has 16-bitdepth.)

    if len(img255.shape) == 2:  # gray image
        height, width = img255.shape
        if shape is None:
            out_height, out_width, out_n_color = height, width, 1
        else:
            out_n_color, out_height, out_width = shape
        assert(out_n_color == 1)
        if out_height != height or out_width != width:
            # imresize returns 0 to 255 image.
            img255 = imresize(img255, (out_height, out_width))
        img255 = img255.reshape((out_n_color, out_height, out_width))
    elif len(img255.shape) == 3:  # RGB image
        height, width, n_color = img255.shape
        if shape is None:
            out_height, out_width, out_n_color = height, width, n_color
        else:
            out_n_color, out_height, out_width = shape
        assert(out_n_color == n_color)
        if out_height != height or out_width != width or out_n_color != n_color:
            # imresize returns 0 to 255 image.
            img255 = imresize(img255, (out_height, out_width, out_n_color))
        img255 = img255.transpose(2, 0, 1)

    if max_range < 0 or max_range == 255.0:
        return img255
    else:
        return img255 * (max_range / 255.0)
Load image from file like object.

    :param file: Image contents
    :type file: file like object.
    :param shape: shape of output array
        e.g. (3, 128, 192) : n_color, height, width.
    :type shape: tuple of int
    :param float max_range: the value of return array ranges from 0 to `max_range`.

    :return: numpy array