Example #1
0
 def setup(self, shape, mode):
     self.img = np.random.randint(255, size=shape, dtype=np.uint8)
     self.tmpdir = Path(mkdtemp())
     self.filename = self.tmpdir / 'saved.bmp'
     imwrite(self.filename, self.img, write_order='RGBA')
     self.filename_pillow = self.tmpdir / 'saved_pillow.bmp'
     # Pillow needs BGRA
     imwrite(self.filename_pillow, self.img, write_order='BGRA')
Example #2
0
 def time_save(self, shape, mode):
     if mode == 'pillow':
         p = Image.fromarray(self.img)
         filename = self.tmpdir / 'pillow.bmp'
         p.save(filename)
     elif mode == 'imageio':
         filename = self.tmpdir / 'imageio.bmp'
         imageio.imwrite(filename, self.img)
     else:
         filename = self.tmpdir / 'redpil.bmp'
         imwrite(filename, self.img)
Example #3
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)
Example #4
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)
Example #5
0
 def setup(self, shape, mode):
     self.img = np.random.randint(255, size=shape, dtype=np.uint8)
     self.tmpdir = Path(mkdtemp())
     self.filename = self.tmpdir / 'saved.bmp'
     imwrite(self.filename, self.img)
Example #6
0
def test_failers(tmpdir):
    tmpfile = os.path.join(str(tmpdir), 'test.bmp')
    img = np.zeros((4, 4), dtype=np.float32)
    with pytest.raises(NotImplementedError):
        imwrite(tmpfile, img)