Skip to content

Commit

Permalink
Add test and fix saving to set axes to zyx instead of default qyx.
Browse files Browse the repository at this point in the history
  • Loading branch information
matham committed Apr 22, 2024
1 parent 8578cc8 commit befb748
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
7 changes: 6 additions & 1 deletion brainglobe_utils/image_io/save.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,12 @@ def to_tiff(img_volume, dest_path, photometric="minisblack"):
Use 'minisblack' (default) for grayscale and 'rgb' for rgb
"""
dest_path = Path(dest_path)
tifffile.imwrite(dest_path, img_volume, photometric=photometric)
tifffile.imwrite(
dest_path,
img_volume,
photometric=photometric,
metadata={"axes": "ZYX"},
)


def to_tiffs(img_volume, path_prefix, path_suffix="", extension=".tif"):
Expand Down
13 changes: 13 additions & 0 deletions tests/tests/test_image_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,6 +350,19 @@ def test_image_size_dir(tmp_path, array_3d):
assert image_shape["z"] == array_3d.shape[0]


def test_image_size_tiff_stack(tmp_path, array_3d):
"""
Test that image size can be detected from a directory of 2D tiffs
"""
filename = tmp_path.joinpath("image_size_tiff_stack.tif")
save.save_any(array_3d, filename)

image_shape = load.get_size_image_from_file_paths(filename)
assert image_shape["x"] == array_3d.shape[2]
assert image_shape["y"] == array_3d.shape[1]
assert image_shape["z"] == array_3d.shape[0]


def test_image_size_txt(txt_path, array_3d):
"""
Test that image size can be detected from a text file containing the paths
Expand Down

0 comments on commit befb748

Please sign in to comment.