Posted by
Wayne Rasband on
Oct 31, 2009; 3:05pm
URL: http://imagej.273.s1.nabble.com/Active-Image-or-Threading-Problem-tp3690601p3690602.html
You can avoid threading problems like this by creating the ROI and
adding it to the image using the setRoi() method. And when running
commands using IJ.run(), it is better to use the version that accepts
an ImagePlus object as an argument. Here is a JavaScript example that
inverts the first image and adds an oval ROI to the second:
ip1 = new ByteProcessor(100,100);
ip2 = new ByteProcessor(100,100);
imp1 = new ImagePlus("ip1", ip1);
imp2 = new ImagePlus("ip2", ip2);
IJ.run(imp1, "Invert", "");
roi = new OvalRoi(0,0,70,70)
imp2.setRoi(roi);
imp1.show();
imp2.show();
-wayne
On Oct 31, 2009, at 2:24 AM, David William Webster wrote:
> All,
>
> I am getting some funny results with the code fragment below. The
> IJ.makeOval(...) method works on the current active image. In case
> 1, when
> I leave IJ.log("2: The ... ) commented out, the oval shows up on
> drawn on
> image ip1. I would have thought it would shown up on ip2. In case 2,
> I un-
> comment IJ.log("2: The ... ), then the oval it does show up super-
> imposed
> on ip2. Sometimes, things work the other way around, at least in the
> first
> case. Am I getting some sort of multi-threading problem or does the
> method
> call in the IJ.log(...) somehow change the active image? In any
> case, how
> can I insure that ip2 is the active image.
>
> David Webster
>
>
>
> ImageProcessor ip1 = new ByteProcessor(100,100);
> ImageProcessor ip2 = new ByteProcessor(100,100);
>
> new ImagePlus("ip1", ip1).show();
> new ImagePlus("ip2", ip2).show();
>
> //IJ.log("2: The current image is "+WindowManager.getCurrentImage
> ().getTitle());
>
> IJ.makeOval(0,0, 70,70);