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

File Format for Input Nuclear Segmentation in Lifted Multicut Algorithm #100

Closed michaelschwimmer closed 2 years ago

michaelschwimmer commented 3 years ago

Hi! Thank you for this amazing work.

I've segmented the nuclei for some images with another model that I've been training for a while, and wish to use these nuclear segmentations as seeds for membrane segmentation with PlantSeg. I've set it all up and have been trying with the label-map tiff file of labelled nuclei. It doesn't seem to work with this, does it only take another file format as input? I have a suspicion it's h5...

If it is do you know of a way I can convert, or ask the model to use my label-map image? Sorry if this is basic stuff, I'm a little new to this.

Thanks again and best wishes,

Michael

wolny commented 3 years ago

Hi @michaelschwimmer,

I'm happy to hear that plantseg has been useful in your research. Regarding your question: both tiff and hdf5 files are supported as input to plantseg LiftedMulticut segmentation. Regarding the nuclei images itself:

  1. If you have a nuclei segmented already, please use the is_segmentation: True flag in the segmentation part for the config, e.g.

    segmentation:
    # enable/disable segmentation
    state: True
    # path to the directory containing the nuclei predictions (either probability maps or segmentation)
    nuclei_predictions_path: PATH_TO_YOUR_NUCLEI_SEGMENTATION_FILE
    # whether the `nuclei_predictions_path` contains the probability maps (is_segmentation=False) or segmentation (is_segmentation=True)
    is_segmentation: True
    # Name of the algorithm to use for inferences
    name: "LiftedMulticut"
    # Segmentation specific parameters here
    # balance under-/over-segmentation; 0 - aim for undersegmentation, 1 - aim for oversegmentation
    beta: 0.65
    # directory where to save the results
    save_directory: OUTPUT_DIR
    # enable/disable watershed
    run_ws: True
    # use 2D instead of 3D watershed
    ws_2D: False
    # probability maps threshold
    ws_threshold: 0.5
    # set the minimum superpixels size
    ws_minsize: 50
    # sigma for the gaussian smoothing of the distance transform
    ws_sigma: 2.0
    # sigma for the gaussian smoothing of boundary
    ws_w_sigma: 0
    # set the minimum segment size in the final segmentation
    post_minsize: 100
  2. I your nuclei file contains the probability maps (foreground semantic class), you need to use `is_segmentation: False, e.g.:

    segmentation:
    # enable/disable segmentation
    state: True
    # path to the directory containing the nuclei predictions (either probability maps or segmentation)
    nuclei_predictions_path: PATH_TO_YOUR_NUCLEI_SEGMENTATION_FILE
    # whether the `nuclei_predictions_path` contains the probability maps (is_segmentation=False) or segmentation (is_segmentation=True)
    is_segmentation: False
    # Name of the algorithm to use for inferences
    name: "LiftedMulticut"
    # Segmentation specific parameters here
    # balance under-/over-segmentation; 0 - aim for undersegmentation, 1 - aim for oversegmentation
    beta: 0.65
    # directory where to save the results
    save_directory: OUTPUT_DIR
    # enable/disable watershed
    run_ws: True
    # use 2D instead of 3D watershed
    ws_2D: False
    # probability maps threshold
    ws_threshold: 0.5
    # set the minimum superpixels size
    ws_minsize: 50
    # sigma for the gaussian smoothing of the distance transform
    ws_sigma: 2.0
    # sigma for the gaussian smoothing of boundary
    ws_w_sigma: 0
    # set the minimum segment size in the final segmentation
    post_minsize: 100

I understand that your usecase is 1., so please make sure your config is correct. If it still doesn't work we would need your YAML config, your input membrane data and the nuclei segmentation file to investigate it further. One more tip: the shape of input membrane and the nuclei segmentation stacks has to be the same.

Best, Adrian

michaelschwimmer commented 3 years ago

Thank you for your quick reply! The config file is correct, and I think I fixed the problem by converting the tiff to an h5 file. However now that you have said that both tiff and h5 are valid inputs, I think the change which actually fixed this was renaming the nuclear segmentation file so that it matched the membrane image. I will try now with the original tiff, but in any case, thank you, this has been very helpful!

Best wishes,

Michael

wolny commented 3 years ago

Hi @michaelschwimmer,

happy to hear that your were able to execute the LiftedMulticut pipeline.

I think the change which actually fixed this was renaming the nuclear segmentation file so that it matched the membrane image

this is not the case: the naming of the files does not matter. What matters is the file extension however. Just for completeness here are the file extensions supported by plantseg: [".tiff", ".tif", ".hdf", ".hdf5", ".h5", ".hd5"]

Cheers, Adrian

michaelschwimmer commented 3 years ago

Hello,

I tried with my tiff file and it didn't seem to work...

Screenshot 2021-09-23 115357

michaelschwimmer commented 3 years ago

Sorry, that sent prematurely, I wanted to add:

Thank you again for your quick replies, and I'm sure I am missing something simple.

Best, Michael

memoryleine commented 3 years ago

Hi there,

I wanted to try the LiftedMulticut segmentation with the nuclei segmentations as tiff files and I ran into the same problem. Exporting the nuclei segmentations to HDF5 solved the problem. However, it wasn't necessary to convert the membrane boundary predictions to h5 - they worked fine as tiffs.

I tried to figure out what the issue was and it seems there is a difference in how the nuclei stacks are being loaded. In the file lmc.py, the method to load nuclei stacks only uses the h5py.File reader (link), while the load_stack method in steps.py (link) checks the file extension to see whether it should use tifffile or h5py.File to read the file. Maybe that's what's going on?

Once I got it to work, the results are quite good even before optimizing the parameters, so thank you all for that. :)

Best, Madeleine

lorenzocerrone commented 2 years ago

Dear all,

sorry for the long waiting; we were completely taken from another project.

@memoryleine is completely correct. The load_stack function used for nuclei is not correct.

I will fix it, thanks a lot!

Best,

Lorenzo