kreshuklab / plant-seg

A tool for cell instance aware segmentation in densely packed 3D volumetric images
https://kreshuklab.github.io/plant-seg/
MIT License
97 stars 31 forks source link

using nuclear probabilities or segmentations from StarDist #109

Closed pr4deepr closed 9 months ago

pr4deepr commented 2 years ago

Hi Thank you for making this software available. I would like to use nuclear prediction label map from StarDist for the Lifted MultiCut segmentation as part of the Plantseg workflow. I had a look at previous closed Issues and it looks like it is possible. and have use following in the yml file

is_segmentation: True

and entered a nuclei_predictions_path and

However, I keep getting this error

assert input_segmentation.shape == watershed.shape

Complete log trace:

2022-02-09 19:03:06,194 [MainThread] INFO PlantSeg - Found 'predictions' dataset inside /home/rajasekhar.p/Documents/bianca_data/dapi_prob_map/membrane/PreProcessing/generic_light_sheet_3d_unet/membrane_predictions.h5
2022-02-09 19:03:09,537 [MainThread] INFO PlantSeg - Computing segmentation with dtWS...
2022-02-09 19:04:53,710 [MainThread] INFO PlantSeg - Clustering with LiftedMulticut...
Traceback (most recent call last):
  File "/home/rajasekhar.p/.conda/envs/plant-seg/bin/plantseg", line 10, in <module>
    sys.exit(main())
  File "/home/rajasekhar.p/.conda/envs/plant-seg/lib/python3.8/site-packages/plantseg/run_plantseg.py", line 28, in main
    raw2seg(config)
  File "/home/rajasekhar.p/.conda/envs/plant-seg/lib/python3.8/site-packages/plantseg/pipeline/raw2seg.py", line 85, in raw2seg
    output_paths = pipeline_step()
  File "/home/rajasekhar.p/.conda/envs/plant-seg/lib/python3.8/site-packages/plantseg/pipeline/steps.py", line 55, in __call__
    return [self.read_process_write(input_path) for input_path in self.input_paths]
  File "/home/rajasekhar.p/.conda/envs/plant-seg/lib/python3.8/site-packages/plantseg/pipeline/steps.py", line 55, in <listcomp>
    return [self.read_process_write(input_path) for input_path in self.input_paths]
  File "/home/rajasekhar.p/.conda/envs/plant-seg/lib/python3.8/site-packages/plantseg/segmentation/lmc.py", line 105, in read_process_write
    output_data = self.process(pmaps)
  File "/home/rajasekhar.p/.conda/envs/plant-seg/lib/python3.8/site-packages/plantseg/segmentation/lmc.py", line 73, in process
    segmentation = segment_volume_lmc_from_seg(boundary_pmaps,
  File "/home/rajasekhar.p/.conda/envs/plant-seg/lib/python3.8/site-packages/plantseg/segmentation/lmc.py", line 174, in segment_volume_lmc_from_seg
    lifted_uvs, lifted_costs = lifted_problem_from_segmentation(rag, watershed_segmentation, nuclei_seg,
  File "/home/rajasekhar.p/.conda/envs/plant-seg/lib/python3.8/site-packages/elf/segmentation/features.py", line 529, in lifted_problem_from_segmentation
    assert input_segmentation.shape == watershed.shape

I am "Computing a rescaling factor" based on pixel size of the image and the membrane predictions generated during the liftedmulticut appear to be rescaled. I've attached the yml file as txt.

lifted_multicut.yml.txt

I'm assuming I need to rescale the images I use for nuclei prediction? Is there anything I should be aware of here?

Cheers Pradeep

pr4deepr commented 2 years ago

I checked the shapes of the arrays (xyz): input_segmentation.shapewas: 577 x 453 x 378 whereas the watershed.shapewas smaller: 284 x 223 x 79..

The larger shapes corresponds to the rescaled image. So, I rescaled the nuclei label image to match the shape of the rescaled membrane prediction. The shape mismatch error disappeared, but now I get another error:

Traceback (most recent call last):
  File "/home/rajasekhar.p/.conda/envs/plant-seg/bin/plantseg", line 10, in <module>
    sys.exit(main())
  File "/home/rajasekhar.p/.conda/envs/plant-seg/lib/python3.8/site-packages/plantseg/run_plantseg.py", line 28, in main
    raw2seg(config)
  File "/home/rajasekhar.p/.conda/envs/plant-seg/lib/python3.8/site-packages/plantseg/pipeline/raw2seg.py", line 85, in raw2seg
    output_paths = pipeline_step()
  File "/home/rajasekhar.p/.conda/envs/plant-seg/lib/python3.8/site-packages/plantseg/pipeline/steps.py", line 55, in __call__
    return [self.read_process_write(input_path) for input_path in self.input_paths]
  File "/home/rajasekhar.p/.conda/envs/plant-seg/lib/python3.8/site-packages/plantseg/pipeline/steps.py", line 55, in <listcomp>
    return [self.read_process_write(input_path) for input_path in self.input_paths]
  File "/home/rajasekhar.p/.conda/envs/plant-seg/lib/python3.8/site-packages/plantseg/segmentation/lmc.py", line 105, in read_process_write
    output_data = self.process(pmaps)
  File "/home/rajasekhar.p/.conda/envs/plant-seg/lib/python3.8/site-packages/plantseg/segmentation/lmc.py", line 73, in process
    segmentation = segment_volume_lmc_from_seg(boundary_pmaps,
  File "/home/rajasekhar.p/.conda/envs/plant-seg/lib/python3.8/site-packages/plantseg/segmentation/lmc.py", line 184, in segment_volume_lmc_from_seg
    lifted_costs = lifted_costs[:, 0]
IndexError: too many indices for array: array is 1-dimensional, but 2 were indexed

I checked the shape of lifted_costs and its (1070,), i.e., its a 1D array. So, I commented out this line lifted_costs = lifted_costs[:, 0] The segmentation now works without a problem.

Is there anything that I'm doing wrong or is it a bug with the program? Is it worth adding a check to see if its a 2D or 1D array?

Cheers Pradeep

lorenzocerrone commented 2 years ago

Hi Pradeep,

Thanks for using plantseg!

About the shape mismatch, that's plantseg fault, the nuclei image is never preprocessed internally (so the setup in the preprocessing config is ignored) and it needs to be 'rescaled' outside plantseg (like in fiji). We are working to change radically plantseg and make the lifted MC workflow better supported. At the moment is still a bit rough and buggy.

About the second error, I have already seen it and I thought it was solved, my guess is that something has changed upstream in elf. Could you please tell me what version of plantseg and what version of elf do you use? (you can get them from the terminal by using conda list | grep elf and conda list | grep plantseg)

I flag this a bug, and look into it.

Best, Lorenzo

pr4deepr commented 2 years ago

Hi @lorenzocerrone

Thanks for the reply.

For elf:

python-elf | 0.4.0 | pyhd8ed1ab_0 | conda-forge

For plantseg

plantseg | 1.4.2 | py_1 | lcerrone

Also, are there any plans to bring it to Windows in the near future, apart from using docker?

Cheers Pradeep

lorenzocerrone commented 2 years ago

We actually as of today have native support for windows. I am still testing it around, so I still expect bugs. In the readme you can find the installation instructions.

Best, Lorenzo

pr4deepr commented 2 years ago

Yes, please!! I'm happy to test and give feedback..

lorenzocerrone commented 2 years ago

Thanks! that would be awesome! :)

pr4deepr commented 2 years ago

It seems to be working fine on Windows. It was a breeze to install as everything is in one conda command. Will let you know if I run into any trouble..

lorenzocerrone commented 2 years ago

Perfect, thanks a lot for testing it.

In the next days (maybe a week) we will release stand alone binaries for Windows, and a new launcher to allow drag and drop of images and configs on Windows. If you are mostly on Windows those could be useful for you.

Cheers, Lorenzo

pr4deepr commented 2 years ago

Hi I'm having trouble with segmentations using the lifted multicut in PlantSeg. Due to data confidentiality, I'm not allowed to share the data publicly. Is it ok if I send the data link in an email?

Cheers Pradeep

qin-yu commented 9 months ago

Hey @pr4deepr, I think this problem was fixed in the Napar interface a long time ago (but after this issue ofc). Do you still experience any issue relating to Lifted MultiCut? If not I'll close the issue. Thanks for reporting!

pr4deepr commented 9 months ago

Hi I haven't used this in a while, but I remember it working for me. I'll close this and reopen if needed.

Cheers Pradeep