-
Notifications
You must be signed in to change notification settings - Fork 19
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
saving masks to png #112
Comments
Hi @sunshx-bioinfo, It's not straightforward, but it's possible to use spatialdata.rasterize to convert the geometries into labels (i.e., an image), and then save it to PNG using any python library such as May I ask why you need to use QuPath? In Sopa, the results are output in the Xenium Explorer, which is the "easy to use software". And since Sopa builds on top of |
Hi, sorry for late reply. I want to use I know you have made it possible that shows Sopa results in the Xenium Explorer, that's great! But i need a function to help me to automatically determine a threshold for idendifing positive protein staining in a cell. |
Alright, I understand, thanks for the extra details! Is it something you'd like to see inside Sopa, or will you always prefer the QuPath way to do it? |
It would be cool if you can build it into Sopa. We are using QuPath for legacy reasons. |
I will be very happy to see such function is avaiable in Sopa! Acturally, I plan to use Sopa as my first-choice software to analysis my spatial data and have suffered a lot from there images and data tranfromation. I have to turn to QuPath if there is no this automatelly-determine-threshold function for protein staining in Sopa. BTW, can we provide more properties of a cell, such as circularity, solidity and so on, besides area? Because we usually have less signatures(genes/proteins) in spatial data, adding extra cell properties can help to cluster cells and find more potential biological difference among real cell types. Another thing, by now, i'm not familiar with data structure inside spatialData image, can you give me a small example to save geometries to PNG file :)? |
Okay thanks, in that case could you please give me more details (or a link to a documentation/manual) that explains this feature? Regarding the cell properties, they are indeed not computed by default, but can be obtained via the shapes stored in your To create the image from the geometries, I have made this example below: import sopa.io
import spatialdata
from PIL import Image
# create a dummy SpatialData object
sdata = sopa.io.uniform()
# turn the geometries into labels (i.e., image with integers indicating the cell IDs)
labels = spatialdata.rasterize(
sdata["cells"],
axes=["y", "x"],
min_coordinate=[0, 0],
max_coordinate=[2048, 2048], # shape of the image (i.e., sdata["image"])
target_coordinate_system="global",
target_unit_to_pixels=1.0,
)
labels = labels.data.compute()[0] # shape: (2048, 2048)
# save the labels using PIL
pil_labels = Image.fromarray(labels.astype(np.uint8))
pil_labels.save("your_file.png", "PNG") |
Thanks! For cell properties, i want to know cell/nucleus's area, perimeter, circularity, solidity, min/max diameter and so on. For In QuPath,
I don't see detail method description about this function in QuPath, here is the document about cell classifier I mentioned above, but we use different parameters (below). Hoping this is helpful to you :). |
Thanks for the details, I'll keep that in mind and work on this when possible (probably not before late September or October). Regarding export to QuPath, @stergioc just told me it's possible to import a GeoJSON file into QuPath. This will be much more convenient and easy for you than re-creating a labels image. For that, you can use this function from GeoPandas, for instance: gdf = sdata["cellpose_boundaries"] # this is a GeoPandas Dataframe
gdf.to_file(path, driver="GeoJSON") Please let me know if it works 🙂 |
Hi, Both of two methods work! Thanks! |
Hi,
I want to use cellpose cell segmentation results in QuPath, I have found a script to transfer cell masks from one image to another in here. To run this script, a mask file with PNG format , which comes from
cellpose.io.save_masks
), is needed.So how do i get this mask figure with PNG format from Sopa output, or do you know any other method to simply transfer Sopa cell segmentation results into QuPath ?
The text was updated successfully, but these errors were encountered: