squidpy icon indicating copy to clipboard operation
squidpy copied to clipboard

Plotting errors when cropping in `spatial_segment`

Open aandytu opened this issue 1 year ago • 2 comments

I have several images that I have successfully imported into image containers, along with their respective whole cell segmentation masks that was generated elsewhere (mesmer). I have separately generated anndata objects using extracted data from these segmentation masks (quantification is done outside of squidpy).

I am able to add the images from the containers back into the anndata objects, but I have no idea how to add the segmentation mask back into same anndata objects, and do plotting as shown in the tutorial.

I looked through all the examples, and couldn't find any info. all the example data already have segmentation masks built into the data object. Some direction and documentation would be much appreciated.

aandytu avatar Mar 15 '23 20:03 aandytu

I was able to get the segmentation mask to load into anndata and plot somewhat successfully, after looking at data types and structure of the provided data.

However, I am getting some very strange behavior with sq.pl.spatial_segment. Firstly, the crop_coord documentation I believe is wrong. Instead of [left, right, top, bottom], it seems to be [x1, y1, x2, y2] where (x,y) 1 and 2 are top left and bottom right corner of the crop. I deduced this by looking at the tutorial usages.

When I plot the entire image, the segmentation masks and the image seem to align reasonable okay. however, when I use crop_coord, the background image becomes misalign with the segmentation mask. I set scaling factor to 1 when I imported the image.

Not only that, when I tried to plot values of the cells associated with the mask, they seem to change, depending on how I crop the image! I haven't tried categorical values yet, but this is odd, to say the least.

Edit: In fact, you can see the effect of this in one of the tutorial, where the "Max.PanCK" value of some cells are clearly plotted as different before and after crop_coord is supplied. (comparing the color of the top left corner portion of the plot).

aandytu avatar Mar 15 '23 21:03 aandytu

Hi @aandytu ,

apologies for late reply. for understanding how to import image and segemntation into anndata, this tutorial might be helpful https://squidpy.readthedocs.io/en/latest/tutorials.html#advanced-tutorials

for the plotting, I feel this is a but with the cropping function inside plotting. I am afraid I don't have time to fix it in the next weeks...

giovp avatar Mar 27 '23 07:03 giovp

Hi @aandytu

I don't think this method can be robustly used for all spatial omics technologies anymore and it will also be deprecated eventually because plotting and visualization of spatial omics data is now done with spatialdata-plot and napari-spatialdata. I would recommend using those tools for plotting the segmentation mask on top of spatial omics data.

LLehner avatar Jun 12 '24 08:06 LLehner