squidpy icon indicating copy to clipboard operation
squidpy copied to clipboard

sq.im.calculate_image_features() - scale factors for cropped image

Open elise-smith opened this issue 2 years ago • 1 comments

Description

Hi, Thank you for the great package. I am having an issue with sq.im.calculate_image_features(), as previously mentioned in #399. I provide the scale factor when initialising the ImageContainer, as mentioned in #399. When using an uncropped tif image, I can successfully use sq.im.calculate_image_features(). However, with a cropped image I get the same error as mentioned previously (below). I'd thought that I may need to re-provide scale factors for the cropped image. Do you have any suggestions about how I'd do this? Many thanks.

scale = adata.uns['spatial'][f'{SAMPLE_NAME}']['scalefactors']['tissue_hires_scalef']
img = sq.im.ImageContainer('/path_to_tif/img.tif', scale = scale)
crop = img.crop_corner(5000, 3000, size=500)
sq.im.segment(img=crop, 
              layer="image", 
              layer_added="segmented_watershed", 
              method="watershed", 
              channel=0,
              qeq=False)
sq.im.calculate_image_features(
    adata,
    crop,
    layer='image',
    features="segmentation",
    key_added="segmentation_features",
    mask_circle=True)

ValueError: Expected 'height' to be in interval '[0, 500]', found '-4390'.

Version

1.2.3

...

elise-smith avatar Apr 13 '23 09:04 elise-smith

Hi, I'm having a similar issue, except that the height of my crop is just barely outside the desired range, so not sure why that is...

Expected `height` to be in interval `[0, 6688]`, found `6702`

I'm following the tutorial here because I am trying to use a new spatial-omics technology (STARmap PLUS), and so I thought that the tissue_hires_scalef should just be set to 1. But that seems to be too large?

I found, however, that if I changed the scale factor to 0.99 instead of 1.0, then it works fine, i.e. the crops never go outside the image range, I guess. Is there a reason for this behavior?

alam-shahul avatar Jan 25 '24 22:01 alam-shahul