Skip to content

Commit

Permalink
support for multiscale images
Browse files Browse the repository at this point in the history
  • Loading branch information
LucaMarconato committed Mar 20, 2024
1 parent 5ac6650 commit 1641977
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/spatialdata/dataloader/datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ def __getitem__(self, idx: int) -> Any | SpatialData:
image = self.sdata[row["image"]]
tile = self._crop_image(
image,
axes=self.dims,
axes=tuple(self.dims),
min_coordinate=t_coords[[f"min{i}" for i in self.dims]].values,
max_coordinate=t_coords[[f"max{i}" for i in self.dims]].values,
target_coordinate_system=row["cs"],
Expand Down
26 changes: 26 additions & 0 deletions tests/dataloader/test_datasets.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,3 +116,29 @@ def test_return_annot(self, sdata_blobs, regions_element, return_annot):
if return_annot is not None:
return_annot = [return_annot] if isinstance(return_annot, str) else return_annot
assert annot.shape[1] == len(return_annot)

@pytest.mark.parametrize("rasterize", [True, False])
@pytest.mark.parametrize("return_annot", [None, "region"])
def test_multiscale_images(self, sdata_blobs, rasterize: bool, return_annot):
sdata = blobs_annotating_element("blobs_circles")
ds = ImageTilesDataset(
sdata=sdata,
regions_to_images={"blobs_circles": "blobs_multiscale_image"},
regions_to_coordinate_systems={"blobs_circles": "global"},
rasterize=rasterize,
return_annotations=return_annot,
table_name="table" if return_annot is not None else None,
rasterize_kwargs={"target_unit_to_pixels": 1} if rasterize else None,
)
if return_annot is None:
sdata_tile = ds[0]
if rasterize:
# rasterize transforms teh multiscale image into a single scale image
tile = sdata_tile["blobs_multiscale_image"]
else:
tile = next(iter(sdata_tile["blobs_multiscale_image"]["scale0"].ds.values()))
else:
tile, annot = ds[0]
if not rasterize:
tile = next(iter(tile["scale0"].ds.values()))
assert tile.shape == (3, 10, 10)

0 comments on commit 1641977

Please sign in to comment.