Skip to content

Commit

Permalink
Prevent image rotation during OME tiff conversion (#36)
Browse files Browse the repository at this point in the history
* swap axes instead of transposing

* to_numpy

* transpose switch rows and cols
  • Loading branch information
camisowers authored Sep 5, 2023
1 parent 03e595e commit 8c796d9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/alpineer/load_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -532,7 +532,7 @@ def fov_to_ome(
# Reorder the DataArray as OME-TIFFs require [Channel, Y, X]
fov_xr: xr.DataArray = load_imgs_from_tree(
data_dir=data_dir, img_sub_folder=img_sub_folder, fovs=fovs, channels=channels
).transpose("fovs", "channels", "cols", "rows")
).transpose("fovs", "channels", "rows", "cols")

_compression: dict = {"algorithm": "zlib", "args": {"level": 6}}

Expand Down Expand Up @@ -613,6 +613,6 @@ def ome_to_fov(ome: Union[str, pathlib.Path], data_dir: Union[str, pathlib.Path]

image_utils.save_image(
fname=save_dir / f"{channel}.tiff",
data=ome_tiff_page.asarray().transpose(),
data=ome_tiff_page.asarray(),
compression_level=6,
)
5 changes: 3 additions & 2 deletions tests/load_utils_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,8 @@ def create_img_data(tmp_path_factory) -> Iterator[Tuple[pathlib.Path, xr.DataArr

# Create OME-TIFFs
_compression: dict = {"algorithm": "zlib", "args": {"level": 6}}
data_xr_transposed = data_xr.transpose("fovs", "channels", "cols", "rows")
data_xr_transposed = data_xr.transpose("fovs", "channels", "rows", "cols")

for fov in data_xr_transposed:
fov_name: str = fov.fovs.values
ome_file_path: pathlib.Path = pathlib.Path(test_dir) / f"{fov_name}.ome.tiff"
Expand Down Expand Up @@ -726,7 +727,7 @@ def test_fov_to_ome(self, fovs, channels) -> None:

# Assert that the channel values in the OME-TIFF are correct.
for page, chan in zip(ome_tiff.pages, channels):
actual_data = page.asarray().transpose()
actual_data = page.asarray()
desired_data = self.data_xr.sel(fovs=fov_name, channels=chan).values
np.testing.assert_equal(actual_data, desired_data)

Expand Down

0 comments on commit 8c796d9

Please sign in to comment.