How to use the imageio.formats 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_lfr_format():
    """
    Test basic read/write properties of LytroLfrFormat
    """
    # 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 lfr format
    format = imageio.formats["lytro-lfr"]
    assert format.name == "LYTRO-LFR"
    assert format.__module__.endswith("lytro")

    # Test can read
    assert format.can_read(Request(lfr_file, "ri"))

    # Test cannot read, cannot write
    assert not format.can_read(Request(lfr_file, "rv"))
    assert not format.can_read(Request(lfr_file, "rI"))
    assert not format.can_read(Request(lfr_file, "rV"))
    assert not format.can_read(Request(lfp_file, "ri"))
    assert not format.can_read(Request(raw_illum_file, "ri"))
    assert not format.can_read(Request(raw_f01_file, "ri"))
    assert not format.can_read(Request(png_file, "ri"))

    assert not format.can_write(Request(lfr_file, "wi"))
github imageio / imageio / tests / test_pillow.py View on Github external
def setup_module():
    # Make sure format order is the default
    imageio.formats.sort()
github imageio / imageio / tests / test_dicom.py View on Github external
def test_selection():

    dname1, dname2, fname1, fname2 = _prepare()

    # Test that DICOM can examine file
    F = imageio.formats.search_read_format(core.Request(fname1, "ri"))
    assert F.name == "DICOM"
    assert F is imageio.formats["DICOM"]

    # Test that we cannot save
    request = core.Request(os.path.join(test_dir, "test.dcm"), "wi")
    assert not F.can_write(request)

    # Test fail on wrong file
    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"))
github imageio / imageio / tests / test_format.py View on Github external
def test_preferring_fi():

    # Prefer FI all the way
    imageio.formats.sort("-FI")

    assert imageio.formats[".tiff"].name == "TIFF-FI"
    assert imageio.formats[".png"].name == "PNG-FI"
    assert imageio.formats[".pfm"].name == "PFM-FI"

    # This would be better
    imageio.formats.sort("TIFF", "-FI")
    assert imageio.formats[".tiff"].name == "TIFF"
    assert imageio.formats[".png"].name == "PNG-FI"
    assert imageio.formats[".pfm"].name == "PFM-FI"
github imageio / imageio / docs / docsinserter.py View on Github external
from pyzolib import insertdocs
import subprocess
import sys

# Imports to fill the global namespace
import imageio

# Auto generate docs for each format
imageio._format_docs = imageio.formats.create_docs_for_all_formats()

# Insert docs
insertdocs.parse_rst_files(NS=globals())

# Set version
text = open('conf.py','rb').read().decode('utf-8')
lines = []
for line in text.splitlines():
    if line.startswith('version = '):
        line = "version  = '%s'" % '.'.join(imageio.__version__.split('.')[:2])
    elif line.startswith('release = '):
        line = "release = '%s'" % imageio.__version__
    lines.append(line)
text = '\n'.join(lines)
open('conf.py','wb').write(text.encode('utf-8'))
github imageio / imageio / imageio / plugins / freeimagemulti.py View on Github external
Y = np.argwhere(diff.sum(1))
            # Get rect coordinates
            if X.size and Y.size:
                x0, x1 = int(X[0]), int(X[-1]) + 1
                y0, y1 = int(Y[0]), int(Y[-1]) + 1
            else:  # No change ... make it minimal
                x0, x1 = 0, 2
                y0, y1 = 0, 2
            # Cut out and return
            return im[y0:y1, x0:x1], (x0, y0)


# formats.add_format(MngFormat('MNG', 'Multiple network graphics',
#                                    '.mng', 'iI'))
formats.add_format(IcoFormat("ICO-FI", "Windows icon", ".ico", "iI"))
formats.add_format(
    GifFormat("GIF-FI", "Static and animated gif (FreeImage)", ".gif", "iI")
)
github imageio / imageio / imageio / plugins / grab.py View on Github external
assert ImageGrab

        pil_im = ImageGrab.grabclipboard()
        if pil_im is None:
            raise RuntimeError(
                "There seems to be no image data on the " "clipboard now."
            )
        im = np.asarray(pil_im)
        return im, {}


# Register. You register an *instance* of a Format class.
format = ScreenGrabFormat(
    "screengrab", "Grab screenshots (Windows and OS X only)", [], "i"
)
formats.add_format(format)

format = ClipboardGrabFormat(
    "clipboardgrab", "Grab from clipboard (Windows only)", [], "i"
)
formats.add_format(format)
github imageio / imageio / imageio / plugins / freeimagemulti.py View on Github external
X = np.argwhere(diff.sum(0))
            Y = np.argwhere(diff.sum(1))
            # Get rect coordinates
            if X.size and Y.size:
                x0, x1 = int(X[0]), int(X[-1]) + 1
                y0, y1 = int(Y[0]), int(Y[-1]) + 1
            else:  # No change ... make it minimal
                x0, x1 = 0, 2
                y0, y1 = 0, 2
            # Cut out and return
            return im[y0:y1, x0:x1], (x0, y0)


# formats.add_format(MngFormat('MNG', 'Multiple network graphics',
#                                    '.mng', 'iI'))
formats.add_format(IcoFormat("ICO-FI", "Windows icon", ".ico", "iI"))
formats.add_format(
    GifFormat("GIF-FI", "Static and animated gif (FreeImage)", ".gif", "iI")
)