http://imagej.273.s1.nabble.com/issue-works-with-Fiji-graphical-interface-but-not-on-the-command-line-tp5024747p5024753.html
Thank you for your suggestion. Process/Find Maxima indeed does the job.
>
> 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