display ResultsTable in window

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

display ResultsTable in window

Aryeh Weiss
We have a python script that runs correctly from the script editor in Fiji.

We are trying to run it in eclipse without launching the GUI . At some
point we run a plugin that generates a ResultsTable, whcih we grab wtih
the following line of code:

  new_rt = ResultsTable.getResultsTable()

However, our first attempt to read  from this table , as in :

  center_x = float(new_rt.getStringValue("X", i))

  throws a row out of range error. But, we know that the row is there.

I tried displaying the table with new_rt.show("new_rt")
and it displayed the table by printing to the console output as text,
rather than in a window.

My questions are -- how do I display a ResultsTable in a window, without
launching the main ImageJ window? Is this possible?

And, can the ResultsTable methods such as getValue, getStringValue, etc
be used in Eclipse without launching the GUI.

Thanks in advance for any help you can provide.

Also, special thanks to Jan Brocher for adding methods to his Extended
Particle Analyzer plugin to enable use of that plugin though  API calls.

BTW - we noticed that some IJ.run("command", args) work find without the
GUI, while others will return a command not found error unless the GIU
is launched.
Why is that?

--aryeh

--
Aryeh Weiss
Faculty of Engineering
Bar Ilan University
Ramat Gan 52900 Israel

Ph:  972-3-5317638
FAX: 972-3-7384051


--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: display ResultsTable in window

Mark Chopping
Hi Aryeh,

BTW - we noticed that some IJ.run("command", args) work find without the
> GUI, while others will return a command not found error unless the GIU is
> launched.
> Why is that?


It's probably because some ImageJ commands expect graphical output and so
need a graphics interface of some kind. You can get around this by fooling
the OS into thinking it is outputting to a valid display. We used xvfb
under linux.

Why don't you save the Results table(s) instead? Do you really need to
display them as your code runs? If not, you can run ImageJ headless and
call from scripts. We did this a few years ago in a Debian environment
using the xvfb utility:

// Using ImageJ 1.48v, 64-bit. Runs "headless", called with a command such
as:
// xvfb-run-safe ~/ImageJ/jre/bin/java -Xmx2048m -jar ~/ImageJ/ij.jar
-ijpath \
// ~/ImageJ -batch CANAPI_HL.ijm arg1 arg2 > /dev/null &

where the .ijm file is a macro and xvfb-run-safe is Charles Duffy's script
used to ensure the uniqueness of display IDs and avoid race issues (from
http://stackoverflow.com/questions/30332137/xvfb-run-unreliable-when-multiple-instancesinvoked-in-parallel
):

#!/bin/bash
# invoke with (e.g.,) xvfb-run-safe my_process args
# to avoid race conditions so long as no other users on your system are
also running xvfb.
# allow settings to be updated via environment
: "${xvfb_lockdir:=$HOME/.xvfb-locks}"
: "${xvfb_display_min:=99}"
: "${xvfb_display_max:=599}"
# assuming only one user will use this, let's put the locks in our own home
directory
# avoids vulnerability to symlink attacks.
mkdir -p -- "$xvfb_lockdir" || exit
i=$xvfb_display_min # minimum display number
while (( i < xvfb_display_max )); do
if [ -f "/tmp/.X$i-lock" ]; then # still avoid an obvious open display
(( ++i )); continue
fi
exec 5>"$xvfb_lockdir/$i" || continue # open a lockfile
if flock -x -n 5; then # try to lock it
exec xvfb-run --server-num="$i" "$@" || exit # if locked, run xvfb-run
fi
(( i++ ))
done # end of xvfb-run-safe script

This way you can run many scripts simultaneously and collect the results by
having the Results Tables written out (and renamed if necessary). This
probably doesn't help you with Eclipse though.

Best wishes,

 Mark

Mark Chopping, Ph.D.
Professor, Department of Earth and Environmental Studies
Director, Ph.D. Program in Environmental Management
Montclair State University, Montclair, NJ 07043
Tel. (973) 655-7384 Fax: (973) 655-4072
http://www.montclair.edu/csam/remote-sensing-lab/
<http://www.montclair.edu/csam/remote-sensing-lab/>[image: It's all here.
Montclair State University.] <http://montclair.edu/>
<http://above.nasa.gov>
<http://misr.jpl.nasa.gov/>      <http://majortaylorclub.com/>
All opinion expressed here is my own and does not represent the views or
policies of Montclair State University, NASA, NJ DEP, NACP, USDA, or AGU.

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: display ResultsTable in window

Aryeh Weiss
Hi Mark -- thank you for your reply.

On 13/07/2018 19:21, Mark Chopping wrote:

> Hi Aryeh,
>
>     BTW - we noticed that some IJ.run("command", args) work find
>     without the GUI, while others will return a command not found
>     error unless the GIU is launched.
>     Why is that?
>
>
> It's probably because some ImageJ commands expect graphical output and
> so need a graphics interface of some kind. You can get around this by
> fooling the OS into thinking it is outputting to a valid display. We
> used xvfb under linux.
>
> Why don't you save the Results table(s) instead? Do you really need to
> display them as your code runs? If not, you can run ImageJ headless
> and call from scripts. We did this a few years ago in a Debian
> environment using the xvfb utility:
>
Some of the plugins that we run create the tables as a "side effect".
and we need to grab data from those tables. Also, in the end we want
people who are running stock Fiji on whatever OS (usually Windows) to
run the scripts from the script editor, so  we do not want to do
something that will be OS dependent.

I do not mind launching the GUI, but it means that when I run it from
the script editor, I need to remove the code that launched the GUI
(since it is already launched). To do it right, I should learn how to
test for this, and launch the GUI only when needed.

Also,  if we run the code again, without explicitly closing the GUI that
was opened, I will have two IJ frames open. If I close the main IJ
window before closing the various images that it opened, it appears that
these image are "orphaned", and cannot be closed without  forcefully
killing various Jython processes that were spawned. All this makes
sense, but it  leaves me with the feeling that I am not using the system
optimally.

I  started doing this in order to  learn how to use a more powerful IDE,
and it has some nice conveniences, so I will muddle along
hopefully learn how to use it more effectively.

Best regards
--aryeh

--
Aryeh Weiss
Faculty of Engineering
Bar Ilan University
Ramat Gan 52900 Israel

Ph:  972-3-5317638
FAX: 972-3-7384051


--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html