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))
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)
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)
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)
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)
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)
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)
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)
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)
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)