def load(filepath, rescale_image=True, dtype='float64'):
    """
    Load an image from a file.

    Parameters
    ----------
    filepath : str
        Path to the image file to load
    rescale_image : bool
        Default value: True
        If True, returned images have pixel values in [0, 1]. Otherwise,
        values are in [0, 255].
    dtype: str
        The dtype to use for the returned value

    Returns
    -------
    img : numpy ndarray
        An array containing the image that was in the file.
    """
    assert isinstance(filepath, string_types)

    if not rescale_image and dtype == 'uint8':
        ensure_Image()
        rval = np.asarray(Image.open(filepath))
        assert rval.dtype == 'uint8'
        return rval

    s = 1.0
    if rescale_image:
        s = 255.
    try:
        ensure_Image()
        rval = Image.open(filepath)
    except Exception:
        reraise_as(Exception("Could not open " + filepath))

    numpy_rval = np.array(rval)

    msg = ("Tried to load an image, got an array with %d"
           " dimensions. Expected 2 or 3."
           "This may indicate a mildly corrupted image file. Try "
           "converting it to a different image format with a different "
           "editor like gimp or imagemagic. Sometimes these programs are "
           "more robust to minor corruption than PIL and will emit a "
           "correctly formatted image in the new format.")
    if [2, 3] not in numpy_rval.ndim:
        logger.error(dir(rval))
        logger.error(rval)
        logger.error(rval.size)
        rval.show()
        raise AssertionError(msg % numpy_rval.ndim)
    rval = numpy_rval

    rval = np.cast[dtype](rval) / s

    if rval.ndim == 2:
        rval = rval.reshape(rval.shape[0], rval.shape[1], 1)

    if rval.ndim != 3:
        raise AssertionError("Something went wrong opening " +
                             filepath + '. Resulting shape is ' +
                             str(rval.shape) +
                             " (it's meant to have 3 dimensions by now)")

    return rval
dataset/ETHPy150Open lisa-lab/pylearn2/pylearn2/utils/image.py/load/swapped operands of `not in`