-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
100 additions
and
102 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,28 @@ | ||
import optimap as om | ||
import numpy as np | ||
from tempfile import TemporaryDirectory | ||
from pathlib import Path | ||
|
||
def test_image_export(): | ||
def test_image_export(tmpdir): | ||
img = np.random.rand(100, 100).astype(np.float32) | ||
with TemporaryDirectory() as tmpdir: | ||
fn = tmpdir + "/test.npy" | ||
om.image.save_image(img, fn) | ||
img2 = om.image.load_image(fn) | ||
assert np.allclose(img, img2) | ||
|
||
# Test if 16-bit PNG and TIFF export works | ||
with TemporaryDirectory() as tmpdir: | ||
img = (img * 65535).astype(np.uint16) | ||
fn = tmpdir + "/test.png" | ||
om.image.save_image(img, fn) | ||
img2 = om.image.load_image(fn) | ||
assert img.dtype == img2.dtype | ||
assert np.allclose(img, img2) | ||
fn = tmpdir / "test.npy" | ||
om.image.save_image(img, Path(fn)) | ||
img2 = om.image.load_image(Path(fn)) | ||
assert np.allclose(img, img2) | ||
|
||
with TemporaryDirectory() as tmpdir: | ||
img = (img * 65535).astype(np.uint16) | ||
fn = tmpdir + "/test.tiff" | ||
om.image.save_image(img, fn) | ||
img2 = om.image.load_image(fn) | ||
assert img.dtype == img2.dtype | ||
assert np.allclose(img, img2) | ||
def test_16bit_export(tmpdir): | ||
"""Test if 16-bit PNG and TIFF export works.""" | ||
img = np.random.rand(100, 100).astype(np.float32) | ||
img = (img * 65535).astype(np.uint16) | ||
|
||
fn = tmpdir / "test.png" | ||
om.image.save_image(img, fn) | ||
img2 = om.image.load_image(fn) | ||
assert img.dtype == img2.dtype | ||
assert np.allclose(img, img2) | ||
|
||
fn = tmpdir / "test.tiff" | ||
om.image.save_image(img, fn) | ||
img2 = om.image.load_image(fn) | ||
assert img.dtype == img2.dtype | ||
assert np.allclose(img, img2) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters