<div dir="ltr"><div>Hi Adrian,</div><div><br></div><div><div>> It's as if the ImageDisplay parameter was getting populated by the</div><div>> image before cropping</div></div><div><br></div><div>It seems that the ROI syncing between IJ1 and IJ2 is not happening as expected. When your command runs, a sync is supposed to happen during preprocessing because you have a Dataset parameter. But maybe the sync is incomplete for some reason. Sorry I don't have time to investigate it right now, though.</div><div><br></div>> <span style="font-size:12.8px">What are those WARNINGs printed upon plugin invokation ?</span><div><span style="font-size:12.8px"><br></span></div><div><span style="font-size:12.8px">Those were debugging statements, which were erroneously set to log.warn. I fixed it [1].</span></div><div><span style="font-size:12.8px"><br></span></div><div>Regards,</div><div>Curtis</div><div><br></div><div>[1] <a href="https://github.com/imagej/imagej-legacy/commit/2015336482fe284954d2603fede892d616d20960">https://github.com/imagej/imagej-legacy/commit/2015336482fe284954d2603fede892d616d20960</a></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Sep 4, 2015 at 2:29 PM, Adrian Daerr <span dir="ltr"><<a href="mailto:adrian.daerr@univ-paris-diderot.fr" target="_blank">adrian.daerr@univ-paris-diderot.fr</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Hi Curtis,<br>
<br>
OverlayService.getSelectionBounds seems to behave stranger yet. Take the Foo_Bar test plugin source from my previous post, compile it and place it in ImageJ's plugins directory. Start ImageJ, create a new image (say 400x400 8bpp), draw a rectangular selection inside and invoke Foo_Bar: as reported in my last mail it will report a getSelectionBounds of 399x399 instead of the expected dimension of the rectangular selection. Now crop the image to the rectangular selection via Image->Crop, and invoke Foo_Bar again. It will report the same getSelectionBounds (width 399, height 399) although the active image is now strictly smaller. It's as if the ImageDisplay parameter was getting populated by the image before cropping (and of course still without rectangular selection).<br>
<br>
How is one supposed to use OverlayService.getSelectionBounds ?<br>
What are those WARNINGs printed upon plugin invokation ?<span class=""><br>
<br>
[WARNING] ====> Roi class = ij.gui.Roi<br></span>
[WARNING] ====> RECTANGLE: Roi[Rectangle, x=76, y=92, width=209, height=160]<br>
<br>
cheers,<br>
Adrian<br>
<br>
<br>
On Tue, 01 Sep 2015 20:41:30 +0200<div class="HOEnZb"><div class="h5"><br>
 "Adrian Daerr" <<a href="mailto:adrian.daerr@univ-paris-diderot.fr" target="_blank">adrian.daerr@univ-paris-diderot.fr</a>> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi Curtis, hi all,<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
If all you care about is the bounding box of the active selection, you can just do it the same way as the ImageJ2 CropImageJ command:<br>
by calling OverlayService.getSelectionBounds. Then you would<br>
avoid some of the current weirdness associated with Overlay<br>
parameters.<br>
</blockquote>
<br>
This was working fine with a programmatically added rectangular overlay/selection, but when I call getSelectionBounds on an image with an interactively created rectangular selection it returns the whole image dimension. It does not seem to be aware of the ROI. Below is a MVCE to reproduce. After compiling and placing it in the plugins folder, I start imagej, create a new image, draw a rectangular selection using ImageJ's leftmost tool and then invoque the plugin. It logs the following to the console:<br>
<br>
[WARNING] ====> Roi class = ij.gui.Roi<br>
[WARNING] ====> RECTANGLE: Roi[Rectangle, x=100, y=163, width=196, height=112]<br>
[INFO] image: plugin:class net.imagej.display.DefaultImageDisplay: type=interface net.imagej.display.DataView, name=Untitled, objects={net.imagej.display.DefaultDatasetView@757dbeaf, net.imagej.display.DefaultOverlayView@2198a037}<br>
[INFO] region: +0.0 +0.0, 559.0 x 559.0<br>
<br>
I expected the region in the last line (that obtained through OverlayService.getSelectionBounds) to coincide with the Roi mentionned in the WARNING.<br>
<br>
The CropImage command you mentionned does not do anything either before calling getSelectionBounds, and cropping works fine. Do you understand what is going on ?<br>
<br>
Cheers,<br>
Adrian<br>
<br>
<br>
import net.imagej.display.ImageDisplay;<br>
import net.imagej.display.OverlayService;<br>
<br>
import org.scijava.command.Command;<br>
import org.scijava.log.LogService;<br>
import org.scijava.plugin.Parameter;<br>
import org.scijava.plugin.Plugin;<br>
import org.scijava.util.RealRect;<br>
<br>
@Plugin(type = Command.class, menuPath = "Plugins>Foo_Bar")<br>
public class Foo_Bar implements Command {<br>
<br>
    @Parameter<br>
    private ImageDisplay display;<br>
<br>
    @Parameter<br>
    private OverlayService overlayService;<br>
<br>
    @Parameter<br>
    private LogService log;<br>
<br>
    @Override<br>
    public void run() {<br>
        RealRect r = overlayService.getSelectionBounds(display);<br>
        <a href="http://log.info" rel="noreferrer" target="_blank">log.info</a>("image: "+display);<br>
        <a href="http://log.info" rel="noreferrer" target="_blank">log.info</a>("region: +" + r.x + " +" +  r.y<br>
                 + ", " +  r.width + " x " + r.height);<br>
    }<br>
}<br>
<br>
<br>
<br>
<br>
On Mon, 24 Aug 2015 16:22:15 -0500<br>
 Curtis Rueden <<a href="mailto:ctrueden@wisc.edu" target="_blank">ctrueden@wisc.edu</a>> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hi Adrian,<br>
