juglab / labkit-ui

Advanced Tool for Labeling And Segmentation
BSD 2-Clause "Simplified" License
34 stars 21 forks source link

Labkit incompatible with batch mode #85

Open SebastienTs opened 2 years ago

SebastienTs commented 2 years ago

Labkit seems incompatible with batch mode when calling it from a macro. I hint that it comes from the fact that the results is a virtual stack. Would it be possible to add a flag so that the results is not a virtual stack (when predicting a stack of modest size).

haesleinhuepf commented 2 years ago

Hi @SebastienTs ,

I'm following up this discussion and your email. Can you please provide more details? For example the macro you are trying to run and the corresponding model together with an example image would be great. It is otherwise very hard to reproduce your issue.

See also: https://en.wikipedia.org/wiki/Minimal_working_example

Thanks!

Robert

SebastienTs commented 2 years ago

Whatever the image and classifier, this macro runs fine:

CurrentImage = getTitle();
run("Segment Image With Labkit", "input="+CurrentImage+" segmenter_file=D:/Classifier.classifier use_gpu=1");

while this doesn't (no output):

CurrentImage = getTitle();
setBatchMode(true);
run("Segment Image With Labkit", "input="+CurrentImage+" segmenter_file=D:/Classifier.classifier use_gpu=1");
setBatchMode("exit & display");

Same behaviour when setting use_gpu=0

Tested on Windows 10 x64 with ImageJ2 2.3.0/1.53f; Java 1.8.0_172 [amd64]

SebastienTs commented 2 years ago

Actually, the problem seems more generic since other imglib based plugins returning results as virtual stacks suffer from a similar issue, or do not output anything. One example is Process > Filters > Frangi Vesselness.

Would it be possible to add an option available from the dialog box to perform the computations not lazily and return a non virtual stack (which would hopefully not interfere with batch mode)?

maarzt commented 2 years ago

Hi @SebastienTs,

Sorry I for the late response. I'm on parental leave right now. I will have a look at this next week. Your are right.

The problem is probably not in Labkit itself, but caused by the fact that Labkit is base so much on imglib2 and scijava. Any idea why the virtual stacks would cause trouble in batch mode?

maarzt commented 2 years ago

I didn't come across a single line of good source code while debugging this code.

There is a method Interpreter.addBatchModeImage(ImagePlus) this method is called correctly to add the output image the Interpreter.imageTable. All the images in the imageTable will be show when setBatchMode("exit & display") is called.

The problem now is with LegacyImageMap, it gets an "DisplayUpdateEvent' and calls Harmoizer.reBuildImagePlusData() on the output image which calls LegacyUtils.deleteImagePlus() and the deleteImagePlus calls removeBatchModeImage... anyway LegacyImageMap needs a complete rewrite...

maarzt commented 2 years ago

@SebastienTs The problem is caused by a bug in https://github.com/imagej/imagej-legacy. I created two PRs https://github.com/imagej/imagej-legacy/pull/272, https://github.com/imagej/imagej-legacy/pull/273 that will fix this.

You may download and install this imagej-legacy.jar into your Fiji, if you don't want to wait for the PRs to be merged and released.

SebastienTs commented 2 years ago

@maarzt Thanks for looking into it. I have tried the new .jar. It works with a small glitch: in batch mode the image "output" generated by the plugin is not active by default after execution (when it is without batch mode).

maarzt commented 2 years ago

glitch: in batch mode the image "output" generated by the plugin is not active by default after execution (when it is without batch mode).

Hi @SebastienTs, that's an interesting glitch. Maybe I can a fix for that as well. How do you see which image is active in batch mode?

SebastienTs commented 2 years ago

I see it by running another plugin right after exiting batch mode. Good practice is to select the image to process first, I agree, but this type of inconstitencies between normal and batch mode can quickly degenerate in bugs for non defensive programming...

On Tue, Mar 8, 2022, 14:33 Matthias Arzt @.***> wrote:

glitch: in batch mode the image "output" generated by the plugin is not active by default after execution (when it is without batch mode).

Hi @SebastienTs https://github.com/SebastienTs, that's an interesting glitch. Maybe I can a fix for that as well. How do you see which image is active in batch mode?

— Reply to this email directly, view it on GitHub https://github.com/juglab/labkit-ui/issues/85#issuecomment-1061782470, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABTFCUHF77FICA7NIZWQFRDU65JMDANCNFSM5OJXFF6A . You are receiving this because you were mentioned.Message ID: @.***>

maarzt commented 2 years ago

I could reproduce the problem. This script scales the segmented image:

run("Leaf");
run("Segment Image With Labkit", "segmenter_file=/home/arzt/leaf.classifier use_gpu=false");
run("Scale...", "x=0.5 y=0.5 width=254 height=223 interpolation=Bilinear average create");

But when I enable batch mode, the input image (leaf.jpg) is scaled instead.

setBatchMode(true);
run("Leaf");
run("Segment Image With Labkit", "segmenter_file=/home/arzt/leaf.classifier use_gpu=false");
setBatchMode("exit & show");
run("Scale...", "x=0.5 y=0.5 width=254 height=223 interpolation=Bilinear average create");