squidpy icon indicating copy to clipboard operation
squidpy copied to clipboard

CODEX

Open matthew-lee1 opened this issue 2 years ago • 1 comments

Hello, thanks for an awesome package! I am currently trying to extract image features within a segmentation mask and here is my set up so far:

mpif = tiff.imread('mpif_cropped.ome.tiff') mask = tiff.imread('cellpose_mask_cropVFS-25489.ome.tif') hae = tiff.imread('hae_cropped.ome.tiff')

image = sq.im.ImageContainer(mpif, layer='mpif') image.add_img(mask, layer='mask') image.add_img(hae, layer='hae')

adata = ad.AnnData(obs=pd.DataFrame(index=range(len(centroids))), obsm={"spatial": centroids}) adata.uns['spatial'] = {'images' : image}

sq.im.calculate_image_features( adata, img=image, layer='mpif', features='segmentation', n_jobs=16, features_kwargs={ 'segmentation': { 'props': ['area', 'centroid'], 'label_layer': 'mask' } } )

I'm thinking there's a problem with the way I'm registering adata.uns['spatial'], another option I've tried is: spatial_key = "spatial" library_id = "CHANGE" adata.uns[spatial_key] = {library_id: {}} adata.uns[spatial_key][library_id]["images"] = {} adata.uns[spatial_key][library_id]["images"] = {"hires": np.transpose(mpif, (1,2,0))} adata.uns[spatial_key][library_id]["scalefactors"] = { "tissue_hires_scalef": 1, "spot_diameter_fullres": 0.5, }

Which is closer to the documentation but still I am unable to get the feature extraction to work. It seems that it cannot find the segmentation mask. Is there a way around this? Thanks!

matthew-lee1 avatar Oct 26 '23 21:10 matthew-lee1

I think part of the problem is that when you run calculate_image_features() it attempts to first do spot cropping. any way around that?

matthew-lee1 avatar Oct 26 '23 23:10 matthew-lee1

Hi @matthew-lee1, thank you for using squidpy.

For loading CODEX data i would highly recommend to use the specified reader codex() from spatialdata-io. This package makes reading spatial omics data very easy and efficient.

LLehner avatar Jun 12 '24 08:06 LLehner