fish-quant / ComSeg

comseg
https://comseg.readthedocs.io/
MIT License
15 stars 3 forks source link

Invalid shape for Image Data Error #5

Open Tripfantasy opened 4 months ago

Tripfantasy commented 4 months ago

Hello, excited to try out this method. I'm currently adapting the 'minimal example' from the docs to 4 sections. My data consists of 4 tiffs with DAPI staining, and 4 csv files with x,y,z coords and gene names. I've manually added in the 'in_nucleus' column with all values set to 0 due to no prior, as per the documents instructions.

I'm having trouble visualizing the cells afterwords with the plot_result function:

from comseg.utils import plot

img_name = "32917-slide7_A1-1_DAPI"
G = Comsegdict[img_name].G
nuclei = tifffile.imread(
    path_to_mask_prior + f'/{img_name}.tiff')

plot.plot_result(G=G,
            nuclei = nuclei,
               key_node = 'cell_index_pred',
                title = None,
                dico_cell_color = None,
                figsize=(15, 15),
                spots_size = 10,
                plot_outlier = False)

This error occurs:

TypeError: Invalid shape (4288,) for image data

Traced specifically to:

ax.imshow(mip_nuclei > 0, cmap='gist_gray', alpha=0.8)
if data is None:
    return func(ax, *map(sanitize_sequence, args), **kwargs)
...
im.set_data(X)

And after doing some digging through the source code, I can't seem to figure out what the image data is, or why the error is occurring to begin with. I'm assuming it's the pixel length of the tiff image. Despite the error, it still overlays cell_index_pred over the tiff I feed it. Though, I can't make sense of it- and the cells seem more chaotic than the initial DAPI stain would imply.

Image for reference: slide7_A_try_1

Probably user error on my part, but I'd appreciate any help you guys can provide. Is it a soft-requirement to run cellpose as a prior? Thanks in advance!

tdefa commented 4 months ago

Hello, What is the shape of your tiff "nuclei" ? I noticed that the function assumes that the input is 3D. I quick fix could be just to reshape your nuclei to 3D shape (1, Y, X) ? Do not hesitate if you have other issues. I will adapt plot_result() to 2d in the future.

" Is it a soft-requirement to run cellpose as a prior?"

Tripfantasy commented 3 months ago

Hello, What is the shape of your tiff "nuclei" ?

Hi! Thanks for the reply. My tiff is 3D shape with x,y,z columns. The default format for my data is X,Y,Z,Gene. Before running ComSeg, I manually add in an 'in_nucleus' column and set all values equal to 0. Here's what it looks like after running.:

image

Note: Unnamed: 0 is just the index after adding the new column via pandas.

The configuration dictionary is mostly untouched aside form changing what the input data is, when compared to the 'minimal example' on the docs page.