def show(image):
    """
    .. todo::

        WRITEME

    Parameters
    ----------
    image : PIL Image object or ndarray
        If ndarray, integer formats are assumed to use 0-255
        and float formats are assumed to use 0-1
    """
    viewer_command = string.preprocess('${PYLEARN2_VIEWER_COMMAND}')

    if viewer_command == 'inline':
        return imview(image)

    if hasattr(image, '__array__'):
        # do some shape checking because PIL just raises a tuple indexing error
        # that doesn't make it very clear what the problem is
        if len(image.shape) < 2 or len(image.shape) > 3:
            raise ValueError('image must have either 2 or 3 dimensions but its'
                             ' shape is ' + str(image.shape))

        # The below is a temporary workaround that prevents us from crashing
        # 3rd party image viewers such as eog by writing out overly large
        # images.
        # In the long run we should determine if this is a bug in PIL when
        # producing
        # such images or a bug in eog and determine a proper fix.
        # Since this is hopefully just a short term workaround the
        # constants below are not included in the interface to the
        # function, so that 3rd party code won't start passing them.
        max_height = 4096
        max_width = 4096

        # Display separate warnings for each direction, since it's
        # common to crop only one.
        if image.shape[0] > max_height:
            image = image[0:max_height, :, :]
            warnings.warn("Cropping image to smaller height to avoid crashing "
                          "the viewer program.")
        if image.shape[0] > max_width:
            image = image[:, 0:max_width, :]
            warnings.warn("Cropping the image to a smaller width to avoid "
                          "crashing the viewer program.")
        # This ends the workaround

        if image.dtype == 'int8':
            image = np.cast['uint8'](image)
        elif str(image.dtype).startswith('float'):
            # don't use *=, we don't want to modify the input array
            image = image * 255.
            image = np.cast['uint8'](image)

        # PIL is too stupid to handle single-channel arrays
        if len(image.shape) == 3 and image.shape[2] == 1:
            image = image[:, :, 0]

        try:
            ensure_Image()
            image = Image.fromarray(image)
        except TypeError:
            reraise_as(TypeError("PIL issued TypeError on ndarray of shape " +
                                 str(image.shape) + " and dtype " +
                                 str(image.dtype)))

    # Create a temporary file with the suffix '.png'.
    fd, name = mkstemp(suffix='.png')
    os.close(fd)

    # Note:
    #   Although we can use tempfile.NamedTemporaryFile() to create
    #   a temporary file, the function should be used with care.
    #
    #   In Python earlier than 2.7, a temporary file created by the
    #   function will be deleted just after the file is closed.
    #   We can re-use the name of the temporary file, but there is an
    #   instant where a file with the name does not exist in the file
    #   system before we re-use the name. This may cause a race
    #   condition.
    #
    #   In Python 2.7 or later, tempfile.NamedTemporaryFile() has
    #   the 'delete' argument which can control whether a temporary
    #   file will be automatically deleted or not. With the argument,
    #   the above race condition can be avoided.
    #

    image.save(name)
    if os.name == 'nt':
        subprocess.Popen(viewer_command + ' ' + name + ' && del ' + name,
                         shell=True)
    else:
        subprocess.Popen(viewer_command + ' ' + name + ' ; rm ' + name,
                         shell=True)
dataset/ETHPy150Open lisa-lab/pylearn2/pylearn2/utils/image.py/show/original