vanvalenlab / deepcell-tf

Deep Learning Library for Single Cell Analysis
https://deepcell.readthedocs.io
Other
427 stars 99 forks source link

Getting cell segmentation mask file from Mesmer standalone program #697

Closed ashishshel closed 1 year ago

ashishshel commented 1 year ago

Describe the bug I have currently set up the Mesmer standalone pipeline and I'm having issues with generating cell segmentation mask files (tiff format). I have separately run Mesmer using Steinbock (on a docker container )and I'm able to generate these mask files (attached - image with grey dots). I have written a few lines of code to generate a 16bit mask file in the Standalone Mesmer pipeline that I am pasting below. However, this gives me a blank file. Could you please suggest how I could generate the same mask file as is generated through Steinbock-Mesmer Mesmer_steinbock_mask Mesmer_standalone_mask

Code: 
  # create overlay of predictions
from deepcell.utils.plot_utils import make_outline_overlay
overlay_data = make_outline_overlay(rgb_data=rgb_images, predictions=segmentation_predictions)

overlay_data.shape 
Output: (3, 700, 1500, 3)

## Extracting 2 D segmentation mask from 4 D 
single_mask = overlay_data[0, :, :, 0]
single_mask.shape
Output: (0, 700, 1500 ,0)

## Scale the greyscale masks in the 0 - 255 range
single_mask = ((single_mask / np.max(single_mask)) * 255).astype('uint16')

tiff.imsave("Cell_seg_mask16bit.tiff", single_mask.astype(np.uint16))
rossbar commented 1 year ago

From the code snippet above, the immediate thing that jumps out is your single_mask.shape has 0's in the first and last dimension, implying the array is empty. That explains the blank images. Re: how you ended up with 0-D arrays - that is likely a result upstream in the processing pipeline - the indexing step (single_mask = overlay_data[0, :, :, 0]) should not result in a 0-D array, so there must be some other components to your pipeline that are modifying things unexepctedly. I'd suggest reviewing the pipeline carefully and consider raising an issue to whichever wrapper for the model you're using.

As it stands, this doesn't strike me as a mesmer bug so I will close this. Feel free to reopen if there is an un-wrapped (i.e. non-steinbock) minimal reproducing example.