I'm trying to take the result of a "subtract create" and threshold it (in
batch mode). But I don't know how to obtain a reference to the subtracted image. My code looks like this: ImageCalculator ic = new ImageCalculator(); for (int i=0; i<fileList.length; i++) { ImagePlus img1 = new Opener().openImage(dir1, fileList[i]); ImagePlus img2 = new Opener().openImage(dir1, bkgrdImgFile); ic.calculate("Subtract create", img1, img2); ic.calculate("Threshold", /* result of subtract? */ ); } As you can see, I need to somehow refer to the resulting image from the first call to calculate(). How do I do that? Please help! I've spent hours scouring the documentation and email archives to no avail! Thanks. John |
John,
I suggest try {Thread.sleep(200);} catch(InterruptedException e) { IJ.error("Sleep exception "+e); } ImagePlus img3 = WindowManager.getCurrentImage(); The first 4 lines are an optional kludge, but they may improve reliability. (I'd be interested in learning about a better approach for making sure that the previous work is done before possibly grabbing the wrong image.) You may also find that WindowManager.putBehind() and WindowManager.getCurrentImage().hide() are handy for controlling clutter. Bob Robert P. Dougherty, Ph.D. President, OptiNav, Inc. (425) 467-1118 [hidden email] http://www.optinav.com > -----Original Message----- > From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of John > Kim > Sent: Monday, September 04, 2006 7:10 PM > To: [hidden email] > Subject: Where is result image of calculate()? > > I'm trying to take the result of a "subtract create" and threshold it (in > batch mode). But I don't know how to obtain a reference to the subtracted > image. My code looks like this: > > ImageCalculator ic = new ImageCalculator(); > for (int i=0; i<fileList.length; i++) { > ImagePlus img1 = new Opener().openImage(dir1, fileList[i]); > ImagePlus img2 = new Opener().openImage(dir1, bkgrdImgFile); > ic.calculate("Subtract create", img1, img2); > ic.calculate("Threshold", /* result of subtract? */ ); > } > > As you can see, I need to somehow refer to the resulting image from > first call to calculate(). How do I do that? > > Please help! I've spent hours scouring the documentation and email > archives > to no avail! Thanks. > > John |
In reply to this post by John Kim-2
Bob wrote:
> I suggest > ImagePlus img3 = WindowManager.getCurrentImage(); Thanks Bob but... I was hoping to be able to call the program from command line. Will this still work? Even if it does, I think it'll slow down the program. I'm trying to process thousands of images. John |
John,
The ImagePlus img3 = WindowManager.getCurrentImage(); statement would not take very long. If it is a thousand cycles, that is still less than a microsecond. A bigger problem would be running out of memory if you don't close the three windows you open in the loop. Another issue is that "Threshold" does not seem to be an ImageCalculator option, so finding the ImagePlus created by the "Subtract create" may not be helpful, at least not for running the threshold operation. Maybe you want something like this: ImageCalculator ic = new ImageCalculator(); for (int i=0; i<fileList.length; i++) { ImagePlus img1 = new Opener().openImage(dir1, fileList[i]); ImagePlus img2 = new Opener().openImage(dir1, bkgrdImgFile); ic.calculate("Subtract create", img1, img2); //ic.calculate("Threshold", /* result of subtract? */ ); int ll = ... something...; int ul = ... something...; //(it might be helpful to do // ImagePlus img3 = WindowManager.getCurrentImage(); //to help establish ll and ul IJ.setThreshold(ll, ul); IJ.run("Threshold", "thresholded remaining black"); ImagePlus imgResult = WindowManager.getCurrentImage(); ...do something with imgResult...; imgResult.hide(); Img1.hide(); Img2.hide(); } I don't understand the question about running the program from the command line. Is your code not an ImageJ plugin? If you are running ImageJ from the command line, what difference does that make? Bob > -----Original Message----- > From: ImageJ Interest Group [mailto:[hidden email]] On Behalf Of John > Kim > Sent: Monday, September 04, 2006 9:50 PM > To: [hidden email] > Subject: Re: Where is result image of calculate()? > > Bob wrote: > > I suggest > > ImagePlus img3 = WindowManager.getCurrentImage(); > > Thanks Bob but... > > I was hoping to be able to call the program from command line. Will > still work? Even if it does, I think it'll slow down the program. I'm > trying to process thousands of images. > > John |
In reply to this post by John Kim-2
On Mon, 4 Sep 2006 23:44:57 -0700, Robert Dougherty <[hidden email]> wrote:
>I don't understand the question about running the program from the >command line. Is your code not an ImageJ plugin? If you are running >ImageJ from the command line, what difference does that make? I was hoping to be able to run the program while logged into a machine remotely via a text terminal. I don't know what will happen if ImageJ wants to open an image window but there's no graphics terminal to open it in. Also, I thought opening & closing image windows on the screen would significantly slow down the program. I don't need to see the intermediate images -- just the final result table. I'm trying to count particles in (thousands of) images by: 1) subtracting out the background; 2) convert the image to 8-bit grayscale; 3) threshold it; then 4) run particle analyzer. I see examples in the email archives about how to do one of these at a time but not do them in series. Anyhow, thanks Bob. I'll try what you suggest.... John |
Free forum by Nabble | Edit this page |