Re: Using ImageJ in another java pp in the existing jre, and batch mode on linux
Posted by
Rasband, Wayne (NIH/NIMH) [E] on
Feb 14, 2010; 5:43am
URL: http://imagej.273.s1.nabble.com/Using-ImageJ-in-another-java-pp-in-the-existing-jre-and-batch-mode-on-linux-tp3689390p3689393.html
On Feb 13, 2010, at 12:27 AM, Adam wrote:
> Hi Jared,
>
> I'm glad you wrote to the list. I have a similar problem that I asked about on February 7th, and also received no response. My issue also involves trying to use ImageJ as a library for a Java-based image analysis program. Specifically, my problem is the requirement of the RoiManager class to show a window in order to add a selection. This forces me to show an image, which prevents this program from running completely in the background, and slows down analysis.
>
> Have you tried to use RoiManager in your programs? If so, have you found a way to circumvent this requirement? I'm including the relevant part of my first email below:
>
> Here's what I need to do:
> 1) Threshold a 16-bit grayscale image. (Using setAutoThreshold).
> 2) Make a mask out of this threshold. (Using IJ.run(img, "Convert to Mask","");)
> 3) Make a selection out of this mask.
> 4) Apply this selection to the original image.
>
> To accomplish the transition between steps 3 and 4, I am using the following code:
>
> <code>
>
> RoiManager rm = new RoiManager(false);
>
> IJ.run(bgmask, "Create Selection","");
> bgmask.show();
> rm.runCommand("Add");
> bgmask.close();
>
> Roi[] roi = rm.getRoisAsArray();
> bs.setRoi(roi[0]);
> ImageStatistics fg_stats = bs.getStatistics(ImageStatistics.MEDIAN);
> </code>
>
> The problem is that if I don't run "bgmask.show()" the roi manager complains that "there are no images open" and aborts the run.
Use
rm.addRoi(bgmask.getRoi());
instead of
rm.runCommand("Add");
-wayne