Teichlab / bin2cell

Join subcellular Visium HD bins into cells
MIT License
60 stars 2 forks source link

`b2c.scaled_he_image()` throws error #29

Closed Doreen181 closed 2 hours ago

Doreen181 commented 4 hours ago

Hi,

I am running into the following error for b2c.scaled_he_image(adata, mpp=0.2, save_path="he.tiff“):

ValueError: Morphology image dimension mismatch. Dimensions inferred from Spaceranger output: [195584.00013352 92152.66139624], actual image dimensions: [3685 1251]. Are you running with source_image_path set to the full resolution morphology image, as used for --image in Spaceranger?

I am using the full resolution image in .tif format as source_image_path, the same as used for --image in Spaceranger.

Some further diagnostics:

Dimensions of the hires image:

np.shape(adata.uns["spatial“][library]["images"]["hires“])
print(np.min(adata.obsm["spatial"],axis=0))
print(np.max(adata.obsm["spatial"],axis=0))

(6000, 2827, 3) [22101.75269837 75225.19198008] [ 49258.15645836 102374.77814838]

Dimensions of the full resolution HE input image:

img = b2c.load_image(source_image_path)
img.shape

(3685, 1251, 3)

Image metadata:

adata.uns["spatial“][library]["scalefactors“]

{'spot_diameter_fullres': 7.996766342229336, 'bin_size_um': 2.0, 'microns_per_pixel': 0.25010109266771957, 'tissue_lowres_scalef': 0.0030677356, 'fiducial_diameter_fullres': 1319.46644646784, 'tissue_hires_scalef': 0.030677356, 'regist_target_img_scalef': 0.030677356}

I would really appreciate any help. Thank you very much!

ktpolanski commented 4 hours ago

Thanks for all the diagnostics. As you can see, the image loaded by b2c.load_image() is already tiny, and matches the dimensions reported by the error message. You can try loading it into Python via alternate means, in case it's somehow cv2 that's screwing it up, but that seems unlikely to me. What's the size of the image on the drive?

Doreen181 commented 3 hours ago

Thanks for the quick response. The size is 4.08 GB.

ktpolanski commented 3 hours ago

That's a strange size - a lot smaller than I'd expect for something of the scale the spaceranger output is implying, but also a lot too big for ~3600x1200. Could you nab ImageMagick (e.g. from conda) and run identify on it?

Doreen181 commented 3 hours ago

Sure, this is the output I get:

image.tif[0] TIFF64 1251x3685 1251x3685+0+0 8-bit sRGB 3.80358GiB 0.010u 0:00.017 image.tif[1] TIFF64 1251x3685 1251x3685+0+0 8-bit Grayscale Gray 0.010u 0:00.016 image.tif[2] TIFF64 92160x195584 92160x195584+0+0 8-bit sRGB 0.010u 0:00.009 image.tif[3] TIFF64 46080x97792 46080x97792+0+0 8-bit sRGB 0.010u 0:00.007 image.tif[4] TIFF64 23040x48896 23040x48896+0+0 8-bit sRGB 0.010u 0:00.007 image.tif[5] TIFF64 11520x24448 11520x24448+0+0 8-bit sRGB 0.010u 0:00.007 image.tif[6] TIFF64 5760x12224 5760x12224+0+0 8-bit sRGB 0.010u 0:00.006 image.tif[7] TIFF64 2880x6112 2880x6112+0+0 8-bit sRGB 0.010u 0:00.006 image.tif[8] TIFF64 1440x3056 1440x3056+0+0 8-bit sRGB 0.010u 0:00.006 image.tif[9] TIFF64 720x1528 720x1528+0+0 8-bit sRGB 0.010u 0:00.006 image.tif[10] TIFF64 360x764 360x764+0+0 8-bit sRGB 0.010u 0:00.006 image.tif[11] TIFF64 180x382 180x382+0+0 8-bit sRGB 0.010u 0:00.005 image.tif[12] TIFF64 90x191 90x191+0+0 8-bit sRGB 0.010u 0:00.005

ktpolanski commented 2 hours ago

Alright, so this is structured more like how IF images are structured, with separate channels. Let's see if we can pull out the big one. Watch out as the RAM use will probably be crazy high.

import tifffile as tf

img = tf.imread(source_image_path, key=2)
img.shape
Doreen181 commented 2 hours ago

Thank you very much! Reading in the image with tf.imread(source_image_path, key=2)gives the right dimensions (195584, 92160) and b2c.scaled_he_image() works!

ktpolanski commented 1 hour ago

And just double-checking, this imported the colour space fine too?

Doreen181 commented 1 hour ago

Yes, everything's fine, the image now looks exactly like expected. Thank you!