stardist / stardist-imagej

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

remove clearing the ROI manager before adding new ROI #17

Open jboulanger opened 2 years ago

jboulanger commented 2 years ago

Clearing the ROI manager prevent using startdist on multiple images in Fiji.

uschmidt83 commented 2 years ago

Hi and thanks for the PR. I can't really remember, but I think there was a reason why we cleared the ROI Manager. Is this important to your workflow?

jboulanger commented 2 years ago

Hi,

Yes it is important. I am using it on different channels in an IJ macro.

I tried using the label image output and extract the ROI from there but in batch mode, for some reason the label image was not accessible. Here is a test example that show the issue with the label image:

run("Close All");
run("Blobs (25K)");
run("Command From Macro", "command=[de.csbdresden.stardist.StarDist2D], args=['input':'blobs.gif', 'modelChoice':'Versatile (fluorescent nuclei)', 'normalizeInput':'true', 'percentileBottom':'0.0', 'percentileTop':'100.0', 'probThresh':'0.479071', 'nmsThresh':'0.3', 'outputType':'Label Image', 'nTiles':'1', 'excludeBoundary':'0', 'roiPosition':'Hyperstack', 'verbose':'false', 'showCsbdeepProgress':'false', 'showProbAndDist':'false'], process=[false]");
selectWindow("Label Image");

run("Close All");
run("Blobs (25K)");
setBatchMode("hide");
run("Command From Macro", "command=[de.csbdresden.stardist.StarDist2D], args=['input':'blobs.gif', 'modelChoice':'Versatile (fluorescent nuclei)', 'normalizeInput':'true', 'percentileBottom':'0.0', 'percentileTop':'100.0', 'probThresh':'0.479071', 'nmsThresh':'0.3', 'outputType':'Label Image', 'nTiles':'1', 'excludeBoundary':'0', 'roiPosition':'Hyperstack', 'verbose':'false', 'showCsbdeepProgress':'false', 'showProbAndDist':'false'], process=[false]");
selectWindow("Label Image");
setBatchMode("exit and display");

An other option was to use convert the image to a time lapse and normalizing the images before hand.

The third option was to modify the stardist code and hope this is useful to others.

I don't see any other use of the ROI Manager in the project at this level. It is only used in this function so it would suggest the side effect are minimal. The roiManager variable would actually not need to be a member of StartDist2DBase in the end and could have its scope limited to the export function. In that case, I would remove protected RoiManager roiManager = null; and have later

roiManager = RoiManager.getInstance();
if (roiManager == null) roiManager = new RoiManager();

otherwise, keep the protected member and have:

if (roiManager == null) {
    roiManager = RoiManager.getInstance();
    if (roiManager == null) roiManager = new RoiManager();
}

May be..