You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Q: How to render xenium morphology image with original colors? #370
Thank you very much for this tool. I want to plot a part of morphology image acquired with xenium + multimodal segmentation kit. It is loaded into spatialdata and plotted without errors, but the colors are dim and they are different from what I'd expected (DAPI - #0F73E6, Boundary - #F300A5, Interior RNA - #A4A400, interior protein - #008A00, reference values from Xenium Explorer). I tried passing a list of colors like this:
The code does not produce an error, it works twice as long, and it results in the same image with colors unchanged.
The key question is how to adjust the colors and saturation of the plot, so that it looked closer to what I see in Xenium Explorer?
Secondary question is how to translate physical coordinates into spatialdata's global coordinate system? Am I supposed to get transformation and then apply transformation to a single or a couple points to get min and max for cropping above? I can make a separate issue with this question, if necessary.
Hi, for coloring the channels please use the palette argument.
Regarding coordinates yes, once you identify the transformation from the physical coordinate system to the global one, you would need to transform the coordinates and use these in the bounding box query.
I assume you have an image with 4 channels that you're trying to map the individual colors to, right? As Luca said, you can use the palette argument for this, see here:
Thank you for checkin in on the issue. I managed to produce an image, but not without issues.
First, the morphology_focus image after reading with spatiadata_io.xenium() has 5 channels for some reason, and I don't know what is the 5th channel. To my best knowledge there should be only 4 images.
Second, there is a small issue where providing only 4 colors causes an error, even if I select only 4 channels. So to produce the image I had to pass five colors like this:
At first I thought that the rendered image is too dim, but it appears that one of the layers is not rendered properly this way. Here is the image I get after executing the code above:
Here is the image of the same region from Xenium Explorer:
And here is the image of the same region from Xenium Explorer without Interior RNA:
So, I am still looking for the way to render the image the same way it is shown in Xenium Explorer.
The argument is actually called channel without the s, could you try that? It requires 5 colors since you're not limiting the channels and therefore it uses all 5 you have in the image.
Hm, I think the true underlying issue here is that the image is stored as a datatree (multi-scale image) and we're not respecting that when sub-selecting for channels. Will check your MRE later, thank you!
If you want, you could try to overwrite the multi-scale image with one of the scales of the datatree. It probably looks like the second one here, right?
I'll probably create a new issue for the issue you probably identified, that we cannot pick channels out of datatrees robustly. So we might close this afterwards.
Could you plot the individual channels of your image separately before opening an issue in spatialdata-io? I'd be surprised if we create a non-sense channel during reading. The separate plot of the 5 channels might help troubleshoot here
@LucaMarconato have we seen a 5th channel popping up before?
Yes, adding a dummy fifth channel was a workaround when the support for the rgb parameter in spatial-image (and napari-spatialdata) was not available. We can remove that from the xenium() reader now, I'll track this in a separate issue.
Activity
LucaMarconato commentedon Oct 10, 2024
Hi, for coloring the channels please use the
paletteargument.Regarding coordinates yes, once you identify the transformation from the physical coordinate system to the global one, you would need to transform the coordinates and use these in the bounding box query.
We are going to improve the ergonomics of this as described in these issues (except for 338, which is unrelated): https://github.com/scverse/spatialdata/issues?q=sort%3Aupdated-desc%20is%3Aissue%20is%3Aopen%20physical
LucaMarconato commentedon Oct 10, 2024
Also please check my comment here (which answers almost a duplicate of question 2): scverse/spatialdata-io#205
timtreis commentedon Oct 15, 2024
Hey @tsvvas,
I assume you have an image with 4 channels that you're trying to map the individual colors to, right? As Luca said, you can use the palette argument for this, see here:
Please let us know if that solves your issue :)
tsvvas commentedon Oct 15, 2024
Hi @timtreis,
Thank you for checkin in on the issue. I managed to produce an image, but not without issues.
First, the morphology_focus image after reading with
spatiadata_io.xenium()has 5 channels for some reason, and I don't know what is the 5th channel. To my best knowledge there should be only 4 images.Second, there is a small issue where providing only 4 colors causes an error, even if I select only 4 channels. So to produce the image I had to pass five colors like this:
At first I thought that the rendered image is too dim, but it appears that one of the layers is not rendered properly this way. Here is the image I get after executing the code above:
Here is the image of the same region from Xenium Explorer:
And here is the image of the same region from Xenium Explorer without Interior RNA:
So, I am still looking for the way to render the image the same way it is shown in Xenium Explorer.
Best,
Vasily
timtreis commentedon Oct 15, 2024
The argument is actually called
channelwithout the s, could you try that? It requires 5 colors since you're not limiting the channels and therefore it uses all 5 you have in the image.tsvvas commentedon Oct 15, 2024
With
channelI get the following error:Error:
tsvvas commentedon Oct 15, 2024
A fully reproducible example:
Interestingly, if I provide five colors, the error becomes:
AttributeError: 'DataTree' object has no attribute 'c'timtreis commentedon Oct 15, 2024
Hm, I think the true underlying issue here is that the image is stored as a datatree (multi-scale image) and we're not respecting that when sub-selecting for channels. Will check your MRE later, thank you!
If you want, you could try to overwrite the multi-scale image with one of the scales of the datatree. It probably looks like the second one here, right?
tsvvas commentedon Oct 15, 2024
Yes, this is how it looks like in the example above
What is the 5th channel here? Or should I ask this in the spatialdata_io issues?
timtreis commentedon Oct 16, 2024
I'll probably create a new issue for the issue you probably identified, that we cannot pick channels out of datatrees robustly. So we might close this afterwards.
Could you plot the individual channels of your image separately before opening an issue in spatialdata-io? I'd be surprised if we create a non-sense channel during reading. The separate plot of the 5 channels might help troubleshoot here
tsvvas commentedon Oct 18, 2024
Hi @timtreis,
Seems like the 5th channel is empty:
tsvvas commentedon Oct 18, 2024
I tried the overwriting with single-scale image approach and still got the same error (continuing the example with the data above):
The error is still
ValueError: If 'palette' is provided, its length must match the number of channels.Providing 5 colors in the palette still results in the absence of Interior RNA channel in the rendered image.
timtreis commentedon Oct 19, 2024
@LucaMarconato have we seen a 5th channel popping up before?
tsvvas commentedon Oct 22, 2024
@timtreis The data from spatialdata tutorial on xenium analysis has 5 channels in "morphology_focus" image. But for me the key problem now is that I cannot render properly the other 4 channels.
LucaMarconato commentedon Oct 23, 2024
Yes, adding a dummy fifth channel was a workaround when the support for the
rgbparameter inspatial-image(andnapari-spatialdata) was not available. We can remove that from thexenium()reader now, I'll track this in a separate issue.feat(color): PercentileNormalize for percentile-based contrast limits