How to use the imageio.core.get_remote_file function in imageio

To help you get started, we’ve selected a few imageio examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github imageio / imageio / tests / test_lytro.py View on Github external
def test_lytro_lfp_format():
    """
    Test basic read/write properties of LytroRawFormat
    """
    # Get test images
    need_internet()
    lfr_file = get_remote_file(LFR_FILENAME)
    raw_illum_file = get_remote_file(RAW_ILLUM_FILENAME)
    lfp_file = get_remote_file(LFP_FILENAME)
    raw_f01_file = get_remote_file(RAW_F0_FILENAME)
    png_file = get_remote_file(PNG_FILENAME)

    # Test lytro raw format
    format = imageio.formats["lytro-lfp"]
    assert format.name == "LYTRO-LFP"
    assert format.__module__.endswith("lytro")

    # Test can read, cannot write
    assert format.can_read(Request(lfp_file, "ri"))

    # Test cannot read, cannot write
    assert not format.can_read(Request(lfp_file, "rv"))
    assert not format.can_read(Request(lfp_file, "rI"))
github imageio / imageio / tests / test_lytro.py View on Github external
def test_lytro_illum_raw_format():
    """
    Test basic read/write properties of LytroRawFormat
    """
    # Get test images
    need_internet()
    lfr_file = get_remote_file(LFR_FILENAME)
    raw_illum_file = get_remote_file(RAW_ILLUM_FILENAME)
    lfp_file = get_remote_file(LFP_FILENAME)
    raw_f01_file = get_remote_file(RAW_F0_FILENAME)
    png_file = get_remote_file(PNG_FILENAME)

    # Test lytro raw format
    format = imageio.formats["lytro-illum-raw"]
    assert format.name == "LYTRO-ILLUM-RAW"
    assert format.__module__.endswith("lytro")

    # Test can read, cannot write
    assert format.can_read(Request(raw_illum_file, "ri"))

    # Test cannot read, cannot write
    assert not format.can_read(Request(raw_illum_file, "rv"))
    assert not format.can_read(Request(raw_illum_file, "rI"))
    assert not format.can_read(Request(raw_illum_file, "rV"))
    assert not format.can_read(Request(lfr_file, "ri"))
    assert not format.can_read(Request(lfp_file, "ri"))
github imageio / imageio / tests / test_avbin.py View on Github external
def test_read_format():
    need_internet()

    # Set videofomat
    # Also set skipempty, so we can test mean
    reader = imageio.read(
        get_remote_file("images/cockatoo.mp4"),
        "avbin",
        videoformat="mp4",
        skipempty=True,
    )
    for i in range(10):
        im = reader.get_next_data()
        assert im.shape == (720, 1280, 3)
        assert 100 < mean(im) < 115
github imageio / imageio / tests / test_pillow.py View on Github external
def test_inside_zipfile():
    need_internet()

    fname = os.path.join(test_dir, "pillowtest.zip")
    with ZipFile(fname, "w") as z:
        z.writestr("x.png", open(get_remote_file("images/chelsea.png"), "rb").read())
        z.writestr("x.jpg", open(get_remote_file("images/rommel.jpg"), "rb").read())

    for name in ("x.png", "x.jpg"):
        imageio.imread(fname + "/" + name)
github imageio / imageio / tests / test_fei_tiff.py View on Github external
def test_fei_file_reading():
    need_internet()  # We keep a test image in the imageio-binaries repo
    fei_filename = get_remote_file("images/fei-sem-rbc.tif")
    reader = imageio.get_reader(fei_filename, format="fei")
    image = reader.get_data(0)  # imageio.Image object
    assert image.shape == (1024, 1536)
    assert np.round(np.mean(image)) == 142
    assert len(image.meta) == 18
    assert image.meta["EScan"]["PixelHeight"] == 7.70833e-009
    assert isinstance(image.meta["Image"]["ResolutionX"], int)

    image_with_watermark = reader.get_data(0, discard_watermark=False)
    assert image_with_watermark.shape == (1094, 1536)
    assert np.round(np.mean(image_with_watermark)) == 137

    assert reader.get_data(0, discard_watermark=False).shape == (1094, 1536)
