Example #1
0
def image_files_noise(request):
    """Three sham images; one has no signal, one has an intensity artifact."""
    # for clarity we define images as integer arrays in [0, 11) and
    # divide by 10 later
    r = np.random.RandomState(0)
    shape = (5, 5)
    # no signal
    i = conv(0.01 * np.ones(shape, dtype=float) + 0.005 * r.randn(*shape))
    # normal image
    j = conv(0.5 * r.rand(*shape))
    # blown-out corner
    k = 0.5 * r.rand(*shape)
    k[3:, 3:] = 1.0
    k = conv(k)
    files = []
    for im in [i, j, k]:
        f, fn = tempfile.mkstemp(suffix='.png')
        files.append(fn)
        mio.imsave(fn, im)

    def cleanup():
        for fn in files:
            os.remove(fn)
    request.addfinalizer(cleanup)

    illum = 0.01 * np.ones(shape, dtype=float)
    return files, illum
Example #2
0
    def make_test_montage_files(missing_fields):
        shape = (2, 2)

        fields = list(range(0, 25))
        for missing_field in missing_fields:
            fields.remove(missing_field)

        ims = [np.ones(shape, np.uint8) * i for i in fields]
        files = []

        for field, im in zip(fields, ims):
            prefix = "MFGTMP_140206180002_A01f{0:02d}d0".format(field)
            f, fn = tempfile.mkstemp(prefix=prefix, suffix=".tif")
            files.append(fn)

            with warnings.catch_warnings():
                warnings.simplefilter("ignore")
                mio.imsave(fn, im)

        def cleanup():
            for file in files:
                os.remove(file)
        request.addfinalizer(cleanup)

        return files
Example #3
0
def image_files(request):
    # for clarity we define images as integer arrays in [0, 11) and
    # divide by 10 later
    i = np.array([[ 7,  4,  1,  1,  0],
                  [ 2,  5,  9,  6,  7],
                  [ 2,  3,  3,  8,  5],
                  [ 3,  0,  1,  7,  5],
                  [ 6,  0, 10,  1,  6]], np.uint8)
    j = np.array([[ 1, 10,  0,  9,  0],
                  [ 3, 10,  4,  1,  1],
                  [ 4, 10,  0,  7,  4],
                  [ 9,  3,  2,  0,  7],
                  [ 1,  3,  3,  9,  3]], np.uint8)
    k = np.array([[ 9,  1,  7,  7,  3],
                  [ 9,  1,  6,  2,  2],
                  [ 2,  8,  2,  0,  3],
                  [ 4,  3,  8,  9, 10],
                  [ 6,  0,  2,  3, 10]], np.uint8)
    files = []
    for im in [i, j, k]:
        f, fn = tempfile.mkstemp(suffix='.png')
        files.append(fn)
        mio.imsave(fn, im)

    def cleanup():
        for fn in files:
            os.remove(fn)
    request.addfinalizer(cleanup)

    return files
Example #4
0
def image_files_noise(request):
    """Three sham images; one has no signal, one has an intensity artifact."""
    r = np.random.RandomState(0)
    shape = (5, 5)
    # no signal
    i = conv(0.01 * np.ones(shape, dtype=float) + 0.005 * r.randn(*shape))
    # normal image
    j = conv(0.5 * r.rand(*shape))
    # blown-out corner
    k = 0.5 * r.rand(*shape)
    k[3:, 3:] = 1.0
    k = conv(k)
    files = []
    for im in [i, j, k]:
        f, fn = tempfile.mkstemp(suffix='.png')
        files.append(fn)
        mio.imsave(fn, im)

    def cleanup():
        for fn in files:
            os.remove(fn)
    request.addfinalizer(cleanup)

    illum = 0.01 * np.ones(shape, dtype=float)
    return files, illum
Example #5
0
def image_files():
    # for clarity we define images as integer arrays in [0, 11) and
    # divide by 10 later
    i = np.array([[7, 4, 1, 1, 0],
                  [2, 5, 9, 6, 7],
                  [2, 3, 3, 8, 5],
                  [3, 0, 1, 7, 5],
                  [6, 0, 10, 1, 6]], np.uint8)
    j = np.array([[1, 10, 0, 9, 0],
                  [3, 10, 4, 1, 1],
                  [4, 10, 0, 7, 4],
                  [9, 3, 2, 0, 7],
                  [1, 3, 3, 9, 3]], np.uint8)
    k = np.array([[9, 1, 7, 7, 3],
                  [9, 1, 6, 2, 2],
                  [2, 8, 2, 0, 3],
                  [4, 3, 8, 9, 10],
                  [6, 0, 2, 3, 10]], np.uint8)
    files = []
    for im in [i, j, k]:
        f, fn = tempfile.mkstemp(suffix='.png')
        files.append(fn)
        mio.imsave(fn, im)

    yield files
    
    for fn in files:
        os.remove(fn)
Example #6
0
    def make_test_montage_files(missing_fields):
        shape = (2, 2)

        fields = list(range(0, 25))
        for missing_field in missing_fields:
            fields.remove(missing_field)

        ims = [np.ones(shape, np.uint8) * i for i in fields]
        files = []

        for field, im in zip(fields, ims):
            prefix = "MFGTMP_140206180002_A01f{0:02d}d0".format(field)
            f, fn = tempfile.mkstemp(prefix=prefix, suffix=".tif")
            files.append(fn)

            with warnings.catch_warnings():
                warnings.simplefilter("ignore")
                mio.imsave(fn, im)

        def cleanup():
            for file in files:
                os.remove(file)

        request.addfinalizer(cleanup)

        return files
Example #7
0
def test_imsave_tif_compress():
    im = np.random.randint(0, 256, size=(1024, 1024, 3)).astype(np.uint8)
    with NamedTemporaryFile(suffix='.tif') as fout:
        fname = fout.name
        fout.close()
        mio.imsave(im, fname, compress=2)
        imin = mio.imread(fname)
        np.testing.assert_array_equal(im, imin)
Example #8
0
def test_imsave_tif_compress():
    im = np.random.randint(0, 256, size=(1024, 1024, 3)).astype(np.uint8)
    with NamedTemporaryFile(suffix='.tif') as fout:
        fname = fout.name
        fout.close()
        mio.imsave(im, fname, compress=2)
        imin = mio.imread(fname)
        np.testing.assert_array_equal(im, imin)
Example #9
0
    def image_files_n(request):
        files = []
        for i in range(0, num_files):
            image = np.ones((2, 2), np.uint8) * i
            file_prefix = '%02d' % (i,) + '_'  # filenames must be sortable
            f, fn = tempfile.mkstemp(prefix=file_prefix, suffix='.png')
            files.append(fn)
            mio.imsave(fn, image)

        def cleanup():
            for fn in files:
                os.remove(fn)
        request.addfinalizer(cleanup)

        return files
Example #10
0
    def image_files_n(request):
        files = []
        for i in range(0, num_files):
            image = np.ones((2, 2), np.uint8) * i
            file_prefix = '%02d' % (i, ) + '_'  # filenames must be sortable
            f, fn = tempfile.mkstemp(prefix=file_prefix, suffix='.png')
            files.append(fn)
            mio.imsave(fn, image)

        def cleanup():
            for fn in files:
                os.remove(fn)

        request.addfinalizer(cleanup)

        return files