Skip to content

Commit 83e34c0

Browse files
Merge pull request #261 from quentinblampey/visium_hd_if
Handle IF images for Visium HD
2 parents b705526 + bc5352d commit 83e34c0

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

src/spatialdata_io/readers/visium_hd.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -407,14 +407,22 @@ def _load_image(
407407
data = imread(path, **imread_kwargs)
408408
if len(data.shape) == 4:
409409
# this happens for the cytassist, hires and lowres images; the umi image doesn't need processing
410-
data = data.squeeze().transpose(2, 0, 1)
410+
data = data.squeeze()
411411
else:
412412
if "MAX_IMAGE_PIXELS" in imread_kwargs:
413413
from PIL import Image as ImagePIL
414414

415415
ImagePIL.MAX_IMAGE_PIXELS = dict(imread_kwargs).pop("MAX_IMAGE_PIXELS")
416416
# dask_image doesn't recognize .btf automatically and imageio v3 throws error due to pixel limit -> use imageio v2
417-
data = imread2(path, **imread_kwargs).squeeze().transpose(2, 0, 1)
417+
data = imread2(path, **imread_kwargs).squeeze()
418+
419+
if data.shape[-1] == 3: # HE image in RGB format
420+
data = data.transpose(2, 0, 1)
421+
else:
422+
assert data.shape[0] == min(
423+
data.shape
424+
), "When the image is not in RGB, the first dimension should be the number of channels."
425+
418426
image = DataArray(data, dims=("c", "y", "x"))
419427
parsed = Image2DModel.parse(image, scale_factors=scale_factors, rgb=None, **image_models_kwargs)
420428
images[dataset_id + suffix] = parsed

0 commit comments

Comments
 (0)