github imageio / imageio / tests / test_dicom.py View on Github external
fname2 = fname1 + ".fake"
    bb = open(fname1, "rb").read()
    bb = bb[:128] + b"XXXX" + bb[132:]
    open(fname2, "wb").write(bb)
    raises(Exception, F.get_reader, core.Request(fname2, "ri"))

    # Test special files with other formats
    im = imageio.imread(get_remote_file("images/dicom_file01.dcm"))
    assert im.shape == (512, 512)
    im = imageio.imread(get_remote_file("images/dicom_file03.dcm"))
    assert im.shape == (512, 512)
    im = imageio.imread(get_remote_file("images/dicom_file04.dcm"))
    assert im.shape == (512, 512)

    # Expected fails
    fname = get_remote_file("images/dicom_file90.dcm")
    raises(RuntimeError, imageio.imread, fname)  # 1.2.840.10008.1.2.4.91
    fname = get_remote_file("images/dicom_file91.dcm")
    raises(RuntimeError, imageio.imread, fname)  # not pixel data

    # This one *should* work, but does not, see issue #18
    try:
        imageio.imread(get_remote_file("images/dicom_file02.dcm"))
    except Exception:
        pass
github imageio / imageio / setup.py View on Github external
def _set_platform_resources(resource_dir, platform):
    import imageio

    # Create file to show platform
    assert platform
    open(op.join(resource_dir, "platform_%s" % platform), "wb")

    # Load freeimage
    fname = imageio.plugins.freeimage.FNAME_PER_PLATFORM[platform]
    imageio.core.get_remote_file(
        "freeimage/" + fname, resource_dir, force_download=True
    )
github mikkkee / gifer / gifer.py View on Github external
# Check if ffmpeg is in PATH
    try:
        with open( os.devnull, "w" ) as null:
            sp.check_call( [ "ffmpeg", "-version" ], stdout=null,
                           stderr=sp.STDOUT )
            return "ffmpeg"
    # ValueError is raised on failure on OS X through Python 2.7.11
    # https://bugs.python.org/issue26083
    except (OSError, ValueError, sp.CalledProcessError):
        pass

    plat = get_platform( )

    if plat and plat in FNAME_PER_PLATFORM:
        try:
            exe = get_remote_file( 'ffmpeg/' + FNAME_PER_PLATFORM[ plat ],
                                   auto=auto )
            os.chmod( exe, os.stat( exe ).st_mode | stat.S_IEXEC )  # executable
            return exe
        except NeedDownloadError:
            raise NeedDownloadError( 'Need ffmpeg exe. '
                                     'You can download it by calling:\n'
                                     '  imageio.plugins.ffmpeg.download()' )
        except InternetNotAllowedError:
            pass  # explicitly disallowed by user
        except OSError as err:  # pragma: no cover
            logging.warning( "Warning: could not find imageio's "
                             "ffmpeg executable:\n%s" %
                             str( err ) )

    # Fallback, let's hope the system has ffmpeg
    return 'ffmpeg'
github imageio / imageio / imageio / plugins / avbin.py View on Github external
""" Get avbin .dll/.dylib/.so
    """

    lib = os.getenv("IMAGEIO_AVBIN_LIB", None)
    if lib:  # pragma: no cover
        return lib

    platform = get_platform()

    try:
        lib = FNAME_PER_PLATFORM[platform]
    except KeyError:  # pragma: no cover
        raise RuntimeError("Avbin plugin is not supported on platform %s" % platform)

    try:
        return get_remote_file("avbin/" + lib, auto=False)
    except NeedDownloadError:
        raise NeedDownloadError(
            "Need avbin library. "
            "You can obtain it with either:\n"
            "  - download using the command: "
            "imageio_download_bin avbin\n"
            "  - download by calling (in Python): "
            "imageio.plugins.avbin.download()\n"
        )
    except InternetNotAllowedError as err:
        raise IOError("Could not download avbin lib:\n%s" % str(err))
        # in this case we raise. Can we try finding the system lib?