<br>
Glad to hear you found a working solution!<br>
<br>
The short answer about ROIs is that they have not been a focus of ImageJ2<br>
or ImgLib2 development in recent years. Support for labelings (highly<br>
related to ROIs) was rewritten this January [1], but a rewrite of the core<br>
ImgLib2 ROI library [2] is still pending. And there is a substantial<br>
pending redesign of the ImageJ Common data model planned as well -- though<br>
it is unlikely anyone will work on it this year.<br>
<br>
At this juncture, the most effective balance for most plugin developers is<br>
probably to use parameterized commands and/or scripts, but with the ImageJ1<br>
data structures (ij.ImagePlus, etc.) -- unless you need access to a new<br>
capability that ImageJ2 + ImgLib2 make possible (>5D images, very large<br>
image planes, very large numbers of image planes, dynamically generated<br>
images, images stored in places besides disk, cell-based image caching,<br>
image types beyond uint8/uint16/float32, etc.).<br>
<br>
That said, your feedback is very much appreciated.<br>
<br>
And some issues will be ironed out in the next couple of weeks as we revamp<br>
the tutorials for the upcoming ImageJ conference.<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
The easiest way to give a plugin a (rectangular) roi is to ... just<br>
declare a net.imagej.overlay.RectangularOverlay as an input parameter.<br>
It is properly populated by the origin and extent of a rectangular<br>
selection drawn on the active image.<br>
</blockquote>
<br>
If all you care about is the bounding box of the active selection, you can<br>
just do it the same way as the ImageJ2 CropImageJ command: by calling<br>
OverlayService.getSelectionBounds [3]. Then you would avoid some of the<br>
current weirdness associated with Overlay parameters.<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
If I launch the default UI, then the ROI will not show, but the plugin<br>
can launch. If on the other hand I launch the "swing" UI as in the<br>
tutorial, I do see the ROI<br>
</blockquote>
<br>
Yes, that tutorial was written when the ImageJ2 Swing UI was still the<br>
default. It is not tested/working with the Legacy UI (which is now the<br>
default). I will try to remedy that very soon.<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
(not until I call Image>Adjust>Brightness/Contrast..., but that's a<br>
minor detail),<br>
</blockquote>
<br>
Yes, that annoying bug has been around for quite a while. Many things that<br>
refresh the display will do, such as pressing + then - to zoom in/out.<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
but now the invocation of the plugin at the end of main() will throw a<br>
MethodCallException with the stackTrace pasted below. How can the<br>
choice of a UI make the plugin execution fail ?<br>
</blockquote>
...<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Caused by: java.lang.NullPointerException<br>
        at Goutte_pendante.initTitle(Goutte_pendante.java:94)<br>
