issue: works with Fiji graphical interface but not on the command line

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

issue: works with Fiji graphical interface but not on the command line

Tamas Karpati
Dear fellow developers/users,

I was recently recommended to use Fiji and find it very nice, indeed.
Also it looks easy to automatize image analysis but I hit the wall here.

I installed the Interactive Watershed plugin
(I guess my issue is not specific to it, though)
from "https://imagej.net/plugins/interactive-watershed"
and run it from a simple javascript macro (attached):

    ImageJ-linux64 -macro attempt.js

It loads an image --> grayscale --> Watershed (not actually interactively).
The issue is that it cannot find the result image, instead it saves the
grayscale image (its log is attached as CLI.txt).


Interestingly, running the same script from the Plugins/Macros/Run menu
(after File/Close All) I got the real results saved.
Its log is attached as GUI.txt to let you compare to CLI.txt.


I tried whatever I found at
https://imagej.nih.gov/ij/developer/api/ij/module-summary.html
to no avail.

Can you please give me a hint on how to hunt down the results?

Thank you in advance,
  Tamas


My script is listed here as the mailer assumes it is insecure:

// Example script to load a raster image and do the Interactive Watershed.
//
// NOTE:   While it runs when loaded via Plugins/Macros/Run,
//         running from the command line it fails:
//
//           $ ImageJ-linux64 -macro attempt.js
//
//         (probably due to grabbing the wrong window, ie. taking the
//         grayscale image instead of the watershedded one; it is seen
//         from that the wrong window is renamed to "apple").
//
// NOTE-2: I do not think it is related to Interactive Watershed at all.


importClass(Packages.ij.IJ);
importClass(Packages.ij.WindowManager);



function listAllWindowsAndImages( ) {
    IJ.log("\n    Window IDs ("+WindowManager.getWindowCount()+"):");
    var IDlist = WindowManager.getIDList();
    for (var i in IDlist) {
        IJ.log("        "+IDlist[i]);
        if (i == IDlist.length)
            IJ.log(" <-- the last one");
    }
    IJ.log("    Images ("+WindowManager.getImageCount()+"):");
    var IMlist = WindowManager.getImageTitles();
    for (var i in IMlist)
        IJ.log("      "+IMlist[i]+"  ID: "+WindowManager.getNthImageID(i));
    IJ.log("    Non-images:");
    IMlist = WindowManager.getNonImageTitles();
    for (var i in IMlist)
        IJ.log("      "+IMlist[i]);
    IJ.log("\n");
}



IJ.log("Loading an image...");
// from "https://imagej.net/plugins/interactive-watershed":
var imGray = IJ.openImage("figure-hmax-hwatershed-v3.png");
IJ.log("imGray: "+imGray+"\n"); // not now but soon it will be gray
listAllWindowsAndImages();


IJ.log("Showing it...");
imGray.show(); // if missing: the plugin cannot process `imGray'
listAllWindowsAndImages();


var titleGray = "gray"
IJ.log("Turning it to gray and renaming to \""+titleGray+"\"...");
IJ.run("32-bit");
imGray.setTitle(titleGray);
listAllWindowsAndImages();


IJ.log("Performing the main activity (takes a few seconds)...");
IJ.run("H_Watershed","impin=["+titleGray+"] hmin="
    +20+" thresh="+100+" peakflooding="+90
    +" outputmask=true allowsplitting=false");
listAllWindowsAndImages();


//
// look for the result image (the point that fails):
//


// via GUI it retrieves the latest (ie. results) image, but
// via the command line it takes the grayscale (ie. previous) image/window
var imWS = IJ.getImage();
var titleWS = "apple";
imWS.setTitle(titleWS);
IJ.log("imWS: "+imWS+"\n");
listAllWindowsAndImages();


IJ.log("\n###");
if (imWS == imGray) {
    IJ.log("It is probable that THE WRONG IMAGE will be saved!");
} else {
    IJ.log("It is probable that the CORRECT image will be saved.");
}
IJ.log("###\n");


IJ.save(imWS,titleWS+".png");
IJ.log("saved \""+titleWS+".png\".\n");

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

