scverse / scverse/spatialdata-io

Xenium cell segmentation mask export requires coordinate flipping among y-axis

Open
#240 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
103
Forks
65
Avg merge
1h 8m
Merged PRs (30d)
3

Description

I have a script that pulls the cell segmentation mask from a spatialdata io object from Xenium and exports it as a tiff for our visualization software. The data are taken from this publicly available breast dataset:

sdata = sd.read_zarr(zarr_path)

cells = sdata.shapes['cell_boundaries']

x_min, y_min = np.min((adata.obsm['spatial']), axis=0)
x_max, y_max = np.max((adata.obsm['spatial']), axis=0)


transform = rasterio.transform.from_bounds(x_min, y_min, x_max,
                                           y_max, int(x_max - x_min), int(y_max - y_min))

shapes = [(geom, idx) for idx, geom in enumerate(cells.geometry)]

mask = rasterize(shapes=shapes, out_shape=(int(y_max - y_min), int(x_max - x_min)),
                 transform=transform, dtype='int32')

tiff.imwrite(f"mask.tiff", mask)

However, upon exporting the mask to tiff format, the coordinates in the y-axis are flipped:

Image

If I flip the mask array among the y-axis prior to export, the mask now aligns with the expression results:

tiff.imwrite(f"mask.tiff", np.flip(mask, axis=0))

Image

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the reported export using the Xenium breast dataset, the spatialdata object from sd.read_zarr, rasterio.transform.from_bounds, rasterize, and tiff.imwrite. Compare the coordinate conventions and determine where the y-axis inversion occurs; done means exported masks align with the expression results without an unexplained manual flip.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
data-visualization
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
28/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.