Different behavior of plugin called from macro

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Different behavior of plugin called from macro

Jon Harman-3
Hi,
I have a plugin that as part of a long sequence of image manipulations
crops an image.  This works fine when run from the plugins menu.  When I
run the plugin from a macro the crop fails, saying an area selection is
required.  When it fails it displays the image with a rectangle ROI
which is the wrong size.
The plugin is then permanently broken until I restart ImageJ.  Then it
works fine again.

This is a mystery to me.  Hope someone can help.  my code is:

Polygon corners = new Polygon();
for(int i = 0; i < 4; i++) corners.addPoint(cor[i].x,cor[i].y);
        corners.addPoint(cor[0].x, cor[0].y);// close the polygon
PolygonRoi corroi = new PolygonRoi(corners, Roi.POLYGON);
                       
iw = trans.getWindow();
iw.toFront();
trans.setRoi(corroi);
trans.show();
IJ.run("Crop");

Jon

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Different behavior of plugin called from macro

Michael Schmid-3
Hi Jon,

when selecting an image, use the WindowManager.setCurrentWindow function, instead of bringing an image to the foreground (which depends on the gui).
Even better, it should be possible to address the ImagePlus directly:

  IJ.run(imp, "Crop", null);

where imp is your ImagePlus (named 'trans'?)

Michael
________________________________________________________________
On Oct 21, 2015, at 19:12, Jon Harman wrote:

> Hi,
> I have a plugin that as part of a long sequence of image manipulations crops an image.  This works fine when run from the plugins menu.  When I run the plugin from a macro the crop fails, saying an area selection is required.  When it fails it displays the image with a rectangle ROI which is the wrong size.
> The plugin is then permanently broken until I restart ImageJ.  Then it works fine again.
>
> This is a mystery to me.  Hope someone can help.  my code is:
>
> Polygon corners = new Polygon();
> for(int i = 0; i < 4; i++) corners.addPoint(cor[i].x,cor[i].y);
> corners.addPoint(cor[0].x, cor[0].y);// close the polygon
> PolygonRoi corroi = new PolygonRoi(corners, Roi.POLYGON);
>
> iw = trans.getWindow();
> iw.toFront();
> trans.setRoi(corroi);
> trans.show();
> IJ.run("Crop");
>
> Jon

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Different behavior of plugin called from macro

Jon Harman-3
Hi,
Thanks for the advice.  I now see that my problem stems from the
following code:

