Posted by
Rasband, Wayne (NIH/NIMH) [E] on
Aug 29, 2015; 3:39pm
URL: http://imagej.273.s1.nabble.com/Race-condition-in-Javascript-tp5014186p5014188.html
> On Aug 29, 2015, at 2:48 AM, Avital Steinberg <
[hidden email]> wrote:
>
> Hi,
> I am experiencing a problem with ImageJ: I open a few images. Then I select
> an image and I want to run a command on it. The problem is that the command
> is executed before the previous command (opening the image) is completed.
> So - I get an error message saying that imageA is not open, and when I
> click OK, imageA opens.
>
> I didn't have this problem when I was running the same script in the macro
> language.
>
> Does anyone have a suggestion how to fix it?
Always use versions of IJ.run() that include an ImagePlus argument, as in the following example. Note that the image is never displayed.
img = IJ.openImage("
http://imagej.nih.gov/ij/images/Cell_Colony.jpg");
IJ.run(img, "Invert", "");
IJ.run(img, "Gaussian Blur...", "sigma=2");
IJ.run(img, "Subtract Background...", "rolling=25");
IJ.setAutoThreshold(img, "IsoData dark");
IJ.run(img, "Analyze Particles...", "size=10 show=[Overlay Outlines] exclude");
print("count="+ img.getOverlay().size());
-wayne
--
ImageJ mailing list:
http://imagej.nih.gov/ij/list.html