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); |
Hi David,
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. > The following always draws the oval on "ip2" for me. You might be right about the thready thing; using WindowManager.setTempCurrentImage() seems to work for this thread. ImageProcessor ip1 = new ByteProcessor(100,100); ImageProcessor ip2 = new ByteProcessor(100,100); ImagePlus imp1 = new ImagePlus("ip1", ip1); imp1.show(); ImagePlus imp2 = new ImagePlus("ip2", ip2); imp2.show(); WindowManager.setTempCurrentImage(imp2); IJ.log("2: The current image is "+WindowManager.getCurrentImage().getTitle()); IJ.makeOval(0,0, 70,70); Cheers, Ben > 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); Cheers, Ben |
In reply to this post by David Webster
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); |
Free forum by Nabble | Edit this page |