iw = trans.getWindow();
WindowManager.setCurrentWindow(iw);
IJ.run("Scale...", "x=- y=- width=" + rotatew + " height=" + newh +"
interpolation=Bilinear average create title=Transformed1");
ImagePlus trans1 = WindowManager.getCurrentImage();


I want to use the scale command in a mode that creates a new image.
(Otherwise the old image is cropped after scaling.)  I think my problem
is in getting the new imagePlus.

Jon

On 10/21/2015 10:27 AM, Michael Schmid wrote:

> Hi Jon,
>
> when selecting an image, use the WindowManager.setCurrentWindow function, instead of bringing an image to the foreground (which depends on the gui).
> Even better, it should be possible to address the ImagePlus directly:
>
>    IJ.run(imp, "Crop", null);
>
> where imp is your ImagePlus (named 'trans'?)
>
> Michael
> ________________________________________________________________
> On Oct 21, 2015, at 19:12, Jon Harman wrote:
>
>> Hi,
>> I have a plugin that as part of a long sequence of image manipulations crops an image.  This works fine when run from the plugins menu.  When I run the plugin from a macro the crop fails, saying an area selection is required.  When it fails it displays the image with a rectangle ROI which is the wrong size.
>> The plugin is then permanently broken until I restart ImageJ.  Then it works fine again.
>>
>> This is a mystery to me.  Hope someone can help.  my code is:
>>
>> Polygon corners = new Polygon();
>> for(int i = 0; i < 4; i++) corners.addPoint(cor[i].x,cor[i].y);
>> corners.addPoint(cor[0].x, cor[0].y);// close the polygon
>> PolygonRoi corroi = new PolygonRoi(corners, Roi.POLYGON);
>>
>> iw = trans.getWindow();
>> iw.toFront();
>> trans.setRoi(corroi);
>> trans.show();
>> IJ.run("Crop");
>>
>> Jon
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Different behavior of plugin called from macro

Jon Harman-3
In reply to this post by Michael Schmid-3
Hi,
After changing all my IJ.Run to use the ImagePlus directly, my problems
have disappeared.

Thanks
Jon

On 10/21/2015 10:27 AM, Michael Schmid wrote:

> Hi Jon,
>
> when selecting an image, use the WindowManager.setCurrentWindow function, instead of bringing an image to the foreground (which depends on the gui).
> Even better, it should be possible to address the ImagePlus directly:
>
>    IJ.run(imp, "Crop", null);
>
> where imp is your ImagePlus (named 'trans'?)
>
> Michael
> ________________________________________________________________
> On Oct 21, 2015, at 19:12, Jon Harman wrote:
>
>> Hi,
>> I have a plugin that as part of a long sequence of image manipulations crops an image.  This works fine when run from the plugins menu.  When I run the plugin from a macro the crop fails, saying an area selection is required.  When it fails it displays the image with a rectangle ROI which is the wrong size.
>> The plugin is then permanently broken until I restart ImageJ.  Then it works fine again.
>>
>> This is a mystery to me.  Hope someone can help.  my code is:
>>
>> Polygon corners = new Polygon();
>> for(int i = 0; i < 4; i++) corners.addPoint(cor[i].x,cor[i].y);
>> corners.addPoint(cor[0].x, cor[0].y);// close the polygon
>> PolygonRoi corroi = new PolygonRoi(corners, Roi.POLYGON);
>>
>> iw = trans.getWindow();
>> iw.toFront();
>> trans.setRoi(corroi);
>> trans.show();
>> IJ.run("Crop");
>>
>> Jon
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Config file and Java 9

Jon Harman-3
In reply to this post by Jon Harman-3
Hi,
There are some mysteries having do with the cfg file and Java 9 on a
Windows 10 64 bit machine. Can anyone help?

My ImageJ directory has the jre inside.  No matter what I put into the
.cfg file, ImageJ uses that.  For example:

C:\Program Files\Java\jre-9.0.1\bin\javaw.exe
-Xmx12000m -cp ij.jar ij.ImageJ

OK so I deleted the jre directory.  Then ImageJ says it is using
Java 1.8.0_65[64-bit];
I do have this JDK installed on my machine, but why isn't it using Java 9?

If I double click on ij.jar
It says Java 9.0.1...

What is going on?  ImageJ must be using some PATH variables instead of
the config file.
I do see JAVA_HOME C:\Program Files\Java\jdk-9.0.1
I assume that double clicking on ij.jar is using this path, but I see
nothing pointing to Java 8.

Thanks for any help,
Jon

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Config file and Java 9

ctrueden
In reply to this post by Jon Harman-3
Hi Jon,

I am not sure whether ImageJ 1.x currently uses the ImageJ Launcher or not (
https://imagej.net/Launcher). You could check by running "ImageJ.exe
--help" from the command line. If you see a line like "ImageJ launcher
x.y.z (build abcdef09)" then it's the ImageJ Launcher.

If that native launcher is indeed being used, you could try launching
ImageJ from the command line to get more information:

    https://imagej.net/Troubleshooting#Launching_ImageJ_from_the_console

On Windows, the easiest way to do that is to make a copy of ImageJ.exe
called debug.exe and run it.

Regards,
Curtis

--
Curtis Rueden
LOCI software architect - https://loci.wisc.edu/software
ImageJ2 lead, Fiji maintainer - https://imagej.net/User:Rueden
Did you know ImageJ has a forum? http://forum.imagej.net/


On Tue, Feb 20, 2018 at 12:04 PM, Jon Harman <[hidden email]>
wrote:

> Hi,
> There are some mysteries having do with the cfg file and Java 9 on a
> Windows 10 64 bit machine. Can anyone help?
>
> My ImageJ directory has the jre inside.  No matter what I put into the
> .cfg file, ImageJ uses that.  For example:
>
> C:\Program Files\Java\jre-9.0.1\bin\javaw.exe
> -Xmx12000m -cp ij.jar ij.ImageJ
>
> OK so I deleted the jre directory.  Then ImageJ says it is using
> Java 1.8.0_65[64-bit];
> I do have this JDK installed on my machine, but why isn't it using Java 9?
>
> If I double click on ij.jar
> It says Java 9.0.1...
>
> What is going on?  ImageJ must be using some PATH variables instead of the
> config file.
> I do see JAVA_HOME C:\Program Files\Java\jdk-9.0.1
> I assume that double clicking on ij.jar is using this path, but I see
> nothing pointing to Java 8.
>
> Thanks for any help,
> Jon
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html
>

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html