</blockquote>
<br>
In 2014, we made a conscious decision to support the ImageJ 1.x classes<br>
_only_ from the legacy UI. You cannot use them from the Swing UI. In your<br>
case: the ActiveImagePlusPreprocessor cannot set the active ImagePlus<br>
because WindowManager.getCurrentImage() returns null [4], because no ImageJ<br>
1.x user interface exists. So it stays null and then your initializer<br>
throws the NPE.<br>
<br>
Regards,<br>
Curtis<br>
<br>
[1]<br>
<a href="https://github.com/imglib/imglib2-roi/tree/imglib2-roi-0.3.2/src/main/java/net/imglib2/labeling" rel="noreferrer" target="_blank">https://github.com/imglib/imglib2-roi/tree/imglib2-roi-0.3.2/src/main/java/net/imglib2/labeling</a><br>
<br>
[2] <a href="https://github.com/imglib/imglib2-roi" rel="noreferrer" target="_blank">https://github.com/imglib/imglib2-roi</a><br>
<br>
[3]<br>
<a href="https://github.com/imagej/imagej-plugins-commands/blob/imagej-plugins-commands-0.5.1/src/main/java/net/imagej/plugins/commands/imglib/CropImage.java#L104" rel="noreferrer" target="_blank">https://github.com/imagej/imagej-plugins-commands/blob/imagej-plugins-commands-0.5.1/src/main/java/net/imagej/plugins/commands/imglib/CropImage.java#L104</a><br>
<br>
[4]<br>
<a href="https://github.com/imagej/imagej-legacy/blob/imagej-legacy-0.17.1/src/main/java/net/imagej/legacy/plugin/ActiveImagePlusPreprocessor.java#L49-L52" rel="noreferrer" target="_blank">https://github.com/imagej/imagej-legacy/blob/imagej-legacy-0.17.1/src/main/java/net/imagej/legacy/plugin/ActiveImagePlusPreprocessor.java#L49-L52</a><br>
<br>
<br>
On Sun, Aug 23, 2015 at 6:30 AM, Adrian Daerr <<br>
<a href="mailto:adrian.daerr@univ-paris-diderot.fr" target="_blank">adrian.daerr@univ-paris-diderot.fr</a>> wrote:<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hello,<br>
<br>
While I am still interested in answers concerning the status/API/roadmap<br>
for ROIs and overlays beyond what's on <a href="http://imagej.net/ROIs" rel="noreferrer" target="_blank">http://imagej.net/ROIs</a>, I have<br>
solved the problem at hand which was keeping me from making progress, so I<br>
post the (rather obvious, once I found the net.imagej.overlay package)<br>
solution here for the record and to close this thread.<br>
<br>
The easiest way to give a plugin a (rectangular) roi is to ...<br>
just declare a net.imagej.overlay.RectangularOverlay as an input<br>
parameter. It is properly populated by the origin and extent of a<br>
rectangular selection drawn on the active image.<br>
<br>
cheers,<br>
Adrian<br>
<br>
<br>
On Wed, 19 Aug 2015 17:10:06 +0200<br>
<br>
 "Adrian Daerr" <<a href="mailto:adrian.daerr@univ-paris-diderot.fr" target="_blank">adrian.daerr@univ-paris-diderot.fr</a>> wrote:<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Dear ImageJ developers,<br>
