scverse / scverse/spatialdata-io
Xenium cell segmentation mask export requires coordinate flipping among y-axis
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:
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))
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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