Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
matt-sd-watson opened this issue Nov 18, 2024 · 0 comments

Comments

@matt-sd-watson
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant