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

Visium HD: handle IF images #261

Merged
merged 1 commit into from
Jan 14, 2025
Merged
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
12 changes: 10 additions & 2 deletions src/spatialdata_io/readers/visium_hd.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,14 +407,22 @@ def _load_image(
data = imread(path, **imread_kwargs)
if len(data.shape) == 4:
# this happens for the cytassist, hires and lowres images; the umi image doesn't need processing
data = data.squeeze().transpose(2, 0, 1)
data = data.squeeze()
else:
if "MAX_IMAGE_PIXELS" in imread_kwargs:
from PIL import Image as ImagePIL

ImagePIL.MAX_IMAGE_PIXELS = dict(imread_kwargs).pop("MAX_IMAGE_PIXELS")
# dask_image doesn't recognize .btf automatically and imageio v3 throws error due to pixel limit -> use imageio v2
data = imread2(path, **imread_kwargs).squeeze().transpose(2, 0, 1)
data = imread2(path, **imread_kwargs).squeeze()

if data.shape[-1] == 3: # HE image in RGB format
data = data.transpose(2, 0, 1)
else:
assert data.shape[0] == min(
data.shape
), "When the image is not in RGB, the first dimension should be the number of channels."

image = DataArray(data, dims=("c", "y", "x"))
parsed = Image2DModel.parse(image, scale_factors=scale_factors, rgb=None, **image_models_kwargs)
images[dataset_id + suffix] = parsed
Expand Down
Loading