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

Cannot aggregate Labels2DModel by ShapesModel #546

Open
GuoshengMa opened this issue Apr 17, 2024 · 1 comment
Open

Cannot aggregate Labels2DModel by ShapesModel #546

GuoshengMa opened this issue Apr 17, 2024 · 1 comment

Comments

@GuoshengMa
Copy link

Hi @LucaMarconato ! I got an error when I use aggregate() to aggregate a label layer by a shape layer.

Here is my code:

image

image

image

The label layer in codex_sdata was created by code below:

segmentation = iio.imread(data_dir / '3-D2_segmentation_borders.tiff')
labels = { 'labels': sd.models.Labels2DModel.parse(segmentation, dims=("y", "x")) }
sdata = sd.SpatialData(table=table, labels=labels, images=images)

In addition, following the conclusion of last Thursday's community meeting, I sent you an email with the subject 'Inquiry Regarding CODEX Data and High-Resolution Visium Image Alignment.' It contained attachments with the test data and scripts I provided. I wanted to confirm whether you received that email?

@LucaMarconato
Copy link
Member

Hi, answering the last question first thanks for your patience with the issue regarding the other issue. I just answered your email with the solution.

Regarding the current problem, currently we do not support aggregating vector data by raster data and vice versa. This could be done by either "vectorizing" the segmentation mask either by rasterizing the shapes. In your case, I would suggest doing the first.

A first approximation, if you do not need the precise shape of the cell, is to consider the cells as circles. In the notebook that I sent you by email I do so, so you can use that code already. (To be more precise, in the notebook I consider circles with arbitrary radii, but if you want to construct the circles from the labels you can follow the directions in my answer here #472).

Finally, if you want to be more precise and construct the exact polygons from the raster segmentation mask you can check out the approach used by SOPA https://gustaveroussy.github.io/sopa/ with the function sopa.segmentation.shapes.geometrize.

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

2 participants