CLI.txt (1K) Download Attachment
GUI.txt (1K) Download Attachment
figure-hmax-hwatershed-v3.png (790K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: issue: works with Fiji graphical interface but not on the command line

Michael Schmid
Hi Tamas,

if there is a problem with the Interactive Watershed, did you have a
look at the the simple Process>Find Maxima? For many applications it is
good enough, and you can use Plugins>Macros>Record to get the respective
macro commands.

Find Maxima also has a "segmented particles" output, which is based on a
simple watershed algorithm (not as elaborate as that of the Interactive
Watershed). It does segmentation all the way into the background, so one
would have to use a threshold in addition to discriminate the particles
from the background.

If you want different particles with different grayscale, you can use
Analyze Particles with show "count masks" output after the segmentation.


Michael
________________________________________________________________
On 17.06.21 22:57, Tamas Karpati wrote:

> Dear fellow developers/users,
>
> I was recently recommended to use Fiji and find it very nice, indeed.
> Also it looks easy to automatize image analysis but I hit the wall here.
>
> I installed the Interactive Watershed plugin
> (I guess my issue is not specific to it, though)
> from "https://imagej.net/plugins/interactive-watershed"
> and run it from a simple javascript macro (attached):
>
>      ImageJ-linux64 -macro attempt.js
>
> It loads an image --> grayscale --> Watershed (not actually interactively).
> The issue is that it cannot find the result image, instead it saves the
> grayscale image (its log is attached as CLI.txt).
>
>
> Interestingly, running the same script from the Plugins/Macros/Run menu
> (after File/Close All) I got the real results saved.
> Its log is attached as GUI.txt to let you compare to CLI.txt.
>
>
> I tried whatever I found at
> https://imagej.nih.gov/ij/developer/api/ij/module-summary.html
> to no avail.
>
> Can you please give me a hint on how to hunt down the results?
>
> Thank you in advance,
>    Tamas
>
>
> My script is listed here as the mailer assumes it is insecure:
>
> // Example script to load a raster image and do the Interactive Watershed.
> //
> // NOTE:   While it runs when loaded via Plugins/Macros/Run,
> //         running from the command line it fails:
> //
> //           $ ImageJ-linux64 -macro attempt.js
> //
> //         (probably due to grabbing the wrong window, ie. taking the
> //         grayscale image instead of the watershedded one; it is seen
> //         from that the wrong window is renamed to "apple").
> //
> // NOTE-2: I do not think it is related to Interactive Watershed at all.
>
>
> importClass(Packages.ij.IJ);
> importClass(Packages.ij.WindowManager);
>
>
>
> function listAllWindowsAndImages( ) {
>      IJ.log("\n    Window IDs ("+WindowManager.getWindowCount()+"):");
>      var IDlist = WindowManager.getIDList();
>      for (var i in IDlist) {
>          IJ.log("        "+IDlist[i]);
>          if (i == IDlist.length)
>              IJ.log(" <-- the last one");
>      }
>      IJ.log("    Images ("+WindowManager.getImageCount()+"):");
>      var IMlist = WindowManager.getImageTitles();
>      for (var i in IMlist)
>          IJ.log("      "+IMlist[i]+"  ID: "+WindowManager.getNthImageID(i));
>      IJ.log("    Non-images:");
>      IMlist = WindowManager.getNonImageTitles();
>      for (var i in IMlist)
>          IJ.log("      "+IMlist[i]);
>      IJ.log("\n");
> }
>
>
>
> IJ.log("Loading an image...");
> // from "https://imagej.net/plugins/interactive-watershed":
> var imGray = IJ.openImage("figure-hmax-hwatershed-v3.png");
> IJ.log("imGray: "+imGray+"\n"); // not now but soon it will be gray
> listAllWindowsAndImages();
>
>
> IJ.log("Showing it...");
> imGray.show(); // if missing: the plugin cannot process `imGray'
> listAllWindowsAndImages();
>
>
> var titleGray = "gray"
> IJ.log("Turning it to gray and renaming to \""+titleGray+"\"...");
> IJ.run("32-bit");
> imGray.setTitle(titleGray);
> listAllWindowsAndImages();
>
>
> IJ.log("Performing the main activity (takes a few seconds)...");
> IJ.run("H_Watershed","impin=["+titleGray+"] hmin="
>      +20+" thresh="+100+" peakflooding="+90
>      +" outputmask=true allowsplitting=false");
> listAllWindowsAndImages();
>
>
> //
> // look for the result image (the point that fails):
> //
>
>
> // via GUI it retrieves the latest (ie. results) image, but
> // via the command line it takes the grayscale (ie. previous) image/window
> var imWS = IJ.getImage();
> var titleWS = "apple";
> imWS.setTitle(titleWS);
> IJ.log("imWS: "+imWS+"\n");
> listAllWindowsAndImages();
>
>
> IJ.log("\n###");
> if (imWS == imGray) {
>      IJ.log("It is probable that THE WRONG IMAGE will be saved!");
> } else {
>      IJ.log("It is probable that the CORRECT image will be saved.");
> }
> IJ.log("###\n");
>
>
> IJ.save(imWS,titleWS+".png");
> IJ.log("saved \""+titleWS+".png\".\n");
>
> --
> 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: issue: works with Fiji graphical interface but not on the command line

Tamas Karpati
Dear Michael,

Thank you for your suggestion. Process/Find Maxima indeed does the job.
To my surprise, the recorded IJM macro works fine on the command line
(no need to dive into javascript or else).

I would, however, still like to make Interactive Watershed work
(and now: to compare :)

Have a nice day,
  Tamas

On Fri, Jun 18, 2021 at 10:33 AM Michael Schmid <[hidden email]> wrote:

>
> Hi Tamas,
>
> if there is a problem with the Interactive Watershed, did you have a
> look at the the simple Process>Find Maxima? For many applications it is
> good enough, and you can use Plugins>Macros>Record to get the respective
> macro commands.
>
> Find Maxima also has a "segmented particles" output, which is based on a
> simple watershed algorithm (not as elaborate as that of the Interactive
> Watershed). It does segmentation all the way into the background, so one
> would have to use a threshold in addition to discriminate the particles
> from the background.
>
> If you want different particles with different grayscale, you can use
> Analyze Particles with show "count masks" output after the segmentation.
>
>
> Michael
> ________________________________________________________________
> On 17.06.21 22:57, Tamas Karpati wrote:
> > Dear fellow developers/users,
> >
> > I was recently recommended to use Fiji and find it very nice, indeed.
> > Also it looks easy to automatize image analysis but I hit the wall here.
> >
> > I installed the Interactive Watershed plugin
> > (I guess my issue is not specific to it, though)
> > from "https://imagej.net/plugins/interactive-watershed"
> > and run it from a simple javascript macro (attached):
> >
> >      ImageJ-linux64 -macro attempt.js
> >
> > It loads an image --> grayscale --> Watershed (not actually interactively).
> > The issue is that it cannot find the result image, instead it saves the
> > grayscale image (its log is attached as CLI.txt).
> >
> >
> > Interestingly, running the same script from the Plugins/Macros/Run menu
> > (after File/Close All) I got the real results saved.
> > Its log is attached as GUI.txt to let you compare to CLI.txt.
> >
> >
> > I tried whatever I found at
> > https://imagej.nih.gov/ij/developer/api/ij/module-summary.html
> > to no avail.
> >
> > Can you please give me a hint on how to hunt down the results?
> >
> > Thank you in advance,
> >    Tamas
> >
> >
> > My script is listed here as the mailer assumes it is insecure:
> >
> > // Example script to load a raster image and do the Interactive Watershed.
> > //
> > // NOTE:   While it runs when loaded via Plugins/Macros/Run,
> > //         running from the command line it fails:
> > //
> > //           $ ImageJ-linux64 -macro attempt.js
> > //
> > //         (probably due to grabbing the wrong window, ie. taking the
> > //         grayscale image instead of the watershedded one; it is seen
> > //         from that the wrong window is renamed to "apple").
> > //
> > // NOTE-2: I do not think it is related to Interactive Watershed at all.
> >
> >
> > importClass(Packages.ij.IJ);
> > importClass(Packages.ij.WindowManager);
> >
> >
> >
> > function listAllWindowsAndImages( ) {
> >      IJ.log("\n    Window IDs ("+WindowManager.getWindowCount()+"):");
> >      var IDlist = WindowManager.getIDList();
> >      for (var i in IDlist) {
> >          IJ.log("        "+IDlist[i]);
> >          if (i == IDlist.length)
> >              IJ.log(" <-- the last one");
> >      }
> >      IJ.log("    Images ("+WindowManager.getImageCount()+"):");
> >      var IMlist = WindowManager.getImageTitles();
> >      for (var i in IMlist)
> >          IJ.log("      "+IMlist[i]+"  ID: "+WindowManager.getNthImageID(i));
> >      IJ.log("    Non-images:");
> >      IMlist = WindowManager.getNonImageTitles();
> >      for (var i in IMlist)
> >          IJ.log("      "+IMlist[i]);
> >      IJ.log("\n");
> > }
> >
> >
> >
> > IJ.log("Loading an image...");
> > // from "https://imagej.net/plugins/interactive-watershed":
> > var imGray = IJ.openImage("figure-hmax-hwatershed-v3.png");
> > IJ.log("imGray: "+imGray+"\n"); // not now but soon it will be gray
> > listAllWindowsAndImages();
> >
> >
> > IJ.log("Showing it...");
> > imGray.show(); // if missing: the plugin cannot process `imGray'
> > listAllWindowsAndImages();
> >
> >
> > var titleGray = "gray"
> > IJ.log("Turning it to gray and renaming to \""+titleGray+"\"...");
> > IJ.run("32-bit");
> > imGray.setTitle(titleGray);
> > listAllWindowsAndImages();
> >
> >
> > IJ.log("Performing the main activity (takes a few seconds)...");
> > IJ.run("H_Watershed","impin=["+titleGray+"] hmin="
> >      +20+" thresh="+100+" peakflooding="+90
> >      +" outputmask=true allowsplitting=false");
> > listAllWindowsAndImages();
> >
> >
> > //
> > // look for the result image (the point that fails):
> > //
> >
> >
> > // via GUI it retrieves the latest (ie. results) image, but
> > // via the command line it takes the grayscale (ie. previous) image/window
> > var imWS = IJ.getImage();
> > var titleWS = "apple";
> > imWS.setTitle(titleWS);
> > IJ.log("imWS: "+imWS+"\n");
> > listAllWindowsAndImages();
> >
> >
> > IJ.log("\n###");
> > if (imWS == imGray) {
> >      IJ.log("It is probable that THE WRONG IMAGE will be saved!");
> > } else {
> >      IJ.log("It is probable that the CORRECT image will be saved.");
> > }
> > IJ.log("###\n");
> >
> >
> > IJ.save(imWS,titleWS+".png");
> > IJ.log("saved \""+titleWS+".png\".\n");
> >
> > --
> > ImageJ mailing list: http://imagej.nih.gov/ij/list.html
> >
>
> --
> 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: issue: works with Fiji graphical interface but not on the command line

Stein Rørvik
There is some general problem with Fiji's window handling that causes it to not work reliably when running a macro from the command line. At least for me (on Windows 10/64), whenever I try to run a macro in Fiji from the command line, a general problem is that the GUI does not appear until _after_ the macro has finished its execution. Any macro involving more than one image is thus prone to failure. So I don't think your problem is related to the Interactive Watershed per se, but maybe the Process/Find Maxima command uses a different type window handling that does not fail.

As an example, try launching the simple macro below from the command line. The scaling should take a minute or so to execute, to illustrate the behaviour: A minute or so after launching (the time Fiji requires to start) the T1 image appears. Then after another minute or so (the time rescaling takes) the rescaled stack appears. Then about 5-10 seconds after that, the GUI appears. If you have a fast computer, try to increase the scaling factor to 10 or more to slow this down to something that is noticeable.

run("T1 Head (16-bits)");
factor = 5;
run("Scale...", "x=&factor y=&factor z=&factor interpolation=Bilinear average process create");

If you try the same with ImageJ, the GUI appears almost immediately (a second or two after launch), then the T1 image appears, and then the rescaled image. The rescaling uses the same amount of seconds in Fiji as in ImageJ, but the GUI gives the advantage of having a progress bar and general visual feedback showing that the macro has started.  Because of this, I always use plain ImageJ for executing macros. Unfortunately, more advanced plugins like Interactive Watershed are difficult to install in ImageJ.

Stein

-----Original Message-----
Sent: 18. juni 2021 12:14
Subject: Re: issue: works with Fiji graphical interface but not on the command line

Dear Michael,

Thank you for your suggestion. Process/Find Maxima indeed does the job.
To my surprise, the recorded IJM macro works fine on the command line (no need to dive into javascript or else).

I would, however, still like to make Interactive Watershed work (and now: to compare :)

Have a nice day,
  Tamas

On Fri, Jun 18, 2021 at 10:33 AM Michael Schmid <[hidden email]> wrote:

>
> Hi Tamas,
>
> if there is a problem with the Interactive Watershed, did you have a
> look at the the simple Process>Find Maxima? For many applications it
> is good enough, and you can use Plugins>Macros>Record to get the
> respective macro commands.
>
> Find Maxima also has a "segmented particles" output, which is based on
> a simple watershed algorithm (not as elaborate as that of the
> Interactive Watershed). It does segmentation all the way into the
> background, so one would have to use a threshold in addition to
> discriminate the particles from the background.
>
> If you want different particles with different grayscale, you can use
> Analyze Particles with show "count masks" output after the segmentation.
>
>
> Michael
> ________________________________________________________________
> On 17.06.21 22:57, Tamas Karpati wrote:
> > Dear fellow developers/users,
> >
> > I was recently recommended to use Fiji and find it very nice, indeed.
> > Also it looks easy to automatize image analysis but I hit the wall here.
> >
> > I installed the Interactive Watershed plugin (I guess my issue is
> > not specific to it, though) from
> > "https://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fimagej.net%2Fplugins%2Finteractive-watershed&amp;data=04%7C01%7Cstein.rorvik%40sintef.no%7C7b3671c235b64ec47f7a08d932435f7c%7Ce1f00f39604145b0b309e0210d8b32af%7C1%7C1%7C637596087222760603%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&amp;sdata=okhDbxqoSXnqCnwHTYEk9d32B%2FMGya48Tzp7WBBKIVs%3D&amp;reserved=0"
> > and run it from a simple javascript macro (attached):
> >
> >      ImageJ-linux64 -macro attempt.js
> >
> > It loads an image --> grayscale --> Watershed (not actually interactively).
> > The issue is that it cannot find the result image, instead it saves
> > the grayscale image (its log is attached as CLI.txt).
> >
> >
> > Interestingly, running the same script from the Plugins/Macros/Run
> > menu (after File/Close All) I got the real results saved.
> > Its log is attached as GUI.txt to let you compare to CLI.txt.
> >
> >
> > I tried whatever I found at
> > https://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fim
> > agej.nih.gov%2Fij%2Fdeveloper%2Fapi%2Fij%2Fmodule-summary.html&amp;d
> > ata=04%7C01%7Cstein.rorvik%40sintef.no%7C7b3671c235b64ec47f7a08d9324
> > 35f7c%7Ce1f00f39604145b0b309e0210d8b32af%7C1%7C1%7C63759608722276060
> > 3%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTi
> > I6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&amp;sdata=1oCFkGfXGElrqK%2BPzUJfbCV7
> > vJfFVEIxNljx9bQIVj8%3D&amp;reserved=0
> > to no avail.
> >
> > Can you please give me a hint on how to hunt down the results?
> >
> > Thank you in advance,
> >    Tamas
> >
> >
> > My script is listed here as the mailer assumes it is insecure:
> >
> > // Example script to load a raster image and do the Interactive Watershed.
> > //
> > // NOTE:   While it runs when loaded via Plugins/Macros/Run,
> > //         running from the command line it fails:
> > //
> > //           $ ImageJ-linux64 -macro attempt.js
> > //
> > //         (probably due to grabbing the wrong window, ie. taking the
> > //         grayscale image instead of the watershedded one; it is seen
> > //         from that the wrong window is renamed to "apple").
> > //
> > // NOTE-2: I do not think it is related to Interactive Watershed at all.
> >
> >
> > importClass(Packages.ij.IJ);
> > importClass(Packages.ij.WindowManager);
> >
> >
> >
> > function listAllWindowsAndImages( ) {
> >      IJ.log("\n    Window IDs ("+WindowManager.getWindowCount()+"):");
> >      var IDlist = WindowManager.getIDList();
> >      for (var i in IDlist) {
> >          IJ.log("        "+IDlist[i]);
> >          if (i == IDlist.length)
> >              IJ.log(" <-- the last one");
> >      }
> >      IJ.log("    Images ("+WindowManager.getImageCount()+"):");
> >      var IMlist = WindowManager.getImageTitles();
> >      for (var i in IMlist)
> >          IJ.log("      "+IMlist[i]+"  ID: "+WindowManager.getNthImageID(i));
> >      IJ.log("    Non-images:");
> >      IMlist = WindowManager.getNonImageTitles();
> >      for (var i in IMlist)
> >          IJ.log("      "+IMlist[i]);
> >      IJ.log("\n");
> > }
> >
> >
> >
> > IJ.log("Loading an image...");
> > // from "https://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fimagej.net%2Fplugins%2Finteractive-watershed&amp;data=04%7C01%7Cstein.rorvik%40sintef.no%7C7b3671c235b64ec47f7a08d932435f7c%7Ce1f00f39604145b0b309e0210d8b32af%7C1%7C1%7C637596087222760603%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&amp;sdata=okhDbxqoSXnqCnwHTYEk9d32B%2FMGya48Tzp7WBBKIVs%3D&amp;reserved=0":
> > var imGray = IJ.openImage("figure-hmax-hwatershed-v3.png");
> > IJ.log("imGray: "+imGray+"\n"); // not now but soon it will be gray
> > listAllWindowsAndImages();
> >
> >
> > IJ.log("Showing it...");
> > imGray.show(); // if missing: the plugin cannot process `imGray'
> > listAllWindowsAndImages();
> >
> >
> > var titleGray = "gray"
> > IJ.log("Turning it to gray and renaming to \""+titleGray+"\"...");
> > IJ.run("32-bit"); imGray.setTitle(titleGray);
> > listAllWindowsAndImages();
> >
> >
> > IJ.log("Performing the main activity (takes a few seconds)...");
> > IJ.run("H_Watershed","impin=["+titleGray+"] hmin="
> >      +20+" thresh="+100+" peakflooding="+90
> >      +" outputmask=true allowsplitting=false");
> > listAllWindowsAndImages();
> >
> >
> > //
> > // look for the result image (the point that fails):
> > //
> >
> >
> > // via GUI it retrieves the latest (ie. results) image, but // via
> > the command line it takes the grayscale (ie. previous) image/window
> > var imWS = IJ.getImage(); var titleWS = "apple";
> > imWS.setTitle(titleWS);
> > IJ.log("imWS: "+imWS+"\n");
> > listAllWindowsAndImages();
> >
> >
> > IJ.log("\n###");
> > if (imWS == imGray) {
> >      IJ.log("It is probable that THE WRONG IMAGE will be saved!"); }
> > else {
> >      IJ.log("It is probable that the CORRECT image will be saved.");
> > } IJ.log("###\n");
> >
> >
> > IJ.save(imWS,titleWS+".png");
> > IJ.log("saved \""+titleWS+".png\".\n");
> >
> > --
> > ImageJ mailing list:
> > https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fima
> > gej.nih.gov%2Fij%2Flist.html&amp;data=04%7C01%7Cstein.rorvik%40sinte
> > f.no%7C7b3671c235b64ec47f7a08d932435f7c%7Ce1f00f39604145b0b309e0210d
> > 8b32af%7C1%7C1%7C637596087222760603%7CUnknown%7CTWFpbGZsb3d8eyJWIjoi
> > MC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&am
> > p;sdata=udNglLMU%2FJbPhx7zDrsfwGh%2BAQN6ZeVfQ30b5FBnbQE%3D&amp;reser
> > ved=0
> >
>
> --
> ImageJ mailing list:
> https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fimage
> j.nih.gov%2Fij%2Flist.html&amp;data=04%7C01%7Cstein.rorvik%40sintef.no
> %7C7b3671c235b64ec47f7a08d932435f7c%7Ce1f00f39604145b0b309e0210d8b32af
> %7C1%7C1%7C637596087222760603%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAw
> MDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&amp;sdata=ud
> NglLMU%2FJbPhx7zDrsfwGh%2BAQN6ZeVfQ30b5FBnbQE%3D&amp;reserved=0

--
ImageJ mailing list: https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fimagej.nih.gov%2Fij%2Flist.html&amp;data=04%7C01%7Cstein.rorvik%40sintef.no%7C7b3671c235b64ec47f7a08d932435f7c%7Ce1f00f39604145b0b309e0210d8b32af%7C1%7C1%7C637596087222760603%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&amp;sdata=udNglLMU%2FJbPhx7zDrsfwGh%2BAQN6ZeVfQ30b5FBnbQE%3D&amp;reserved=0

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

Re: issue: works with Fiji graphical interface but not on the command line

Tamas Karpati
Dear Stein,

Thank you for your explanation and reaction.

I also noticed some 0.1 sec delays between events on the screen and
tried to use the wait(1000) command between steps of execution -to no avail.
I could not find a way to bring all images/windows in synchron
(which is obviously done when the GUI is up).

You have, on the other hand, gave me an idea. My workflow might allow
to use just one window at a time. I will try to kill the unused ones
as I proceed.
Probably images can exist without a window (?) so in principle it can be done.

Thank you very much.
  Tamas


On Fri, Jun 18, 2021 at 7:31 PM Stein Rørvik <[hidden email]> wrote:

>
> There is some general problem with Fiji's window handling that causes it to not work reliably when running a macro from the command line. At least for me (on Windows 10/64), whenever I try to run a macro in Fiji from the command line, a general problem is that the GUI does not appear until _after_ the macro has finished its execution. Any macro involving more than one image is thus prone to failure. So I don't think your problem is related to the Interactive Watershed per se, but maybe the Process/Find Maxima command uses a different type window handling that does not fail.
>
> As an example, try launching the simple macro below from the command line. The scaling should take a minute or so to execute, to illustrate the behaviour: A minute or so after launching (the time Fiji requires to start) the T1 image appears. Then after another minute or so (the time rescaling takes) the rescaled stack appears. Then about 5-10 seconds after that, the GUI appears. If you have a fast computer, try to increase the scaling factor to 10 or more to slow this down to something that is noticeable.
>
> run("T1 Head (16-bits)");
> factor = 5;
> run("Scale...", "x=&factor y=&factor z=&factor interpolation=Bilinear average process create");
>
> If you try the same with ImageJ, the GUI appears almost immediately (a second or two after launch), then the T1 image appears, and then the rescaled image. The rescaling uses the same amount of seconds in Fiji as in ImageJ, but the GUI gives the advantage of having a progress bar and general visual feedback showing that the macro has started.  Because of this, I always use plain ImageJ for executing macros. Unfortunately, more advanced plugins like Interactive Watershed are difficult to install in ImageJ.
>
> Stein
>
> -----Original Message-----
> Sent: 18. juni 2021 12:14
> Subject: Re: issue: works with Fiji graphical interface but not on the command line
>
> Dear Michael,
>
> Thank you for your suggestion. Process/Find Maxima indeed does the job.
> To my surprise, the recorded IJM macro works fine on the command line (no need to dive into javascript or else).
>
> I would, however, still like to make Interactive Watershed work (and now: to compare :)
>
> Have a nice day,
>   Tamas
>
> On Fri, Jun 18, 2021 at 10:33 AM Michael Schmid <[hidden email]> wrote:
> >
> > Hi Tamas,
> >
> > if there is a problem with the Interactive Watershed, did you have a
> > look at the the simple Process>Find Maxima? For many applications it
> > is good enough, and you can use Plugins>Macros>Record to get the
> > respective macro commands.
> >
> > Find Maxima also has a "segmented particles" output, which is based on
> > a simple watershed algorithm (not as elaborate as that of the
> > Interactive Watershed). It does segmentation all the way into the
> > background, so one would have to use a threshold in addition to
> > discriminate the particles from the background.
> >
> > If you want different particles with different grayscale, you can use
> > Analyze Particles with show "count masks" output after the segmentation.
> >
> >
> > Michael
> > ________________________________________________________________
> > On 17.06.21 22:57, Tamas Karpati wrote:
> > > Dear fellow developers/users,
> > >
> > > I was recently recommended to use Fiji and find it very nice, indeed.
> > > Also it looks easy to automatize image analysis but I hit the wall here.
> > >
> > > I installed the Interactive Watershed plugin (I guess my issue is
> > > not specific to it, though) from
> > > "https://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fimagej.net%2Fplugins%2Finteractive-watershed&amp;data=04%7C01%7Cstein.rorvik%40sintef.no%7C7b3671c235b64ec47f7a08d932435f7c%7Ce1f00f39604145b0b309e0210d8b32af%7C1%7C1%7C637596087222760603%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&amp;sdata=okhDbxqoSXnqCnwHTYEk9d32B%2FMGya48Tzp7WBBKIVs%3D&amp;reserved=0"
> > > and run it from a simple javascript macro (attached):
> > >
> > >      ImageJ-linux64 -macro attempt.js
> > >
> > > It loads an image --> grayscale --> Watershed (not actually interactively).
> > > The issue is that it cannot find the result image, instead it saves
> > > the grayscale image (its log is attached as CLI.txt).
> > >
> > >
> > > Interestingly, running the same script from the Plugins/Macros/Run
> > > menu (after File/Close All) I got the real results saved.
> > > Its log is attached as GUI.txt to let you compare to CLI.txt.
> > >
> > >
> > > I tried whatever I found at
> > > https://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fim
> > > agej.nih.gov%2Fij%2Fdeveloper%2Fapi%2Fij%2Fmodule-summary.html&amp;d
> > > ata=04%7C01%7Cstein.rorvik%40sintef.no%7C7b3671c235b64ec47f7a08d9324
> > > 35f7c%7Ce1f00f39604145b0b309e0210d8b32af%7C1%7C1%7C63759608722276060
> > > 3%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTi
> > > I6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&amp;sdata=1oCFkGfXGElrqK%2BPzUJfbCV7
> > > vJfFVEIxNljx9bQIVj8%3D&amp;reserved=0
> > > to no avail.
> > >
> > > Can you please give me a hint on how to hunt down the results?
> > >
> > > Thank you in advance,
> > >    Tamas
> > >
> > >
> > > My script is listed here as the mailer assumes it is insecure:
> > >
> > > // Example script to load a raster image and do the Interactive Watershed.
> > > //
> > > // NOTE:   While it runs when loaded via Plugins/Macros/Run,
> > > //         running from the command line it fails:
> > > //
> > > //           $ ImageJ-linux64 -macro attempt.js
> > > //
> > > //         (probably due to grabbing the wrong window, ie. taking the
> > > //         grayscale image instead of the watershedded one; it is seen
> > > //         from that the wrong window is renamed to "apple").
> > > //
> > > // NOTE-2: I do not think it is related to Interactive Watershed at all.
> > >
> > >
> > > importClass(Packages.ij.IJ);
> > > importClass(Packages.ij.WindowManager);
> > >
> > >
> > >
> > > function listAllWindowsAndImages( ) {
> > >      IJ.log("\n    Window IDs ("+WindowManager.getWindowCount()+"):");
> > >      var IDlist = WindowManager.getIDList();
> > >      for (var i in IDlist) {
> > >          IJ.log("        "+IDlist[i]);
> > >          if (i == IDlist.length)
> > >              IJ.log(" <-- the last one");
> > >      }
> > >      IJ.log("    Images ("+WindowManager.getImageCount()+"):");
> > >      var IMlist = WindowManager.getImageTitles();
> > >      for (var i in IMlist)
> > >          IJ.log("      "+IMlist[i]+"  ID: "+WindowManager.getNthImageID(i));
> > >      IJ.log("    Non-images:");
> > >      IMlist = WindowManager.getNonImageTitles();
> > >      for (var i in IMlist)
> > >          IJ.log("      "+IMlist[i]);
> > >      IJ.log("\n");
> > > }
> > >
> > >
> > >
> > > IJ.log("Loading an image...");
> > > // from "https://eur03.safelinks.protection.outlook.com/?url=https%3A%2F%2Fimagej.net%2Fplugins%2Finteractive-watershed&amp;data=04%7C01%7Cstein.rorvik%40sintef.no%7C7b3671c235b64ec47f7a08d932435f7c%7Ce1f00f39604145b0b309e0210d8b32af%7C1%7C1%7C637596087222760603%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&amp;sdata=okhDbxqoSXnqCnwHTYEk9d32B%2FMGya48Tzp7WBBKIVs%3D&amp;reserved=0":
> > > var imGray = IJ.openImage("figure-hmax-hwatershed-v3.png");
> > > IJ.log("imGray: "+imGray+"\n"); // not now but soon it will be gray
> > > listAllWindowsAndImages();
> > >
> > >
> > > IJ.log("Showing it...");
> > > imGray.show(); // if missing: the plugin cannot process `imGray'
> > > listAllWindowsAndImages();
> > >
> > >
> > > var titleGray = "gray"
> > > IJ.log("Turning it to gray and renaming to \""+titleGray+"\"...");
> > > IJ.run("32-bit"); imGray.setTitle(titleGray);
> > > listAllWindowsAndImages();
> > >
> > >
> > > IJ.log("Performing the main activity (takes a few seconds)...");
> > > IJ.run("H_Watershed","impin=["+titleGray+"] hmin="
> > >      +20+" thresh="+100+" peakflooding="+90
> > >      +" outputmask=true allowsplitting=false");
> > > listAllWindowsAndImages();
> > >
> > >
> > > //
> > > // look for the result image (the point that fails):
> > > //
> > >
> > >
> > > // via GUI it retrieves the latest (ie. results) image, but // via
> > > the command line it takes the grayscale (ie. previous) image/window
> > > var imWS = IJ.getImage(); var titleWS = "apple";
> > > imWS.setTitle(titleWS);
> > > IJ.log("imWS: "+imWS+"\n");
> > > listAllWindowsAndImages();
> > >
> > >
> > > IJ.log("\n###");
> > > if (imWS == imGray) {
> > >      IJ.log("It is probable that THE WRONG IMAGE will be saved!"); }
> > > else {
> > >      IJ.log("It is probable that the CORRECT image will be saved.");
> > > } IJ.log("###\n");
> > >
> > >
> > > IJ.save(imWS,titleWS+".png");
> > > IJ.log("saved \""+titleWS+".png\".\n");
> > >
> > > --
> > > ImageJ mailing list:
> > > https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fima
> > > gej.nih.gov%2Fij%2Flist.html&amp;data=04%7C01%7Cstein.rorvik%40sinte
> > > f.no%7C7b3671c235b64ec47f7a08d932435f7c%7Ce1f00f39604145b0b309e0210d
> > > 8b32af%7C1%7C1%7C637596087222760603%7CUnknown%7CTWFpbGZsb3d8eyJWIjoi
> > > MC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&am
> > > p;sdata=udNglLMU%2FJbPhx7zDrsfwGh%2BAQN6ZeVfQ30b5FBnbQE%3D&amp;reser
> > > ved=0
> > >
> >
> > --
> > ImageJ mailing list:
> > https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fimage
> > j.nih.gov%2Fij%2Flist.html&amp;data=04%7C01%7Cstein.rorvik%40sintef.no
> > %7C7b3671c235b64ec47f7a08d932435f7c%7Ce1f00f39604145b0b309e0210d8b32af
> > %7C1%7C1%7C637596087222760603%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAw
> > MDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&amp;sdata=ud
> > NglLMU%2FJbPhx7zDrsfwGh%2BAQN6ZeVfQ30b5FBnbQE%3D&amp;reserved=0
>
> --
> ImageJ mailing list: https://eur03.safelinks.protection.outlook.com/?url=http%3A%2F%2Fimagej.nih.gov%2Fij%2Flist.html&amp;data=04%7C01%7Cstein.rorvik%40sintef.no%7C7b3671c235b64ec47f7a08d932435f7c%7Ce1f00f39604145b0b309e0210d8b32af%7C1%7C1%7C637596087222760603%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000&amp;sdata=udNglLMU%2FJbPhx7zDrsfwGh%2BAQN6ZeVfQ30b5FBnbQE%3D&amp;reserved=0
>
> --
> ImageJ mailing list: http://imagej.nih.gov/ij/list.html

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