Skip to content

Commit

Permalink
Set rgb argument to auto-detect whether image channels are RGB
Browse files Browse the repository at this point in the history
  • Loading branch information
aeisenbarth committed Aug 25, 2023
1 parent 03102c6 commit 4df62fc
Show file tree
Hide file tree
Showing 7 changed files with 11 additions and 5 deletions.
1 change: 1 addition & 0 deletions src/spatialdata_io/readers/codex.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ def codex(
"images": Image2DModel.parse(
image,
scale_factors=[2, 2],
rgb=None,
)
}
sdata = SpatialData(images=images, shapes={str(region): shapes}, table=table)
Expand Down
1 change: 1 addition & 0 deletions src/spatialdata_io/readers/cosmx.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ def cosmx(
"global_only_image": aff,
},
dims=("y", "x", "c"),
rgb=None,
**image_models_kwargs,
)
images[f"{fov}_image"] = parsed_im
Expand Down
2 changes: 1 addition & 1 deletion src/spatialdata_io/readers/mcmicro.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ def _get_images(
image_models_kwargs: Mapping[str, Any] = MappingProxyType({}),
) -> Union[SpatialImage, MultiscaleSpatialImage]:
image = imread(path / McmicroKeys.IMAGES_DIR / f"{sample}{McmicroKeys.IMAGE_SUFFIX}", **imread_kwargs)
return Image2DModel.parse(image, **image_models_kwargs)
return Image2DModel.parse(image, rgb=None, **image_models_kwargs)


def _get_labels(
Expand Down
1 change: 1 addition & 0 deletions src/spatialdata_io/readers/merscope.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ def merscope(
dims=("c", "y", "x"),
transformations={"microns": microns_to_pixels.inverse()},
c_coords=stainings,
rgb=True,
**image_models_kwargs,
)
images[f"{dataset_id}_z{z_layer}"] = parsed_im
Expand Down
2 changes: 1 addition & 1 deletion src/spatialdata_io/readers/steinbock.py
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ def _get_images(
image_models_kwargs: Mapping[str, Any] = MappingProxyType({}),
) -> Union[SpatialImage, MultiscaleSpatialImage]:
image = imread(path / SteinbockKeys.IMAGES_DIR / f"{sample}{SteinbockKeys.IMAGE_SUFFIX}", **imread_kwargs)
return Image2DModel.parse(data=image, transformations={sample: Identity()}, **image_models_kwargs)
return Image2DModel.parse(data=image, transformations={sample: Identity()}, rgb=None, **image_models_kwargs)


def _get_labels(
Expand Down
7 changes: 5 additions & 2 deletions src/spatialdata_io/readers/visium.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ def visium(
full_image,
scale_factors=[2, 2, 2, 2],
transformations={"global": transform_original},
rgb=None,
**image_models_kwargs,
)
else:
Expand All @@ -201,13 +202,15 @@ def visium(
image_hires = imread(path / VisiumKeys.IMAGE_HIRES_FILE, **imread_kwargs).squeeze().transpose(2, 0, 1)
image_hires = DataArray(image_hires, dims=("c", "y", "x"), name=dataset_id)
images[dataset_id + "_hires_image"] = Image2DModel.parse(
image_hires, transformations={"downscaled_hires": Identity()}
image_hires, transformations={"downscaled_hires": Identity()}, rgb=None
)
if (path / VisiumKeys.IMAGE_LOWRES_FILE).exists():
image_lowres = imread(path / VisiumKeys.IMAGE_LOWRES_FILE, **imread_kwargs).squeeze().transpose(2, 0, 1)
image_lowres = DataArray(image_lowres, dims=("c", "y", "x"), name=dataset_id)
images[dataset_id + "_lowres_image"] = Image2DModel.parse(
image_lowres, transformations={"downscaled_lowres": Identity()}
image_lowres,
transformations={"downscaled_lowres": Identity()},
rgb=None,
)

return SpatialData(images=images, shapes=shapes, table=table)
2 changes: 1 addition & 1 deletion src/spatialdata_io/readers/xenium.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,5 +216,5 @@ def _get_images(
) -> SpatialImage | MultiscaleSpatialImage:
image = imread(path / file, **imread_kwargs)
return Image2DModel.parse(
image, transformations={"global": Identity()}, dims=("c", "y", "x"), **image_models_kwargs
image, transformations={"global": Identity()}, dims=("c", "y", "x"), rgb=None, **image_models_kwargs
)

0 comments on commit 4df62fc

Please sign in to comment.