<br>
I have included code from the AddROIs tutorial into the main()<br>
method of my plugin (for the moment essentially one of Curtis'<br>
commands-with-preview example), to select a Rectangle before<br>
calling the plugin. The source is available here:<br>
<br>
<a href="https://gitlab.com/pendant-drop/pendant-drop" rel="noreferrer" target="_blank">https://gitlab.com/pendant-drop/pendant-drop</a><br>
(in Goutte_pendante.java)<br>
<br>
If I launch the default UI, then the ROI will not show, but the<br>
plugin can launch. If on the other hand I launch the "swing" UI<br>
as in the tutorial, I do see the ROI (not until I call<br>
Image>Adjust>Brightness/Contrast..., but that's a minor detail),<br>
but now the invocation of the plugin at the end of main() will<br>
throw a MethodCallException with the stackTrace pasted below. How<br>
can the choice of a UI make the plugin execution fail ?<br>
<br>
Is there any other way that main can set a ROI on a loaded image<br>
that the plugin, which still uses an ImagePlus as input<br>
parameter, will see when calling imp.getProcessor().getRoi() ?<br>
<br>
TIA<br>
Adrian<br>
<br>
<br>
$> mvn package<br>
$> fiji --class-path target/pendant_drop-2.0.0-SNAPSHOT.jar<br>
Goutte_pendante.class<br>
[INFO] Overriding About Pendant Drop; identifier:<br>
command:About_Pendant_Drop; jar:<br>
file:/home/adrian/Programmes/plugins_ImageJ_src/Traitement_Gouttes/target/pendant_drop-2.0.0-SNAPSHOT.jar<br>
[INFO] Overriding Pendant Drop; identifier: command:Goutte_pendante; jar:<br>
file:/home/adrian/Programmes/plugins_ImageJ_src/Traitement_Gouttes/target/pendant_drop-2.0.0-SNAPSHOT.jar<br>
[INFO] Populating metadata<br>
[INFO] Populating metadata<br>
[INFO] Found 10 JHotDraw adapters.<br>
org.scijava.module.MethodCallException: Error executing method:<br>
Goutte_pendante#initTitle<br>
        at org.scijava.module.MethodRef.execute(MethodRef.java:73)<br>
        at<br>
org.scijava.module.AbstractModuleItem.initialize(AbstractModuleItem.java:199)<br>
        at<br>
org.scijava.module.AbstractModule.initialize(AbstractModule.java:86)<br>
        at<br>
org.scijava.command.CommandModule.initialize(CommandModule.java:147)<br>
        at<br>
org.scijava.module.process.InitPreprocessor.process(InitPreprocessor.java:60)<br>
        at<br>
org.scijava.module.ModuleRunner.preProcess(ModuleRunner.java:104)<br>
        at org.scijava.module.ModuleRunner.run(ModuleRunner.java:156)<br>
        at org.scijava.module.ModuleRunner.call(ModuleRunner.java:126)<br>
        at org.scijava.module.ModuleRunner.call(ModuleRunner.java:65)<br>
        at<br>
org.scijava.thread.DefaultThreadService$2.call(DefaultThreadService.java:191)<br>
        at<br>
java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)<br>
        at java.util.concurrent.FutureTask.run(FutureTask.java:138)<br>
        at<br>
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)<br>
        at<br>
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)<br>
        at java.lang.Thread.run(Thread.java:662)<br>
Caused by: java.lang.reflect.InvocationTargetException<br>
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)<br>
        at<br>
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)<br>
        at<br>
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)<br>
        at java.lang.reflect.Method.invoke(Method.java:597)<br>
        at org.scijava.module.MethodRef.execute(MethodRef.java:69)<br>
        ... 14 more<br>
Caused by: java.lang.NullPointerException<br>
        at Goutte_pendante.initTitle(Goutte_pendante.java:94)<br>
        ... 19 more<br>
[ERROR] Module threw exception<br>
java.lang.NullPointerException<br>
        at Goutte_pendante.cancel(Goutte_pendante.java:87)<br>
        at<br>
org.scijava.command.CommandModule.cancel(CommandModule.java:140)<br>
        at<br>
org.scijava.module.ModuleRunner.cleanupAndBroadcastCancelation(ModuleRunner.java:189)<br>
        at org.scijava.module.ModuleRunner.run(ModuleRunner.java:161)<br>
        at org.scijava.module.ModuleRunner.call(ModuleRunner.java:126)<br>
        at org.scijava.module.ModuleRunner.call(ModuleRunner.java:65)<br>
        at<br>
org.scijava.thread.DefaultThreadService$2.call(DefaultThreadService.java:191)<br>
        at<br>
java.util.concurrent.FutureTask$Sync.innerRun(FutureTask.java:303)<br>
        at java.util.concurrent.FutureTask.run(FutureTask.java:138)<br>
        at<br>
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)<br>
        at<br>
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)<br>
        at java.lang.Thread.run(Thread.java:662)<br>
<br>
<br>
<br>
On Sat, 15 Aug 2015 13:14:13 +0200<br>
 Adrian Daerr <<a href="mailto:adrian.daerr@univ-paris-diderot.fr" target="_blank">adrian.daerr@univ-paris-diderot.fr</a>> wrote:<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
Hello,<br>
<br>
I am seizing a major rewrite of a plugin as an opportunity to switch<br>
from ImageJ1 to ImageJ2, also to avoid concurrency issues[*], and now<br>
lots of questions come up. Some concern the way ROIs are handled. What<br>
has happened in this regard since<br>
  <a href="http://imagej.net/ROIs" rel="noreferrer" target="_blank">http://imagej.net/ROIs</a><br>
