예제 #1
0
 def time_load(self, shape, mode):
     if mode == 'pillow':
         try:
             img = np.asarray(
                 Image.open(self.filename_pillow).convert('RGBA'))
         except Image.DecompressionBombError:
             pass
     elif mode == 'imageio':
         img = imread(self.filename)
     else:
         img = imread(self.filename)
     assert np.array_equal(img, self.img)
예제 #2
0
def test_uint8_rgb_image(tmpdir, shape, backend):
    tmpfile = os.path.join(str(tmpdir), 'test.bmp')

    img = np.random.randint(255, size=shape, dtype=np.uint8)
    imwrite(tmpfile, img)

    if backend == 'pillow':
        img_read = np.asarray(Image.open(tmpfile).convert('RGB'))
    else:
        img_read = imread(tmpfile)

    assert img.dtype == img_read.dtype
    assert_array_equal(img, img_read)
예제 #3
0
def test_bool_image(tmpdir, shape, backend):
    tmpfile = os.path.join(str(tmpdir), 'test.bmp')

    img = np.random.randint(2, size=shape, dtype=np.bool)
    img[0, 0] = False
    img[-1, -1] = True
    print(img)
    imwrite(tmpfile, img)

    if backend == 'pillow':
        img_read = np.asarray(Image.open(tmpfile).convert('L'))
    else:
        img_read = imread(tmpfile)
    print(img_read)
    assert img_read[0, 0] == 0
    assert img_read[-1, -1] == 255

    color_pallet = np.asarray([0, 255], dtype=np.uint8)
    assert_array_equal(color_pallet[img.astype(np.uint8)], img_read)