Preventing RoiManager from requiring an image to be displayed

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Preventing RoiManager from requiring an image to be displayed

Adam Waite
Hi List,

I am trying to use imagej as a library in some image analysis programs I am writing (in Java).  Ideally, I would like to avoid ever showing an image and, for the most part, I can achieve this.  However, there is one step that I cannot figure out how to write without showing an image.

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.

Is there a way to circumvent this?

Thanks in advance,

Adam


=====
Science is more of an art than a science.