was last updated ?<br>
<br>
[*] cf discussion on the ImageJ list archived at<br>
<br>
<a href="http://imagej.1557.x6.nabble.com/ExtendedPlugInFilter-GenericDialog-and-synchronization-td5013333.html" rel="noreferrer" target="_blank">http://imagej.1557.x6.nabble.com/ExtendedPlugInFilter-GenericDialog-and-synchronization-td5013333.html</a><br>
<br>
Here are two concrete questions:<br>
<br>
1) My plugin relies on a rectangular ROI being drawn on the image to<br>
know which area to include in the computation. How do I draw this ROI<br>
once I have loaded the image as a dataset in the main() method that is<br>
used for testing purposes ?<br>
<br>
public static void main(final String... args) throws Exception {<br>
    final String testImagePath = "testImage.jpg";<br>
<br>
    // Launch ImageJ as usual.<br>
    final ImageJ ij = net.imagej.Main.launch(args);<br>
<br>
    // Open test image.<br>
    final Dataset dataset = ij.dataset().open(testImagePath);<br>
<br>
    // display the dataset<br>
    ij.ui().show(dataset);<br>
<br>
    // create rectangular ROI<br>
    //imp.setRoi(120,60,340,420);// How to do this on a dataset ?<br>
<br>
    // Launch the "Foo_Bar" command.<br>
    ij.command().run(Foo_Bar.class, true);<br>
}<br>
<br>
(alternatively, how would I generate a new dataset, or I guess something<br>
like a "View" in ImageJ2 terminology, of the ROI sub-image of the original<br>
dataset ? I could then substitute the original dataset with this sub-image<br>
and have the plugin operate on the whole image by default)<br>
<br>
2) The plugin preview generates overlays using java.awt.geom.Path2D,<br>
java.awt.geom.Area and java.awt.Shape, which are then converted via<br>
ij.gui.ShapeRoi() and ij.gui.Overlay(), assembled with overlay.add(),<br>
and drawn using imp.setOverlay(). Is there a new IJ2-way to do this<br>
(especially since the cited web page (rightly) insists on separation<br>
of selection and visualisation shapes) ?<br>
<br>
TIA,<br>
Adrian<br>
<br>
_______________________________________________<br>
ImageJ-devel mailing list<br>
<a href="mailto:ImageJ-devel@imagej.net" target="_blank">ImageJ-devel@imagej.net</a><br>
<a href="http://imagej.net/mailman/listinfo/imagej-devel" rel="noreferrer" target="_blank">http://imagej.net/mailman/listinfo/imagej-devel</a><br>
<br>
</blockquote>
<br>
--<br>
<a href="http://www.msc.univ-paris-diderot.fr/~daerr/" rel="noreferrer" target="_blank">http://www.msc.univ-paris-diderot.fr/~daerr/</a><br>
<br>
_______________________________________________<br>
ImageJ-devel mailing list<br>
<a href="mailto:ImageJ-devel@imagej.net" target="_blank">ImageJ-devel@imagej.net</a><br>
<a href="http://imagej.net/mailman/listinfo/imagej-devel" rel="noreferrer" target="_blank">http://imagej.net/mailman/listinfo/imagej-devel</a><br>
<br>
</blockquote>
<br>
--<br>
<a href="http://www.msc.univ-paris-diderot.fr/~daerr/" rel="noreferrer" target="_blank">http://www.msc.univ-paris-diderot.fr/~daerr/</a><br>
<br>
_______________________________________________<br>
ImageJ-devel mailing list<br>
<a href="mailto:ImageJ-devel@imagej.net" target="_blank">ImageJ-devel@imagej.net</a><br>
<a href="http://imagej.net/mailman/listinfo/imagej-devel" rel="noreferrer" target="_blank">http://imagej.net/mailman/listinfo/imagej-devel</a><br>
<br>
</blockquote></blockquote>
<br>
-- <br>
<a href="http://www.msc.univ-paris-diderot.fr/~daerr/" rel="noreferrer" target="_blank">http://www.msc.univ-paris-diderot.fr/~daerr/</a><br>
</blockquote>
<br></div></div><span class="HOEnZb"><font color="#888888">
-- <br>
<a href="http://www.msc.univ-paris-diderot.fr/~daerr/" rel="noreferrer" target="_blank">http://www.msc.univ-paris-diderot.fr/~daerr/</a><br>
</font></span></blockquote></div><br></div>