Esempio n. 1
0
 def test_write_output_shape(self):
     with tempfile.TemporaryDirectory() as out_dir:
         image_name = os.path.join(out_dir, "test.png")
         img = np.random.rand(2, 2, 3)
         write_png(img, image_name, (4, 4), scale=255)
         out = np.asarray(Image.open(image_name))
         np.testing.assert_allclose(out.shape, (4, 4, 3))
Esempio n. 2
0
 def test_write_gray_1height(self):
     with tempfile.TemporaryDirectory() as out_dir:
         image_name = os.path.join(out_dir, "test.png")
         img = np.random.rand(1, 3)
         img_save_val = (65535 * img).astype(np.uint16)
         write_png(img, image_name, scale=65535)
         out = np.asarray(Image.open(image_name))
         np.testing.assert_allclose(out, img_save_val)
Esempio n. 3
0
 def test_write_2channels(self):
     with tempfile.TemporaryDirectory() as out_dir:
         image_name = os.path.join(out_dir, "test.png")
         img = np.random.rand(2, 3, 2)
         img_save_val = (255 * img).astype(np.uint8)
         write_png(img, image_name, scale=255)
         out = np.asarray(Image.open(image_name))
         np.testing.assert_allclose(out, img_save_val)
Esempio n. 4
0
 def test_write_rgb(self):
     with tempfile.TemporaryDirectory() as out_dir:
         image_name = os.path.join(out_dir, "test.png")
         img = np.random.rand(2, 3, 3)
         img_save_val = (255 * img).astype(np.uint8)
         write_png(img, image_name, scale=True)
         out = io.imread(image_name)
         np.testing.assert_allclose(out, img_save_val)
Esempio n. 5
0
 def test_write_output_shape(self):
     out_dir = tempfile.mkdtemp()
     image_name = os.path.join(out_dir, "test.png")
     img = np.random.rand(2, 2, 3)
     write_png(img, image_name, (4, 4), scale=True)
     out = io.imread(image_name)
     np.testing.assert_allclose(out.shape, (4, 4, 3))
     shutil.rmtree(out_dir)
Esempio n. 6
0
 def test_write_rgb(self):
     out_dir = tempfile.mkdtemp()
     image_name = os.path.join(out_dir, "test.png")
     img = np.random.rand(2, 3, 3)
     img_save_val = (255 * img).astype(np.uint8)
     write_png(img, image_name, scale=True)
     out = io.imread(image_name)
     np.testing.assert_allclose(out, img_save_val)
     shutil.rmtree(out_dir)
Esempio n. 7
0
 def test_write_2channels(self):
     out_dir = tempfile.mkdtemp()
     image_name = os.path.join(out_dir, "test.png")
     img = np.random.rand(2, 3, 2)
     img_save_val = (255 * img).astype(np.uint8)
     write_png(img, image_name, scale=255)
     out = np.asarray(Image.open(image_name))
     np.testing.assert_allclose(out, img_save_val)
     shutil.rmtree(out_dir)
Esempio n. 8
0
 def test_write_gray_1height(self):
     out_dir = tempfile.mkdtemp()
     image_name = os.path.join(out_dir, "test.png")
     img = np.random.rand(1, 3)
     img_save_val = (65535 * img).astype(np.uint16)
     write_png(img, image_name, scale=65535)
     out = np.asarray(Image.open(image_name))
     np.testing.assert_allclose(out, img_save_val)
     shutil.rmtree(out_dir)
Esempio n. 9
0
 def test_write_gray(self):
     with tempfile.TemporaryDirectory() as out_dir:
         image_name = os.path.join(out_dir, "test.png")
         img = np.random.rand(2, 3, 1)
         img_save_val = 255 * img
         # saving with io.imsave (h, w, 1) will only give us (h,w) while reading it back.
         img_save_val = img_save_val[:, :, 0].astype(np.uint8)
         write_png(img, image_name, scale=True)
         out = io.imread(image_name)
         np.testing.assert_allclose(out, img_save_val)
Esempio n. 10
0
 def test_write_output_shape(self):
     with tempfile.TemporaryDirectory() as out_dir:
         image_name = os.path.join(out_dir, "test.png")
         img = np.random.rand(2, 2, 3)
         write_png(img, image_name, (4, 4), scale=True)
         img_save_val = transform.resize(img, (4, 4),
                                         order=3,
                                         mode="constant",
                                         cval=0,
                                         preserve_range=True)
         img_save_val = (255 * img_save_val).astype(np.uint8)
         out = io.imread(image_name)
         np.testing.assert_allclose(out, img_save_val)