MouseLand / cellpose

a generalist algorithm for cellular segmentation with human-in-the-loop capabilities
https://www.cellpose.org/
BSD 3-Clause "New" or "Revised" License
1.24k stars 359 forks source link

get mask from flow-maps #948

Open phisanti opened 1 month ago

phisanti commented 1 month ago

Hi, I like the approach of using flow masks for bacterial cell segmentation. It works really well in highly dense areas. However, I am not getting the expected output. When I pass a labelled image (0 for background and int-n for each cell), I get a 4 dimension image: source, pmap, flow1, flow2. If I understand your documentation, the flow map should encode background as -5, but in my case, it comes as 0. Also, I am not able to reconvert the flow maps into pmaps. Ideally, I would like to train my model to output two channels (pmaps) and then convert to pmap.

Please let me know if you can help; any advice will be highly appreciated.

This is how I get the flow maps:

test=labels_to_flows(batch_img_tensor, use_gpu=False, device=None, redo_flows=True)

And this is how I get the mask back from the flows (channels 2 and 3 from the previous image)

flows=test[2:]
z2=get_masks(flows)