stardist / stardist-imagej

StarDist plugin for ImageJ
BSD 3-Clause "New" or "Revised" License
26 stars 14 forks source link

macro for slices #4

Open matfallet opened 4 years ago

matfallet commented 4 years ago

Hi, Is there a way to put stardist in a macro to apply the segmentation for each slice and recombine them to reconstruct 3D nuclei ? It would be great, I try but don't find the command to skip the interface :

getDimensions(width, height, channels, slices, frames);
for (i = 1; i < slices+1; i++) {
                setSlice(i);
                run("Make Substack...", "  slices="+i);
                run("StarDist 2D");
}
// Recombine the slices and make the Connectivity like in morpholibJ
// Run("Connected Components Labeling", "connectivity=6 type=[16 bits]");

Thanks so much, the segmentation is amazing in 2D for nuclei, I cannot imagine it was possible to do so good job ! Cheers, Mathieu

uschmidt83 commented 4 years ago

Hi Mathieu, thanks for using StarDist!

Our Python package can do 3D nuclei segmentation and we would love to bring that also to our Fiji plugin. However, there are unfortunately several technical challenges why this hasn't happened yet.

What you are trying to do (segment in 2D and merge) could work for some easier datasets, but is likely not going to work well in general. Hence, we're not pursuing this approach. However, if you want to give it a try, please have a look at this Jython script that shows how StarDist can be scripted from within Fiji.

Hope that helps.

Best, Uwe

haesleinhuepf commented 4 years ago

Hey @uschmidt83,

there are some people on the image.sc forum asking for how to run StartDist from ImageJ Macro or having issues in running it from Macro:

https://forum.image.sc/t/automation-of-stardist-in-imagej-macros/35611

https://forum.image.sc/t/beginner-in-clij-implementation-for-an-existing-macro/35541

Unfortunately, the Macro recorder just records run("StarDist 2D"); when executing the plugin. I was wondering if there are any plans for making StartDist usable from ImageJ Macro.

I would also be happy to help implementing it. Just let me know. ;-)

Cheers, Robert

uschmidt83 commented 4 years ago

Hi Robert,

Unfortunately, the Macro recorder just records run("StarDist 2D"); when executing the plugin. I was wondering if there are any plans for making StartDist usable from ImageJ Macro.

I would also be happy to help implementing it. Just let me know. ;-)

I don't know if/how this is possible (note that StarDist is an ImageJ2 plugin). We'd gladly support ImageJ macro and the macro recorder if the amount of work to do that is reasonable ;)

Best, Uwe

haesleinhuepf commented 4 years ago

Hi Uwe,

cool. ImageJ2 plugins are usually recordable. In this case it's tricky. But I've done it before, so no big deal. I'll send a PR with the recordable plugin soon.

Cheers, Robert

matfallet commented 4 years ago

Hi Uwe, It would be great to have plugin for sure. I will try now to run your python code from my macro as I need a 3D version. Is-it possible to run your python code like this ? call("ij.plugin.Macro_Runner.runPython", script, parameter); Thanks, Mathieu

uschmidt83 commented 4 years ago

Hi @matfallet,

sorry for the late reply. I don't think you can easily call our python code from within Fiji, let alone a macro.

Sorry.

matfallet commented 4 years ago

Hi Uwe,

ok thanks, do you implement just right now image J macro on 2D ?

We have tested the 3D python on our images (KI67proliferative nucleu but also dapi). It doesn't seem to work.

We have questions about it :

Thanks for you reply, maybe i can put the questions on Github ?

Cheers, Mathieu

uschmidt83 commented 4 years ago
  • do you implement it on synthetic data only ?

No, the example just uses synthetic data.

  • Does your model is robust to different parameters, in 2D it works perfect, so why not in 3D ?

I don't understand. Do you mean why the 3D model cannot be applied to other images like yours? In contrast to the 2D model, which was trained a larger variety of different images, there is no similar model in 3D yet. Hence, for now you need to train a model on your own labeled training data.

matfallet commented 4 years ago

OK I understand, there is no model cuurently in 3D to detect nuclei like for 2D : versatile (fluo nuclei). I suppose that the 3D model could be trained on 3D image with high voxel size (good sampling) and then we can change the number of slices to train on lower sampling...how many cells do you use to build the 2D model ? Just an idea how long could it takes in 3D.. Thanks Mathieu

uschmidt83 commented 4 years ago

how many cells do you use to build the 2D model ? Just an idea how long could it takes in 3D

We trained the 2D model on hundreds of images (thousands of cells) of the DSB 2018 nuclei segmentation challenge dataset. That's why it works so well in general.

In general, it is very difficult to say how many annotated images/cells are needed to reach results that are good enough for the intended application. It really depends on the appearance variability of the to be segmented cells. The more variability, the more annotated data is required.