Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix label image dimension mis match #12

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ repos:
hooks:
- id: validate-cff
- repo: https://github.com/codespell-project/codespell
rev: v2.4.0
rev: v2.4.1
hooks:
- id: codespell
exclude: |
Expand Down
2 changes: 1 addition & 1 deletion docs/src/_static/coverage-badge.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
8 changes: 6 additions & 2 deletions src/nviz/image.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ def image_set_to_arrays(
label_dir: Optional[str],
channel_map: Dict[str, str],
ignore: Optional[List[str]] = ["Merge"],
expected_dim: int = 4,
) -> Dict[str, Dict[str, np.ndarray]]:
"""
Read a set of images as an array of images.
Expand Down Expand Up @@ -101,7 +102,6 @@ def image_set_to_arrays(
key=lambda x: x.name.split("_")[0],
)
}

return zstack_arrays


Expand Down Expand Up @@ -234,6 +234,7 @@ def tiff_to_ometiff( # noqa: PLR0913
channel_map: Dict[str, str],
scaling_values: Union[List[int], Tuple[int]],
ignore: Optional[List[str]],
expected_dim: int = 4,
) -> str:
"""
Convert TIFF files to OME-TIFF format.
Expand Down Expand Up @@ -286,7 +287,10 @@ def tiff_to_ometiff( # noqa: PLR0913
# Collect label data
if label_dir:
for compartment_name, stack in frame_zstacks["labels"].items():
labels_data.append(stack)
if stack.ndim != expected_dim and stack.ndim < expected_dim:
labels_data.append(np.expand_dims(stack, axis=0))
else:
labels_data.append(stack)
label_names.append(f"{compartment_name} (labels)")

# Stack the images and labels along a new axis for channels
Expand Down
10 changes: 8 additions & 2 deletions tests/test_image.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,14 @@
import tifffile as tiff
import zarr

from nviz.image import image_set_to_arrays, tiff_to_ometiff, tiff_to_zarr
from tests.utils import example_data_for_image_tests
from nviz.image import (
image_set_to_arrays,
tiff_to_ometiff,
tiff_to_zarr,
)
from tests.utils import (
example_data_for_image_tests,
)


@pytest.mark.parametrize(
Expand Down